fork download
  1. % =================================================================
  2. % データ定義(ファクト)
  3. % product(Name, Price, Rating, ReviewCount)
  4. % =================================================================
  5. product(item1, 3000, 4.8, 20).
  6. product(item2, 1800, 4.2, 200).
  7. product(item3, 5000, 4.9, 5).
  8. product(item4, 2500, 4.5, 80).
  9.  
  10. % =================================================================
  11. % AIが独自に定義した「おすすめ(recommended)」のルール
  12. % 定義:評価(Rating)が4.5以上、かつレビュー数(ReviewCount)が15件以上
  13. % =================================================================
  14. recommended_product(Name) :-
  15. product(Name, _, Rating, ReviewCount),
  16. Rating >= 4.5,
  17. ReviewCount >= 15.
  18.  
  19. % =================================================================
  20. % メイン処理(ideoneの実行用エントリーポイント)
  21. % =================================================================
  22. main :-
  23. % すべてのおすすめ商品をバックトラックで列挙して表示
  24. forall(recommended_product(Name),
  25. (format('Recommended item: ~w~n', [Name]))),
  26.  
  27. % 起動時にmainを実行する指定
  28. :- initialization(main).
Success #stdin #stdout 0.02s 5884KB
stdin
Standard input is empty
stdout
Recommended item: item1
Recommended item: item4