我正尝试在参考数据和内存中保留一个大模型,并在其他模型上附加推理规则,当新的三元组即将到来时,我需要匹配规则来触发,查找参考数据和所有新的三元组以结束在第二个模型中。
像这样:
#Reference data:
:alice
foaf:name "Alice" ;
schema:identifier "1" ;
.
#New incoming triples:
:claire
foaf:name "Claire" ;
schema:identifier "3" ;
:friend_id "1" ;
.
当克莱尔到达时,应触发一条规则,按ID在参考数据中找到爱丽丝,并生成其他类似
:alice foaf:knows :claire
应该与正在填写的模型中的克莱尔记录一起结束,而不是爱丽丝所住的那个模型。
我对此的最新尝试:
private void createUnionModel() {
Model referred = RDFDataMgr.loadModel("referred.ttl");
Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL("align.sse"));
Model aligned = ModelFactory.createDefaultModel();
Model union = ModelFactory.createUnion(aligned, referred);
InfModel infModel = ModelFactory.createInfModel(reasoner, union);
RDFDataMgr.read(infModel, "new_triples.ttl");
printModel(referred, "referred");
printModel(aligned, "aligned");
printModel(union, "union");
printModel(infModel, "inference");
}
显示由推理规则生成的三元组不会进入aligned
模型:
'alignment rules loaded'
'alignment rules loaded'
----------------- referred
:alice a foaf:Person ;
schema:identifier "1" ;
foaf:name "Alice" .
:bob a foaf:Person ;
schema:identifier "2" ;
foaf:name "Bob" .
----------------- aligned
<http://example.org/claire>
a <http://xmlns.com/foaf/0.1/Person> ;
<http://example.org/friend_id> "1" ;
<http://schema.org/identifier> "3" ;
<http://xmlns.com/foaf/0.1/name>
"Claire" .
----------------- union
:claire a foaf:Person ;
:friend_id "1" ;
schema:identifier "3" ;
foaf:name "Claire" .
:alice a foaf:Person ;
schema:identifier "1" ;
foaf:name "Alice" .
:bob a foaf:Person ;
schema:identifier "2" ;
foaf:name "Bob" .
----------------- inference
'alignment rules loaded'
'rule matched: ' <http://example.org/claire> ' knows ' <http://example.org/alice>
:claire a foaf:Person ;
schema:identifier "3" ;
foaf:knows :alice ;
foaf:name "Claire" .
:alice a foaf:Person ;
schema:identifier "1" ;
foaf:name "Alice" .
:bob a foaf:Person ;
schema:identifier "2" ;
foaf:name "Bob" .
我试图以不同的方式来构成模型,即先构造推理模型,然后将其与参考相结合,无济于事。
如何将推理规则生成的三元组与查找数据分开保存在模型中?
是否可以在ttl
文件中而不是Java代码中定义它?