我正在阅读Pereira和Shieber的书“序言和自然语言分析”(pdf),在问题2.7中我的口号是:
In semantic network representations, we often want to ask [...] “What relationships hold between Ford and the class of companies?”
Modify your representation of semantic networks to allow both this new kind of question and the kind in the previous problem. HINT: Treat semantic network relations as Prolog individuals. This is an important Prolog programming technique, sometimes called reification in philosophical circles.
我不熟悉这种
reification
技术。好,让我们假设这个事实和规则数据库:
isa('Ole Black', 'Mustangs').
isa('Lizzy', 'Automobiles').
isa('Ford','Companies').
isa('GM','Companies').
isa('1968','Dates').
ako('Model T', 'Automobiles').
ako('Mustangs', 'Automobiles').
ako('Companies', 'Legal Persons').
ako('Humans', 'Legal Persons').
ako('Humans', 'Physical Objects').
ako('Automobiles', 'Physical Objects').
ako('Legal Persons', 'Universal').
ako('Dates', 'Universal').
ako('Physical Objects', 'Universal').
have_mass('Physical Objects').
self_propelled('Automobiles').
company(X) :- isa(X,'Companies').
legal_persons(X) :- ako(X,'Legal Persons').
我如何编写一个查询,在上面的代码中发现
'Ford'
和'Companies'
之间的关系是isa
?当然,我总是可以这样写
fact(isa, 'Ford','Companies').
并查询
?- fact(X, 'Ford','Companies').
,但以某种方式我认为这不是正确的方法。有人可以向我解释如何正确执行吗?
最佳答案
结合Paul和Carlo的答案,另一个可能的解决方案是引入元关系谓词。例如:
relation(isa/2).
relation(ako/2).
relation(have_mass/1).
...
这样可以避免由于关系的关系化而丢失了使用原始数据库对某些查询进行第一参数索引的好处。在Carlo的解决方案中,它还避免了对
current_predicate/2
的调用,例如不应该考虑的辅助谓词。通过上面
relation/2
谓词的定义,我们可以编写:relation(Relation, Entity1, Entity2) :-
relation(Relation/2),
call(Relation, Entity1, Entity2).
relation(Relation, Entity) :-
relation(Relation/1),
call(Relation, Entity).
然后查询:
?- relation(Relation, 'Ford', 'Companies').
Relation = isa.
关于prolog - 了解具体化- “What relationships hold between x and y?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57566271/