我使用RDF4J服务器和工作台版本2.2.2.我在RDF4J中使用了一个支持SPIN的存储库,并且我正在读取我在TobBraid Composer Free Edition(TBC FE)中创建的RDF文件,其中包含许多旋转:构造
规则。TBD FE设置为通过sp: text
属性为我的构造函数包含SPARQL源代码。我观察到,当存在使SPARQL源代码可供RDF4J使用的sp: text
三元组时,RDF4J似乎使用SPARQL源代码,而不是使用相同查询的RDF标记化表示。我的主要和次要问题是:
sp:text
和RDF表示时,如何指示RDF4J使用自旋构造函数的RDF表示
当我取消RDF4J的sp:text
SPARQL源代码表示时,构造函数使用在导入的RDF文件头部定义的前缀按预期运行。在实例化已定义构造函数的类之前,我可以通过执行查询删除源代码来剥夺RDF4J的源代码。我已使用此SPARQL更新查询来实现此目的:
PREFIX sp: <http://spinrdf.org/sp#>
DELETE {?s sp:text ?o .} WHERE {?s sp:text ?o .}
我希望在我正在构建的GUI中保留SPARQL源代码,以便通过SPARQL查询与RDF4J服务器通信。我笨拙的临时修复方法是使用下面步骤5中使用的SPARQL更新查询,用另一个自定义数据属性替换sp:text
属性。此属性替换成功地阻止RDF4J查找SPIN构造函数的SPARQL源代码。RDF4J然后解释规则的标记化RDF表示。有没有更干净的方法强制RDF4J从RDF而不是从SPARQL源代码执行SPIN构造函数?我认为一定有某种方法可以向RDF4J发送信号,以解释RDF表示,而不是SPARQL源代码,但我不知道如何解释。
现在是血淋淋的细节让这种情况重现。。。
请注意,此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) .
}
我在RDF4J工作台的修改→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 .
}
由于试图基于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
...
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工作台的Explore→ 探索函数以查看我们刚刚创建的实例化/个体,inst:aPub7TestClassInstance\u test1
。我们应该通过spin:hasConstratintViolation
属性看到实例化有一个约束违反通知,提供证据表明测试构造函数确实在没有sp:text
表示的情况下运行,被迫使用spin构造函数的RDF标记化表示。
我有一个不完整的、不优雅的变通方法来解决我关于在旋转规则中包含前缀的次要问题。作为初始化步骤,我运行以下SPARQL更新查询,将所需的前缀添加到每个sp: text
字符串。当然,这种解决方法是有限的,因为查询嵌入了我正在使用的前缀映射。如果需要其他前缀,则需要编辑下面的查询以嵌入新的查询定义。
下面是在类/规则/属性定义本体加载到RDF4J之后,但在加载实例化本体之前,我将SPARQL更新查询用作初始化步骤。(由于实例化本体开始调用SPIN构造函数,因此计时非常关键。)
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) .
}
如果前缀定义恰好包含在嵌入的字符串或注释中,则上述查询可能包含基于误报的前缀定义。例如,literal“Greg's solo:five measures”^^xsd:string
将导致上述查询包含olo:
前缀的定义,这可能是不必要的。然而,包含非必需的前缀对性能和正确性没有重大影响。在上面的查询中,使用正则表达式代替简单的CONTAINS
匹配项可以做得更好。
问题内容: 我有一个简单的RDF文件,想将其转换为漂亮的嵌套JSON。 应该成为 问题答案: 使用框架 版画 带绒球
我想将名称(ClassName)更改为一个不同的名称,例如(ClassA)。我可以通过编写SPARQL查询来实现吗? 作为一个工具包,我正在使用gena,我不确定我所询问的是可能的还是不可能的!
我正在使用Jena框架来操作RDF文件,但我找不到一种方法来用您各自的RDF模式验证RDF。我正在尝试这个方法: 但它总是返回true。
我正在尝试添加RDF的这个简单示例: 进入Blazegraph三重存储,但我得到以下错误: 据我所知,我正在密切检查名称空间。 我也试过这个例子: null
我已经在Scala中创建了一个blazegraph RDF4J存储库和连接: 我可以添加语句、检索SPARQL结果等。 现在我想将存储库的内容转储到一个RDF文件中,如下所示: 但是,如果我试图用或替换预期的模型参数,Eclipse会抱怨: 重载方法值write with备选项:(X$1:Iterable[org.openrdf.model.statement],X$2:java.io.write