简体   繁体   English

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

[英]How to turn a SPARQL/SPIN query/rule into an RDF structure from Java?

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. 我一直在使用TopQuadrant Composer Free Edition(TBC FE)将SPARQL / SPIN规则(主要是SPIN构造函数)嵌入到以RDF存储的OWL本体中。 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 . 此过程的一部分是,根据http://spinrdf.org/sp.htmlhttp://spinrdf.org/sp中指定的架构,以RDF结构对SPARQL源代码进行标记化/编码。 It is this structure that actually gets interpreted by RDF4J to run the SPIN rules. RDF4J实际解释的就是这种结构,以运行SPIN规则。

I'm also using RDF4J as my triple store, reasoner, SPARQL endpoint, and SPIN rule engine. 我还将RDF4J用作三元组存储,推理程序,SPARQL端点和SPIN规则引擎。 In addition, I'm generating custom Java code and GUIs to manipulate my data and rules. 另外,我正在生成自定义Java代码和GUI,以操纵我的数据和规则。

My question is what can I use in Java to encode SPARQL/SPIN source code as RDF ? 我的问题是我可以在Java中使用什么将SPARQL / SPIN源代码编码为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. 请注意,我不是在问如何编码查询结果(在另一个stackoverflow问题/响应中回答),而是在询问如何编码查询本身。 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. 原因是我想启用自己的Java代码中的SPIN规则编辑功能,而不是仅依赖于TBC FE。

Also note that I'm aware of the option to store the original SPARQL query text. 还要注意,我知道可以存储原始SPARQL查询文本的选项。 However, my experience has been that this is not correctly interpreted whereas the tokenized/structured RDF is correctly interpreted. 但是,根据我的经验,这不能正确解释,而标记化/结构化RDF可以正确解释。 Therefore, I must use the structured RDF. 因此,我必须使用结构化RDF。

I'm hoping that much of the Java code to do this encoding is already written, perhaps as part of Apache Jena. 我希望已经编写了许多用于执行此编码的Java代码,也许是Apache Jena的一部分。 I just need a pointer as to where to look. 我只需要一个指向哪里的指针。

Thanks! 谢谢!

PS: Here's the start of example SPIN constructor encoded by TBC FE. PS:这是由TBC FE编码的示例SPIN构造函数的开始。 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). 它既包括SPARQL / SPIN源代码的原始sp:text,也包括结构化RDF的开头(在sp:text块之后)。 It's the structured RDF that I need to be able to generate using Java from the SPARQL source code. 我需要能够使用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>

As @AKSW pointed out, a SPIN API coupled with the Jena libraries can accomplish what I'm after. 正如@AKSW所指出的,结合Jena库的SPIN API可以完成我所追求的。 TopBraid's SPINParsingExample.java is very close to what I want to do. TopBraid的SPINParsingExample.java与我想做的非常接近。

I did need to add one SPIN library and several Jena library files ( .jar files) to my Eclipse project and to the Build Path. 我确实需要向我的Eclipse项目和“构建路径”中添加一个SPIN库和几个Jena库文件( .jar文件)。 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 library: SPIN库:

Apache Jena libraries (better to use 3.0.1 as suggested in comments): Apache Jena库(最好使用注释中建议的3.0.1):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM