我一直在使用TopQuadrant Composer免费版(TBC FE)在存储为RDF的OWL本体中嵌入SPARQL / SPIN规则(主要是SPIN构造函数)。此过程的一部分是SPARQL源代码根据http://spinrdf.org/sp.html中http://spinrdf.org/sp指定的模式在RDF结构中进行标记/编码。正是这种结构实际上被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:文本和结构化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>
答案 0 :(得分:1)
正如@AKSW指出的那样,与Jena库结合的SPIN API可以实现我所追求的目标。 TopBraid的SPINParsingExample.java非常接近我想做的事情。
我确实需要在我的Eclipse项目和Build Path中添加一个SPIN库和几个Jena库文件( // Assign the location of the persons ics files to a variable to use later, then scan through all the files
// and place them in an array.
$personCalendars = '../folder01/calendars/person';
$personFiles = scandir($personCalendars);
// Find the ID of the person hat is logged in by looking through the session information.
$personID = $_SESSION['person_ID'];
// Get the url of the page that we are on and check the server name.
function url(){
return sprintf('%s//%s%s',
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https:' : 'http:',
$_SERVER['SERVER_NAME'],
$_SERVER['REQUEST_URI']
);
}
// Find the ID of the person in the file array
$getURL = preg_grep('/'.$personID.'/',$personFiles);
// Set the pointer of the array to the first part of the url
$filename = reset($getURL);
// If there is an ics file for the person, grab the URL of the page and add on the filename
// eg: portal.company/index.php/calendar?99203.ics
// If no file is found, say so.
if ($filename){
$fullURL = url() . '?' . $filename;
echo $fullURL;
}else{
echo 'File not found\n';
}
文件)。我知道有自动方法来处理这些依赖关系,但是现在我手动完成它。对于那些也手动完成的人,这些文件列在下面......
SPIN库:
Apache Jena库(最好按照评论中的建议使用3.0.1):