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]))),
Success #stdin #stdout #stderr 0.02s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit