如何将SPARQL/SPIN查询/规则从Java转换为RDF结构?



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

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

我的问题是,我可以在Java中使用什么来将SPARQL/SPIN源代码编码为RDF? 请注意,我不是在问如何对查询结果进行编码(在另一个堆栈溢出问题/响应中回答了这个问题(,而是在问如何对查询本身进行编码。 原因是我想从我自己的 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>

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

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

旋转库:

  • 自旋-2.0.0.jar

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

  • 耶拿-arq-3.4.0.jar
  • 耶拿基地-3.4.0.jar
  • 耶拿-CMDS-3.4.0.jar
  • 耶拿核心-3.4.0.jar
  • 耶拿-IRI-3.4.0.jar
  • 耶拿-RDF连接-3.4.0.jar
  • 耶拿-阴影番石榴-3.4.0.jar
  • 耶拿-TDB-3.4.0.jar
  • libthrift-0.9.1.jar
  • xercesImpl-2.7.1.jar

最新更新