0

我试图在内存中保留一个带有参考数据的大模型,并用推理规则附加其他模型,当新的三元组出现时,我需要匹配规则来触发,查找参考数据和所有新的三元组以结束第二个模型。

像这样:

#Reference data:

    :alice
        foaf:name   "Alice" ;
        schema:identifier "1" ;
        .

#New incoming triples:

    :claire
        foaf:name   "Claire" ;
        schema:identifier "3" ;
        :friend_id   "1" ;
        .

当 Claire 到达时,应该触发一个规则,通过 id 在参考数据中找到 Alice 并生成额外的三元组

:alice foaf:knows :claire

这应该与正在填充的模型中的 Claire 记录一起结束,而不是 Alice 所在的那个。

我对此的最新尝试:

    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 代码中定义它?

此示例的完整代码在 GitHub 上

4

0 回答 0