Prolog数据库查询
创建一个包含以下形式事实的约会数据库:
person(姓名、年龄、性别、身高、体重、教育程度、薪水)
给定输入:
datable(alex, X)。
datable_weight_limit(alex, 170, X).
其中170是体重的阈值
如何根据规则返回潜在匹配的姓名:
- 只能匹配异性
- 男性应该年龄较大比女性
- 男性应该比女性接受更高的教育吗?
我已经建立了这些关系:
edu_less(hs, bachelor).
edu_less(bachelor, master).
edu_less(master, phd).
edu_lesser(A, B):-
edu_less(A, X),
edu_lesser(X, B).
我已经尝试过:
datable(X, Y):-
person(X, Agel, Sexl, Heightl, Weightl, Educationl, Salaryl),
person(Namem, Agem, Sexm, Heightm, Weightm, Educationm, Salarym),
Sexm \== Sexl.
datable(X, Y):-
person(X, Agel, Sexl, Heightl, Weightl, Educationl, Salaryl),
Sexl == female,
findall( X, person(X, _, male, _, _, _, _), Y).
但我似乎没有运气。是否有我遗漏的功能或我实施的错误?
To make a dating database with facts in the form of:
person(name, age, sex, height, weight, education, salary)
Given the input of:
datable(alex, X).
datable_weight_limit(alex, 170, X).
Where 170 is the threshold for weight
How can I return the names of potential matches with the rules:
- Only opposite sexes can be matched
- Males should be older than females
- Males should have a higher education than females?
I have these relations set up:
edu_less(hs, bachelor).
edu_less(bachelor, master).
edu_less(master, phd).
edu_lesser(A, B):-
edu_less(A, X),
edu_lesser(X, B).
I've tried:
datable(X, Y):-
person(X, Agel, Sexl, Heightl, Weightl, Educationl, Salaryl),
person(Namem, Agem, Sexm, Heightm, Weightm, Educationm, Salarym),
Sexm \== Sexl.
datable(X, Y):-
person(X, Agel, Sexl, Heightl, Weightl, Educationl, Salaryl),
Sexl == female,
findall( X, person(X, _, male, _, _, _, _), Y).
But I seem to have no luck. Is there a function I'm missing or something I'm implementing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你几乎是正确的。试试这个:
在这里我们假设教育也是数字。
如果您还需要函数 -
datable(F,M)
:I think you are almost correct. Try this:
Here we suppose, that education is also numbers.
If you need also function -
datable(F,M)
: