我正在阅读Pereira和Shieber 撰写的“序言和自然语言分析”(pdf)一书,在问题2.7中有一段评论:
在语义网络表示中,我们经常想问“福特与公司类别之间保持什么关系?”
修改语义网络的表示形式,以允许这种新类型的问题和上一个问题中的类型。提示:将语义网络关系视为Prolog个人。这是一项重要的Prolog编程技术,有时在哲学界称为“具体化”。
我不熟悉这种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').
Run Code Online (Sandbox Code Playgroud)
如何编写一个查询,在上面找到的代码之间的关系'Ford',并'Companies'为isa?当然,我总是可以这样写
fact(isa, 'Ford','Companies').
Run Code Online (Sandbox Code Playgroud)
和查询,?- fact(X, 'Ford','Companies').但以某种方式我认为这不是正确的方法。
有人可以解释一下如何正确执行吗?
结合Paul和Carlo的答案,另一个可能的解决方案是引入元关系谓词。例如:
relation(isa/2).
relation(ako/2).
relation(have_mass/1).
...
Run Code Online (Sandbox Code Playgroud)
这样可以避免由于关系的关系化而丢失了使用原始数据库对某些查询进行第一参数索引的好处。在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).
Run Code Online (Sandbox Code Playgroud)
然后查询:
?- relation(Relation, 'Ford', 'Companies').
Relation = isa.
Run Code Online (Sandbox Code Playgroud)
我想为之前的答案添加一些背景知识(这非常有帮助)。
据我所知,Prolog 中没有普遍接受的具体化定义。可以说原始代码中的关系已经部分具体化了。例子:
isa('Ford', 'Companies').
% ...is a reification of...
company('Ford').
ako('Companies', 'Legal Persons').
% ...is a reification of...
legal_person(X) :- company(X).
have_mass('Physical Objects').
% ...is a reification of...
has_mass(X) :- physical_object(X).
self_propelled('Automobiles').
% ...is a reification of...
self_propelled(X) :- automobile(X).
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅Matthew Huntbach的《语义网和框架注释》中的具体化部分。