0

我一直在使用 TopQuadrant Composer 免费版 (TBC FE) 将 SPARQL/SPIN 规则(主要是 SPIN 构造函数)嵌入到存储为 RDF 的 OWL 本体中。这个过程的一部分是根据http://spinrdf.org/sp.html将 SPARQL 源代码标记化/编码为 RDF 结构,该架构在http://spinrdf.org/sp中指定。正是这种结构实际上被 RDF4J 解释为运行 SPIN 规则。

我还使用 RDF4J 作为我的三重存储、推理器、SPARQL 端点和 SPIN 规则引擎。此外,我正在生成自定义 Java 代码和 GUI 来操作我的数据和规则。

我的问题是我可以在 Java 中使用什么将 SPARQL/SPIN 源代码编码为 RDF?请注意,我不是在问如何对查询结果进行编码(在另一个 stackoverflow 问题/响应中已回答),而是在问如何对查询本身进行编码。原因是我希望能够从我自己的 Java 代码中编辑 SPIN 规则,而不是仅仅依赖于 TBC FE。

另请注意,我知道存储原始 SPARQL 查询文本的选项。然而,我的经验是,这没有被正确解释,而标记化/结构化的 RDF 被正确解释。因此,我必须使用结构化 RDF。

我希望执行这种编码的大部分 Java 代码已经编写好了,也许是 Apache Jena 的一部分。我只需要一个关于在哪里看的指针。

谢谢!

PS:这是由 TBC FE 编码的示例 SPIN 构造函数的开始。它包括 SPARQL/SPIN 源代码的原始 sp:text 和结构化 RDF 的开头(在 sp:text 块之后)。这是我需要能够使用 Java 从 SPARQL 源代码生成的结构化 RDF。

     <sp:Construct>
        <sp:text rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
        ># [enabled] &lt;http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#Pub7Proposal_makeRxSCMPointSurface&gt; construct an SCM Point Surface (zero radius) from supporting rx data items under an SCM receiver model
CONSTRUCT {
    ?this soo:hasSCMReceiverModel ?receiverModelURI . 
    ?receiverModelURI soo:hasSCMPointSurfaceLocation ?pointSurfaceURI .
    ?pointSurfaceURI soo:SCMPointSurfaceHasPoint ?pointURI .&#xD;
    ?pointSurfaceURI a soo:SCMPointSurfaceLocation .
}
WHERE {
    ?this pub7:pub7ProposalHasDataItem ?rxRadiusDataItem .
    ?rxRadiusDataItem a pub7:Pub7DataItem406 .
    ?rxRadiusDataItem soo:hasSCMRadius ?radiusURI .
    ?radiusURI Nuvio:hasDataValue ?radiusValue .
    FILTER (?radiusValue = 0.0000) .
    ?this pub7:pub7ProposalHasDataItem ?rxPointDataItem .
    ?rxPointDataItem a pub7:Pub7DataItem403 .
    ?rxPointDataItem soo:hasSCMPointLocation ?pointURI .
    BIND (URI(CONCAT(str(?this), "_rxModel")) AS ?newReceiverModelURI) .
    BIND (IF(bound(?existingReceiverModelURI), ?existingReceiverModelURI, ?newReceiverModelURI) AS ?receiverModelURI) .
    BIND (URI(CONCAT(str(?receiverModelURI), "_pointSurface")) AS ?pointSurfaceURI) .
}</sp:text>
        <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
        >[enabled] &lt;http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#Pub7Proposal_makeRxSCMPointSurface&gt; construct an SCM Point Surface (zero radius) from supporting rx data items under an SCM receiver model</rdfs:comment>
        <sp:templates rdf:parseType="Collection">
          <rdf:Description>
            <sp:object rdf:parseType="Resource">
              <sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
              >receiverModelURI</sp:varName>
            </sp:object>
            <sp:predicate rdf:resource="http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#hasSCMReceiverModel"/>
            <sp:subject rdf:resource="http://spinrdf.org/spin#_this"/>
          </rdf:Description>
          <rdf:Description>
            <sp:object rdf:parseType="Resource">
              <sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
              >pointSurfaceURI</sp:varName>
            </sp:object>
            <sp:predicate rdf:resource="http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#hasSCMPointSurfaceLocation"/>
            <sp:subject rdf:parseType="Resource">
              <sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
              >receiverModelURI</sp:varName>
            </sp:subject>
          </rdf:Description>
          <rdf:Description>
            <sp:object rdf:parseType="Resource">
              <sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
              >pointURI</sp:varName>
            </sp:object>
            <sp:predicate rdf:resource="http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#SCMPointSurfaceHasPoint"/>
            <sp:subject rdf:parseType="Resource">
              <sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
              >pointSurfaceURI</sp:varName>
            </sp:subject>
          </rdf:Description>
          <rdf:Description>
            <sp:object rdf:resource="http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#SCMPointSurfaceLocation"/>
            <sp:predicate rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"/>
            <sp:subject rdf:parseType="Resource">
              <sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
              >pointSurfaceURI</sp:varName>
            </sp:subject>
          </rdf:Description>
        </sp:templates>
4

1 回答 1

1

正如@AKSW 所指出的,SPIN API 与 Jena 库相结合可以完成我所追求的。TopBraid 的SPINParsingExample.java非常接近我想要做的。

我确实需要将一个 SPIN 库和几个 Jena 库文件(.jar文件)添加到我的 Eclipse 项目和构建路径中。我知道有自动化的方法来处理这些依赖关系,但现在我是手动做的。对于那些也手动执行此操作的人,这些文件在下面列出...

旋转库:

Apache Jena 库(最好按照评论中的建议使用 3.0.1):

于 2017-08-23T22:45:43.493 回答