【问题标题】:Blank node skolemization in SPARQL without iteration没有迭代的 SPARQL 中的空白节点 skolemization
【发布时间】:2018-05-10 20:45:24
【问题描述】:

是否可以在 SPARQL 中实现 blank node skolemization 而无需迭代?在我看来,需要迭代来完成空白节点链,例如:

@prefix : <http://example.com/> .

[ a :A ;
  :p1 [
    a :B
  ]
] .

用于 skolemization 的 SPARQL 更新操作可以从仅在三元组中显示为主体的空白节点开始,而没有空白节点对象:

DELETE {
  ?b1 ?outP ?outO .
  ?inS ?inP ?b1 .
}
INSERT {
  ?iri ?outP ?outO .
  ?inS ?inP ?iri .
}
WHERE {
  {
    SELECT ?b1 (uuid() AS ?iri)
    WHERE {
      {
        SELECT DISTINCT ?b1
        WHERE {
          ?b1 ?p1 [] .
          FILTER isBlank(?b1)
          FILTER NOT EXISTS {
            ?b1 ?p2 ?b2 .
            FILTER isBlank(?b2)
          }
        }
      }
    }
  }
  ?b1 ?outP ?outO .
  OPTIONAL {
    ?inS ?inP ?b1 .
  }
}

可以重复此操作,直到在数据中找不到空白节点:

ASK {
  ?bnode ?p [] .
  FILTER isBlank(?bnode)
}

是否可以在单个 SPARQL 更新操作中避免迭代并实现空白节点 skolemization?

(此外,此方法假设没有“孤立”空白节点(即仅作为对象出现的空白节点)。

【问题讨论】:

    标签: sparql blank-nodes


    【解决方案1】:

    我找到了一个两步解决方案,分别计算主题和对象并将空白节点别名(空白节点和 IRI 之间的链接通过owl:sameAs)存储为中间数据:

    PREFIX :    <http://example.com/>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    
    ####################
    # Rewrite subjects #
    ####################
    
    DELETE {
      ?bnode ?p ?o .
    }
    INSERT {
      ?iri ?p ?o .
      GRAPH :aliases {
        ?bnode owl:sameAs ?iri .
      }
    }
    WHERE {
      {
        SELECT ?bnode (uuid() AS ?iri)
        WHERE {
          {
            SELECT DISTINCT ?bnode
            WHERE {
              ?bnode ?p [] .
              FILTER isBlank(?bnode)
            }
          }
        }
      }
      ?bnode ?p ?o .
    }
    ;
    
    ###################
    # Rewrite objects #
    ###################
    
    DELETE {
      ?s ?p ?bnode .
    }
    INSERT {
      ?s ?p ?iri .
    }
    WHERE {
      {
        SELECT ?bnode ?iri
        WHERE {
          {
            SELECT DISTINCT ?bnode
            WHERE {
              [] ?p ?bnode .
              FILTER isBlank(?bnode)
            }
          }
          OPTIONAL {
            GRAPH :aliases {
              ?bnode owl:sameAs ?_iri .
            }
          }
          BIND (coalesce(?_iri, uuid()) AS ?iri)
        }
      }
      ?s ?p ?bnode .
    }
    ;
    
    ############################
    # Clear blank node aliases #
    ############################
    
    CLEAR GRAPH :aliases
    

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 2017-04-12
      • 2018-03-13
      • 2016-03-14
      • 2014-03-16
      • 2017-10-22
      • 2017-10-11
      • 1970-01-01
      • 2017-11-03
      相关资源
      最近更新 更多