how to find classes from dbpedia?

三世轮回 提交于 2019-12-25 18:33:51

问题


I need a sparql query that given a free text (user input), it finds me from dbpedia all the classes related to it.

How do it?


回答1:


Also asked here. Accepted answer said --

When you say classes, are you mean about types? If yes, try something like

SELECT ?uri ?label ?type
WHERE {
?uri rdfs:label ?label .
?uri <http://dbpedia.org/ontology/type> ?type .
FILTER regex(str(?label), "Leipzig") .
}
limit 10

I couldn't let this go...

PREFIX     rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  virtdrf:  <http://www.openlinksw.com/schemas/virtrdf#>

SELECT      ?s1c AS ?c1 
       COUNT (*) AS ?c2 
                    ?c3
WHERE 
  { 
    QUAD MAP virtrdf:DefaultQuadMap 
    { 
      GRAPH ?g 
      { 
         ?s1  ?s1textp      ?o1          .
         ?o1  bif:contains  '"dbpedia"'  .
      }
    }
    ?s1 a ?s1c .
    OPTIONAL { ?s1c  rdfs:label  ?c3 
               FILTER(langMatches(LANG(?c3),"EN"))}
  }
GROUP BY ?s1c ?c3
ORDER BY DESC (2) ASC (3)

The earlier answer gets you partial results.



来源:https://stackoverflow.com/questions/48888524/how-to-find-classes-from-dbpedia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!