首页 > 解决方案 > SPARQL查询手工本体.owl

问题描述

我正在尝试从我建模的本体中进行 SPARQL 查询,但是在确定应该使用哪些前缀时遇到了麻烦。例如,如何从该本体、Pub 类中返回所有个体(owl:NamedIndividuals)以及所有子类数据(标签、描述、CID 等)?

对于此类查询,我使用 Protégé 'SPARQL Query' 插件

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?s ?o ?p
    WHERE { ?s rdf:type owl:NamedIndividual .
            FILTER ( ?s = 'Philosophy' )
          }

本体: https ://ipfs.io/ipfs/QmYdBz4hTwhStf5eR7fv6imoKny82Y9QbyqNoZAbjceXiu

编辑。分享这个问题的部分解决方案

SELECT ?subject ?description ?date ?tags
WHERE {

    #?subject <http://127.0.0.1:8000/gott2.owl#has_CID> <http://127.0.0.1:8000/gott2.owl#QmWCpZXGECFmwyoySt86LkJduE275iMffsNu6dFZ8q23h4>.
  
  OPTIONAL {?subject <http://127.0.0.1:8000/gott2.owl#has_CID> ?object.}
  OPTIONAL {?subject  <http://127.0.0.1:8000/gott2.owl#has_description> ?description.}
  OPTIONAL {?subject  <http://127.0.0.1:8000/gott2.owl#has_tags> ?tags.}
  OPTIONAL {?subject  <http://127.0.0.1:8000/gott2.owl#has_date> ?date.}
  
  BIND (STR(?subject) AS ?s) .
  BIND (STR(?tags) AS ?t) .

  OPTIONAL { FILTER CONTAINS ( LCASE(?s) , ENCODE_FOR_URI("philosophy"))} .
  OPTIONAL { FILTER CONTAINS ( LCASE(?t) , ENCODE_FOR_URI("philosophy"))} .
}

标签: sparqlowlontology

解决方案


推荐阅读