[英]How to turn a SPARQL/SPIN query/rule into an RDF structure from Java?
我一直在使用TopQuadrant Composer Free Edition(TBC FE)将SPARQL / SPIN规则(主要是SPIN构造函数)嵌入到以RDF存储的OWL本体中。 此过程的一部分是,根据http://spinrdf.org/sp.html在http://spinrdf.org/sp中指定的架构,以RDF结构对SPARQL源代码进行标记化/编码。 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] <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#Pub7Proposal_makeRxSCMPointSurface> 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 .
?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] <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#Pub7Proposal_makeRxSCMPointSurface> 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所指出的,结合Jena库的SPIN API可以完成我所追求的。 TopBraid的SPINParsingExample.java与我想做的非常接近。
我确实需要向我的Eclipse项目和“构建路径”中添加一个SPIN库和几个Jena库文件( .jar
文件)。 我知道有自动方法可以处理这些依赖关系,但现在我是手动完成的。 对于那些也手动执行的操作,下面列出了这些文件...
SPIN库:
Apache Jena库(最好使用注释中建议的3.0.1):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.