我在RDF4J中使用支持SPIN的存储库,并且在包含许多 spin:construct
规则的TobBraid Composer免费版(TBC FE)中创建了我 . TBD FE设置为通过 sp:text
属性为我的构造函数包含SPARQL源代码 . 我观察到,当存在 sp:text
三元组使得SPARQL源代码可用于RDF4J时,RDF4J似乎使用SPARQL源而不是使用相同查询的RDF标记化表示 . 我的主要和次要问题是:
-
How can I direct RDF4J to use the RDF representation of a SPIN constructor when both the sp:text and the RDF representation are present in the imported RDF file?
-
If RDF4J uses the sp:text representation of a SPIN constructor, how can it be directed to use the prefix definitions present at the head of the imported RDF file? 到目前为止,我有69个构造函数 . 虽然我可以在每个构造函数中嵌入前缀定义,但这样做似乎很浪费 .
当我剥夺RDF4J的 sp:text
SPARQL源代码表示时,构造函数使用在导入的RDF文件头部定义的前缀按预期运行 . 我可以通过在我实例化已定义构造函数的类之前执行查询来删除源代码来剥夺RDF4J的源代码 . 我已经使用此SPARQL更新查询来完成该目的:
PREFIX sp: <http://spinrdf.org/sp#>
DELETE {?s sp:text ?o .} WHERE {?s sp:text ?o .}
我是通过SPARQL查询与RDF4J服务器通信的建筑物 . 我尴尬的临时修复是使用下面步骤5中使用的SPARQL更新查询替换 sp:text
属性的另一个自定义数据属性 . 此属性替换成功阻止RDF4J查找SPIN构造函数的SPARQL源代码 . 然后RDF4J解释规则的标记化RDF表示 . 有没有更简洁的方法来强制RDF4J从RDF而不是从SPARQL源代码执行SPIN构造函数?我知道怎么做了 .
现在,血腥的细节使这种情况可以重现......
-
使用RDF4J工作台在RDF4J中创建支持SPIN的存储库 . 我的名字叫TakeRDF4J4SPIN(Repositories→New Repository)
-
使用RDF4J工作台清除存储库(修改→清除)
-
使用RDF4J工作台加载pub7.rdf ...(修改→添加w /使用基URI作为上下文标识符未选中)
请注意,此RDF文件定义文件头部的所有相关前缀:
<?xml version="1.0"?>
<rdf:RDF
xmlns:fn="http://www.w3.org/2005/xpath-functions#"
xmlns:soo="http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/SpectrumOperationsOntology#"
xmlns:spolicy="http://www.disa.mil/dso/a2i/ontologies/PBSM/Sharing/spolicy#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:spin="http://spinrdf.org/spin#"
xmlns:sp="http://spinrdf.org/sp#"
xmlns:smf="http://topbraid.org/sparqlmotionfunctions#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:arg="http://spinrdf.org/arg#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:pub7="http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:spl="http://spinrdf.org/spl#"
xml:base="http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/Pub7">
另请注意,附加到类 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 Update中使用此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:text
SPARQL源代码表示执行上述构造函数,导致RDF4J工作台中报告的前缀未定义错误:
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
- 现在使用以下SPARQL更新查询从RDF4J隐藏SPIN构造函数'
sp:text
:
.
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 .
}
-
现在重新运行步骤4中显示的SPARQL更新查询以实例化测试类 . 这次更新查询应该没有错误地运行 .
-
现在使用RDF4J Workbench的Explore→Explore功能来查看我们刚刚创建的实例/个人
inst:aPub7TestClassInstance_test1
. 应该看到实例化通过spin:hasConstratintViolation
属性有一个约束违规通知,提供证据表明测试构造函数确实在没有sp:text
表示的情况下运行,强制使用SPIN构造函数的RDF标记化表示 .
1 回答
我有一个部分的,不优雅的解决方案,以解决关于在旋转规则中包含前缀的第二个问题 . 作为初始化步骤,我运行以下SPARQL更新查询,为每个
sp:text
字符串添加所需的前缀 . 当然,这种解决方法是有限的,因为查询嵌入了我正在使用的前缀映射 . 如果需要其他前缀,则需要编辑下面的查询以嵌入新的查询定义 .这是我在将类/规则/属性定义本体加载到RDF4J之后但在加载我的实例化本体之前使用的SPARQL更新查询作为初始化步骤 . (自实例化本体开始调用SPIN构造函数以来,时序至关重要 . )
如果前缀定义恰好包含在嵌入的字符串或注释中,则上述查询可能包含基于误报的前缀定义 . 例如,文字
"Greg’s solo: five measures"^^xsd:string
会导致上述查询包含olo:
前缀的定义,可能是不必要的 . 但是,包含非必需的前缀对性能没有重大影响,对正确性没有影响 . 通过使用正则表达式代替上面查询中的简单CONTAINS
匹配,可以做得更好 .