问题描述
我一直在使用TopQuadrant Composer免费版(TBC FE)在存储为RDF的OWL本体中嵌入SPARQL / SPIN规则(主要是SPIN构造函数)。此过程的一部分是根据,该模式在中指定。正是这种结构实际上被RDF4J解释为运行SPIN规则。
I have been using TopQuadrant Composer Free Edition (TBC FE) to embed SPARQL/SPIN rules (primarily SPIN constructors) in my OWL ontologies stored as RDF. Part of this process is that the SPARQL source code is tokenized/encoded in an RDF structure according to http://spinrdf.org/sp.html which the schema specified in http://spinrdf.org/sp. It is this structure that actually gets interpreted by RDF4J to run the SPIN rules.
我也使用RDF4J作为我的三重存储,推理器,SPARQL端点和SPIN规则引擎。另外,我正在生成自定义Java代码和GUI来操纵我的数据和规则。
I'm also using RDF4J as my triple store, reasoner, SPARQL endpoint, and SPIN rule engine. In addition, I'm generating custom Java code and GUIs to manipulate my data and rules.
我的问题是我可以在Java中使用什么来将SPARQL / SPIN源代码编码为RDF ?请注意,我不询问如何编码查询结果(在另一个stackoverflow问题/响应中回答),而是如何编码查询本身。原因是我想从我自己的Java代码中启用SPIN规则的编辑,而不是完全依赖于TBC FE。
My question is what can I use in Java to encode SPARQL/SPIN source code as RDF? Note that I'm not asking how to encode query results (which was answered in another stackoverflow question/response) but rather how to encode the query itself. The reason is that I would like to enable editing of SPIN rules from my own Java code rather than being solely reliant on TBC FE.
另请注意我知道的存储原始SPARQL查询文本的选项。但是,我的经验是,未正确解释这一点,而正确解释了标记化/结构化的RDF。因此,我必须使用结构化的RDF。
Also note that I'm aware of the option to store the original SPARQL query text. However, my experience has been that this is not correctly interpreted whereas the tokenized/structured RDF is correctly interpreted. Therefore, I must use the structured RDF.
我希望已经编写了许多用于执行此编码的Java代码,可能是Apache Jena的一部分。我只需要一个指针来查看。
I'm hoping that much of the Java code to do this encoding is already written, perhaps as part of Apache Jena. I just need a pointer as to where to look.
谢谢!
PS:这是示例的开头由TBC FE编码的SPIN构造函数。它包括SPARQL / SPIN源代码的原始sp:文本和结构化RDF的开头(在sp:text块之后)。这是我需要能够使用Java从SPARQL源代码生成的结构化RDF。
PS: Here's the start of example SPIN constructor encoded by TBC FE. It includes both the original sp:text of the SPARQL/SPIN source code and the start of the structured RDF (after the sp:text block). It's the structured RDF that I need to be able to generate using Java from the SPARQL source code.
<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指出的那样,SPIN API加上耶拿图书馆可以完成我追求的目标。 TopBraid的非常接近我想做的事情。
As @AKSW pointed out, a SPIN API coupled with the Jena libraries can accomplish what I'm after. TopBraid's SPINParsingExample.java is very close to what I want to do.
我确实需要添加一个SPIN库和几个Jena库文件( .jar
files)到我的Eclipse项目和Build Path。我知道有自动方法来处理这些依赖关系,但是现在我手动完成它。对于那些也手动操作的人,这些文件列在下面......
I did need to add one SPIN library and several Jena library files (.jar
files) to my Eclipse project and to the Build Path. I'm aware that there are automated ways to handle these dependencies, but for now I'm doing it manually. For those also doing it manually, these files are listed below...
SPIN库:
- spin-2.0.0.jar
Apache Jena库(最好按照评论中的建议使用3.0.1):
Apache Jena libraries (better to use 3.0.1 as suggested in comments):
- jena-arq-3.4.0.jar
- jena-base-3.4.0.jar
- jena-cmds-3.4.0.jar
- jena-core-3.4.0.jar
- jena-iri-3.4.0.jar
- jena-rdfconnection-3.4.0.jar
- jena-shaded-guava-3.4.0.jar
- jena-tdb-3.4.0.jar
- libthrift-0.9.1.jar
- xercesImpl-2.7.1.jar
这篇关于如何从Java将SPARQL / SPIN查询/规则转换为RDF结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!