Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

sparql - how to find classes from dbpedia?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...