当导入的RDF文件中存在SP:文本时,如何将RDF4J用于使用Spin RDF三元组



我正在使用RDF4J服务器和Workbench版本2.2.2。我在RDF4J中使用了可自旋的存储库,并且正在阅读我在Tobbraid Composer Free Edition(TBC FE)中创建的RDF文件,其中包含许多spin:construct规则。TBD FE设置为通过sp:text属性包含我构造函数的SPARQL源代码。我已经观察到,当sp:text三重速度在RDF4J可用的SPARQL源代码时,RDF4J似乎使用SPARQL源,而不是使用同一查询的RDF tokenized表示。我的主要和次要问题是:

  • sp:text和RDF表示都存在于导入的RDF文件中时,我如何指示RDF4J使用旋转构造器的RDF表示?
  • 如果RDF4J使用旋转构造器的sp:text表示,则如何使用导入的RDF文件头部存在的前缀定义?我到目前为止有69个构造函数。尽管我可以在每个构造函数中嵌入前缀定义,但这样做似乎很浪费。

当我剥夺rdf4j的 sp:text sparql源代码表示时,构造函数使用在导入的RDF文件的头部定义的前缀按预期运行。我可以通过执行查询来删除源代码来删除源代码,以删除源代码,然后在我实例化我定义构造函数的类之前。我已经使用此SPARQL更新查询来完成此目的:

PREFIX sp: <http://spinrdf.org/sp#>
DELETE {?s sp:text ?o .} WHERE {?s sp:text ?o .}

我想将SPARQL源代码保留在我正在构建的GUI中,以通过SPARQL查询与RDF4J服务器进行通信。我尴尬的临时修复程序是使用下面步骤5中使用的SPARQL更新查询替换sp:text属性的另一个自定义数据属性。该属性替代成功阻止了RDF4J为旋转构造器找到SPARQL源代码。然后,RDF4J改为解释该规则的标记RDF表示。是否有一种更干净的方法来强制RDF4J从RDF而不是从SPARQL源代码执行旋转构造函数?我认为必须有某种方式来发出RDF4J来解释RDF表示而不是SPARQL源代码,但我不知道如何。

现在的血腥详细信息使这种情况可再现...

  1. 使用RDF4J Workbench在RDF4J中创建一个可自旋的存储库。我的名为takerdf4j4spin(存储库→新存储库)
  2. 使用RDF4J Workbench清除存储库(修改→Clear)
  3. 使用RDF4J Workbench加载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的旋转构造函数为:

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) .
}
  1. 尝试创建pub7:Pub7TestClass的实例...

我在RDF4J Workbench的修改→Sparql Update中使用此SPARQL UPDATE查询来创建实例...

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 .
}

应该导致RDF4J Workbench中报告的前缀未定义错误,因为试图根据sp:text SPARQL源代码表示上述构造函数:

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
  1. 现在使用以下SPARQL更新查询:
  2. ,将旋转构造仪的 sp:text隐藏在rdf4j中:

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 . 
}
  1. 现在重新运行步骤4中显示的SPARQL更新查询以实例化测试类。这次更新查询应在没有错误的情况下运行。

  2. 现在使用RDF4J Workbench的探索→探索功能,以查看我们刚刚创建的实例化/个人inst:aPub7TestClassInstance_test1。应该看到,实例化通过spin:hasConstratintViolation属性有限制性违规通知,提供了证据表明,测试构造器确实在这段时间确实运行了sp:text表示,被迫使用旋转构造函数的RDF代币化表示。

我有一个部分,不高级的工作,可以解决我的次要问题,以解决旋转规则中的前缀。作为初始化步骤,我运行以下SPARQL Update查询,该查询添加了每个sp:text字符串所需的前缀。当然,由于查询嵌入了我使用的前缀映射,因此此工作范围是有限的。如果需要其他前缀,则需要对以下查询进行编辑以嵌入新的查询定义。

这是我使用的SPARQL更新查询作为初始化步骤,在将我的类/规则/属性定义定义已加载到RDF4J之后,但是在加载我的实例化本体本体之前。(时间至关重要,因为实例化本体论开始调用旋转构造函数。)

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) . 
}

,如果前缀定义恰好包含在嵌入式字符串或注释中,则可能在误报的前缀定义中包括一个前缀定义。例如,文字"Greg’s solo: five measures"^^xsd:string可能会导致上述查询包括olo:前缀的定义,也许是必需的。但是,包含不需要的前缀对性能没有重大影响,也没有对正确性的影响。通过使用正则表达式代替上述查询中的简单CONTAINS匹配项可以做得更好。

相关内容

  • 没有找到相关文章

最新更新