从数据库返回值-Prolog

发布于 2025-02-04 15:38:05 字数 442 浏览 3 评论 0原文

早上好,我正在学习prolog。 但是我已经搜索过,但是我没有找到解决方案,它一定很简单,但是我被卡住了,

我创建了一个数据库,如以下

data base([
   movie(["Titanic"], [["Jack", "Dawson"] ,["Rose", "DeWitt", "Bukater"]], ["James","Cameron"] ),
   movie(["Hulk"], [["Bruce", "Banner"] ,["Betty", "Ross"]], ["Ang","Lee"] )
]).

数据库包含电影的名称,主要角色的名称,然后是导演。

目标是创建一个函数:

示例

find_movies_by_character(“ Bruce Banner”) 需要回报泰坦尼克号

,我想可能有问题,我愿意接受新想法

Good morning, I'm learning prolog.
But I already searched, but I didn't find a solution, it must be very simple, but I got stuck

I created a database like the following

data base([
   movie(["Titanic"], [["Jack", "Dawson"] ,["Rose", "DeWitt", "Bukater"]], ["James","Cameron"] ),
   movie(["Hulk"], [["Bruce", "Banner"] ,["Betty", "Ross"]], ["Ang","Lee"] )
]).

This database contains the name of the film, the name of the main characters and then the director.

The goal would be to create a function:

Example

find_movies_by_character("Bruce Banner")
Need return Titanic

I imagine something might be wrong, I'm open to new ideas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦欢 2025-02-11 15:38:05

数据库([带有该空间,在SWI Prolog中似乎不是有效的语法。无论您从哪里得到它?

此数据库包含电影的名称,主要角色的名称,然后是导演。

更具体地说,数据库包含一个包含电影术语的列表,每个列表包含一个包含电影名称的列表,以及(包含主要字符名称部分列表的列表)和(包含董事名称的部分的列表)。

从写出的内容是多么复杂,至少与之合作会很复杂。如果您可以简化它,它将变得更容易使用:

movie('Titanic', ['Jack Dawson', 'Rose DeWitt Bukater'], 'James Cameron').
movie('Hulk', ['Bruce Banner', 'Betty Ross'], 'Ang Lee').

find_movie_by_character(Character, MovieName) :-
    movie(MovieName, Characters, _),
    member(Character, Characters).

例如

?- find_movie_by_character('Bruce Banner', X).
X = 'Hulk'

data base([ with that space in it, doesn't seem to be valid syntax in SWI Prolog. Wherever did you get that from?

This database contains the name of the film, the name of the main characters and then the director.

More specifically, the database contains a list containing movie terms, each containing a list containing the name of the film and (a list containing lists of parts of names of the main characters) and (a list containing parts of names of directors).

From how complicated it is to write out, it will be at least that complicated to work with. If you can simplify it, it will get easier to work with:

movie('Titanic', ['Jack Dawson', 'Rose DeWitt Bukater'], 'James Cameron').
movie('Hulk', ['Bruce Banner', 'Betty Ross'], 'Ang Lee').

find_movie_by_character(Character, MovieName) :-
    movie(MovieName, Characters, _),
    member(Character, Characters).

e.g.

?- find_movie_by_character('Bruce Banner', X).
X = 'Hulk'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文