Sparql 当导入的RDF文件中存在sp:text时,如何指示RDF4J使用旋转RDF三元组?
我使用的是RDF4J服务器和工作台版本2.2.2。我正在RDF4J中使用一个支持自旋的存储库,我正在阅读我在TobBraid Composer Free Edition(TBC FE)中创建的一个RDF文件,其中包含许多Sparql 当导入的RDF文件中存在sp:text时,如何指示RDF4J使用旋转RDF三元组?,sparql,rdf4j,topbraid-composer,spin-rdf,Sparql,Rdf4j,Topbraid Composer,Spin Rdf,我使用的是RDF4J服务器和工作台版本2.2.2。我正在RDF4J中使用一个支持自旋的存储库,我正在阅读我在TobBraid Composer Free Edition(TBC FE)中创建的一个RDF文件,其中包含许多SPIN:construct规则。TBD FE设置为通过sp:text属性为我的构造函数包含SPARQL源代码。我观察到,当出现sp:text三元组使SPARQL源代码可供RDF4J使用时,RDF4J似乎使用SPARQL源代码,而不是使用同一查询的RDF标记化表示。我的主要和次要
SPIN:construct
规则。TBD FE设置为通过sp:text
属性为我的构造函数包含SPARQL源代码。我观察到,当出现sp:text
三元组使SPARQL源代码可供RDF4J使用时,RDF4J似乎使用SPARQL源代码,而不是使用同一查询的RDF标记化表示。我的主要和次要问题是:
- 当导入的RDF文件中同时存在
和RDF表示时,如何指示RDF4J使用旋转构造函数的RDF表示?sp:text
- 如果RDF4J使用SPIN构造函数的
表示,如何引导它使用导入的RDF文件开头的前缀定义?到目前为止,我有69个构造函数。虽然我可以在每个构造函数中嵌入前缀定义,但这样做似乎很浪费sp:text
sp:text
SPARQL源代码表示时,构造函数使用在导入的RDF文件头部定义的前缀按预期运行。在实例化已定义构造函数的类之前,我可以通过执行查询删除源代码来剥夺RDF4J的源代码。我已使用此SPARQL更新查询来实现此目的:
PREFIX sp: <http://spinrdf.org/sp#>
DELETE {?s sp:text ?o .} WHERE {?s sp:text ?o .}
还请注意,附加到类pub7:Pub7TestClass
的SPIN构造函数是:
CONSTRUCT {
?this spin:hasConstraintViolation _:b0 .
_:b0 a spin:ConstraintViolation ;
rdfs:label "Test message." ;
spin:violationRoot ?this ;
spin:violationLevel spin:Error ;
spolicy:sPActionRecordHasTimestamp ?timestamp .
}
WHERE {
BIND(now() AS ?timestamp) .
}
pub7:Pub7TestClass
的实例李>
我在RDF4J工作台的Modify中使用这个SPARQL更新查询→ SPARQL更新以创建实例
PREFIX inst: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/Instantiations#>
PREFIX pub7: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#>
INSERT DATA {
inst:aPub7TestClassInstance_test1 a pub7:Pub7TestClass .
}
前缀sp:
前缀soo:
删除{
?originalPolicyURI sp:systemProperty?policySourceCodeString。
?originalPolicyURI sp:text?policySourceCodeString。
}
插入{
?originalPolicyURI-soo:policySourceCode?policySourceCodeString。
}
在哪里{
?originalPolicyURI sp:text?policySourceCodeString。
}
inst:aPub7TestClassInstance\u test1
。我们应该通过spin:hasConstratintViolation
属性看到实例化有一个约束违反通知,提供证据表明测试构造函数确实在没有sp:text
表示的情况下运行,被迫使用spin构造函数的RDF标记化表示我有一个局部的,不雅的工作来解决我的第二个问题,关于在旋转规则中包含前缀。作为初始化步骤,我运行以下SPARQL更新查询,向每个
sp:text
字符串添加所需的前缀。当然,这种解决方法是有限的,因为查询嵌入了我正在使用的前缀映射。如果需要其他前缀,则需要编辑下面的查询以嵌入新的查询定义
下面是在类/规则/属性定义本体加载到RDF4J之后,但在加载实例化本体之前,我将SPARQL更新查询用作初始化步骤。(由于实例化本体开始调用SPIN构造函数,因此计时非常关键。)
前缀sp:
删除{
?规则sp:文本?规则文本。
}
插入{
?规则sp:text?新规则text。
}
何处{
?规则sp:文本?规则文本。
绑定(如果(包含(?ruleText,“fn:”),“前缀fn:\n”,”)
AS?prefixComponent00)。
绑定(如果(包含(?ruleText,“owl:”),“前缀owl:\n”,”)
AS?prefixComponent01)。
绑定(如果(包含(?ruleText,“spin:”),“前缀spin:\n”,”)
AS?prefixComponent02)。
绑定(如果(包含(?规则文本,“spl:”),“前缀spl:\n”,”)
AS?prefixComponent03)。
绑定(如果(包含(?规则文本,“sp:”),“前缀sp:\n”,”)
AS?prefixComponent04)。
绑定(如果(包含(?ruleText,“par:”),“前缀par:\n”,”)
AS?prefixComponent05)。
绑定(如果(包含(?ruleText,“rdf:”),“前缀rdf:\n”,”)
AS?prefixComponent06)。
绑定(如果(包含(?ruleText,“rdfs:”),“前缀rdfs:\n”,”)
AS?prefixComponent07)。
绑定(如果(包含(?ruleText,“time:”),“前缀time:\n”,”)
AS?prefixComponent08)。
绑定(如果(包含(?ruleText,“xsd:”),“前缀xsd:\n”,”)
AS?prefixComponent09)。
绑定(如果(包含(?ruleText,“geo:”),“前缀geo:\n”,”)
AS?prefixComponent10)。
绑定(如果(包含(?ruleText,“geof:),“前缀geof:\n:,”)
AS?prefixComponent11)。
绑定(如果(包含(?ruleText,“inst:”),“前缀inst:\n”,“”)
AS?prefixComponent12)。
绑定(如果(包含(?ruleText,“pub7:),“前缀pub7:\n”,”)
AS?prefixComponent13)。
绑定(如果(包含(?ruleText,“pub8:”),“前缀pub8:\n”,”)
AS?prefixComponent14)。
绑定(如果(包含(?ruleText,“soo:”),“前缀soo:\n”,”)
AS?prefixComponent15)。
绑定(如果(包含(?ruleText,“spolicy:”),“前缀spolicy:\n”,“”)
AS?prefixComponent16)。
绑定(如果(包含(?ruleText,“共享:”),“前缀共享:\n”,”)
AS?prefixComponent17)。
绑定(如果(包含(?ruleText,“dd1494:”),“前缀dd1494:\n”,”)
AS?prefixComponent18)。
绑定(如果(包含(?ruleText,“Nuvio:”),“前缀Nuvio:\n”,”)
PREFIX inst: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/Instantiations#>
PREFIX pub7: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#>
INSERT DATA {
inst:aPub7TestClassInstance_test1 a pub7:Pub7TestClass .
}
org.eclipse.rdf4j.query.UpdateExecutionException: org.eclipse.rdf4j.repository.RepositoryException: org.eclipse.rdf4j.sail.SailException: org.eclipse.rdf4j.query.MalformedQueryException: org.eclipse.rdf4j.query.parser.sparql.ast.VisitorException: QName 'spin:hasConstraintViolation' uses an undefined prefix
PREFIX sp: <http://spinrdf.org/sp#>
PREFIX soo: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#>
DELETE {
?originalPolicyURI sp:systemProperty ?policySourceCodeString .
?originalPolicyURI sp:text ?policySourceCodeString .
}
INSERT {
?originalPolicyURI soo:policySourceCode ?policySourceCodeString .
}
WHERE {
?originalPolicyURI sp:text ?policySourceCodeString .
}
PREFIX sp: <http://spinrdf.org/sp#>
DELETE {
?rule sp:text ?ruleText .
}
INSERT {
?rule sp:text ?newRuleText .
}
WHERE {
?rule sp:text ?ruleText .
BIND (IF (CONTAINS(?ruleText, "fn:"), "PREFIX fn: <http://www.w3.org/2005/xpath-functions#>\n","")
AS ?prefixComponent00) .
BIND (IF (CONTAINS(?ruleText, "owl:"), "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n","")
AS ?prefixComponent01) .
BIND (IF (CONTAINS(?ruleText, "spin:"), "PREFIX spin: <http://spinrdf.org/spin#>\n","")
AS ?prefixComponent02) .
BIND (IF (CONTAINS(?ruleText, "spl:"), "PREFIX spl: <http://spinrdf.org/spl#>\n","")
AS ?prefixComponent03) .
BIND (IF (CONTAINS(?ruleText, "sp:"), "PREFIX sp: <http://spinrdf.org/sp#>\n","")
AS ?prefixComponent04) .
BIND (IF (CONTAINS(?ruleText, "par:"), "PREFIX par: <http://parliament.semwebcentral.org/parliament#>\n","")
AS ?prefixComponent05) .
BIND (IF (CONTAINS(?ruleText, "rdf:"), "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n","")
AS ?prefixComponent06) .
BIND (IF (CONTAINS(?ruleText, "rdfs:"), "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n","")
AS ?prefixComponent07) .
BIND (IF (CONTAINS(?ruleText, "time:"), "PREFIX time: <http://www.w3.org/2006/time#>\n","")
AS ?prefixComponent08) .
BIND (IF (CONTAINS(?ruleText, "xsd:"), "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n","")
AS ?prefixComponent09) .
BIND (IF (CONTAINS(?ruleText, "geo:"), "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n","")
AS ?prefixComponent10) .
BIND (IF (CONTAINS(?ruleText, "geof:"), "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>\n:","")
AS ?prefixComponent11) .
BIND (IF (CONTAINS(?ruleText, "inst:"), "PREFIX inst: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/Instantiations#>\n","")
AS ?prefixComponent12) .
BIND (IF (CONTAINS(?ruleText, "pub7:"), "PREFIX pub7: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#>\n","")
AS ?prefixComponent13) .
BIND (IF (CONTAINS(?ruleText, "pub8:"), "PREFIX pub8: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub8#>\n","")
AS ?prefixComponent14) .
BIND (IF (CONTAINS(?ruleText, "soo:"), "PREFIX soo: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#>\n","")
AS ?prefixComponent15) .
BIND (IF (CONTAINS(?ruleText, "spolicy:"), "PREFIX spolicy: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/spolicy#>\n","")
AS ?prefixComponent16) .
BIND (IF (CONTAINS(?ruleText, "sharing:"), "PREFIX sharing: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/sharing#>\n","")
AS ?prefixComponent17) .
BIND (IF (CONTAINS(?ruleText, "dd1494:"), "PREFIX dd1494: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/dd1494#>\n","")
AS ?prefixComponent18) .
BIND (IF (CONTAINS(?ruleText, "Nuvio:"), "PREFIX Nuvio: <http://cogradio.org/ont/Nuvio.owl#>\n","")
AS ?prefixComponent19) .
BIND (IF (CONTAINS(?ruleText, "CRO2:"), "PREFIX CRO2: <http://cogradio.org/ont/CRO2.owl#>\n","")
AS ?prefixComponent20) .
BIND (IF (CONTAINS(?ruleText, "olo:"), "PREFIX olo: <http://purl.org/ontology/olo/core#>\n","")
AS ?prefixComponent21) .
BIND (CONCAT(
?prefixComponent00,
?prefixComponent01,
?prefixComponent02,
?prefixComponent03,
?prefixComponent04,
?prefixComponent05,
?prefixComponent06,
?prefixComponent07,
?prefixComponent08,
?prefixComponent09,
?prefixComponent10,
?prefixComponent11,
?prefixComponent12,
?prefixComponent13,
?prefixComponent14,
?prefixComponent15,
?prefixComponent16,
?prefixComponent17,
?prefixComponent18,
?prefixComponent19,
?prefixComponent20,
?prefixComponent21
) AS ?prefixes ) .
BIND (CONCAT(?prefixes, "\n", ?ruleText) AS ?newRuleText) .
}