【发布时间】:2017-08-23 01:54:03
【问题描述】:
我一直在使用 TopQuadrant Composer 免费版 (TBC FE) 将 SPARQL/SPIN 规则(主要是 SPIN 构造函数)嵌入到存储为 RDF 的 OWL 本体中。此过程的一部分是 SPARQL 源代码根据http://spinrdf.org/sp.html 在 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] <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>
【问题讨论】:
-
也许我错过了您的文字中的某些内容,但是您为什么不能简单地使用API?它的功能之一是“文本 SPARQL 语法和 SPIN RDF 词汇之间的转换器”
-
An example 显示从查询字符串到 SPIN RDF 的转换
-
实际上@AKSW,这就是我正在寻找的答案。我希望我的问题不是太简单。我已将 xercesimpl-2.7.1.jar、libthrift-0.9.1.jar、spin-2.0.0.jar 和 jena 3.4.0 jar 文件拉到我的项目和构建路径中,现在是您指出的示例运行。谢谢!我可以将其发布为我自己问题的答案,但这确实是您的答案,因此您可以根据需要发布答案。你的选择。谢谢!
-
别担心。通常,找到解决方案的简单方法是最好的。随意添加它作为答案,不要忘记接受它。干杯