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