gpt4 book ai didi

通过给类加分来进行 Prolog 分类

转载 作者:行者123 更新时间:2023-12-04 09:38:09 29 4
gpt4 key购买 nike

我正在开发一个知识系统,当用户进入一道菜时,该系统可以返回酒。我的想法是根据用户的输入为每个葡萄酒类别添加分数,然后显示最适合的葡萄酒类别的前 3 个。例如,如果有人输入鱼,那么知识库中的所有红葡萄酒都得零分,而白葡萄酒确实得一分。如果用户然后输入一种香肠或蔬菜等。与此匹配的葡萄酒将获得加分。然后,这将生成一个列表,根据分数显示哪些葡萄酒(在我的知识库中)最适合,哪些最不适合。有谁知道我如何在序言中做到这一点。

最佳答案

您可以像这样设置葡萄酒及其特征的数据库:

wine_color_body(chardonnay, white, light).
wine_color_body(gruener_veltliner, white, full).
wine_color_body(cabernet_franc, red, light).
wine_color_body(pinot_noir, red, medium).
wine_color_body(merlot, red, full).

(你会比我更了解葡萄酒,并且可能会添加更多标准。)

然后,您可以根据个人特征制定评分规则,如下所示:
dish_wine_score(fish, Wine, 1) :-
wine_color_body(Wine, white, _).
dish_wine_score(fish, Wine, 0) :-
wine_color_body(Wine, red, _).

dish_wine_score(beef, Wine, 1) :-
wine_color_body(Wine, red, _).
dish_wine_score(beef, Wine, 0) :-
wine_color_body(Wine, white, _).

dish_wine_score(dessert, Wine, 2) :-
wine_color_body(Wine, _, light).
dish_wine_score(dessert, Wine, 1) :-
wine_color_body(Wine, _, medium).
dish_wine_score(dessert, Wine, 0) :-
wine_color_body(Wine, _, full).

例如,要查看与鱼有关的内容:
?- dish_wine_score(fish, Wine, Score).
Wine = chardonnay,
Score = 1 ;
Wine = gruener_veltliner,
Score = 1 ;
Wine = cabernet_franc,
Score = 0 ;
Wine = pinot_noir,
Score = 0 ;
Wine = merlot,
Score = 0.

然后您可以根据菜肴列表或其属性轻松评分:
dishes_wine_score([], _Wine, 0).
dishes_wine_score([Dish | Dishes], Wine, Score) :-
dish_wine_score(Dish, Wine, DishScore),
dishes_wine_score(Dishes, Wine, RestScore),
Score is DishScore + RestScore.

什么酒最适合搭配牛肉和之后的甜点?
?- dishes_wine_score([beef, dessert], Wine, Score).
Wine = cabernet_franc,
Score = 3 ;
Wine = pinot_noir,
Score = 2 ;
Wine = merlot,
Score = 1 ;
Wine = chardonnay,
Score = 2 ;
Wine = gruener_veltliner,
Score = 0.

一旦你到了这一点,你只需要收集所有这些答案,对它们进行排序,然后找到得分最高的答案。你可以用 bagof/3 来做到这一点或 findall/3其次是 sort/2 .

关于通过给类加分来进行 Prolog 分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62453336/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com