开发者

How to get namespace of the property in dbpedia by giving the property name using jena?

I am trying to 开发者_JAVA百科get the value of property genre in the following dbpedia link using sparql in jena http://dbpedia.org/page/Black_Sabbath

But i have no idea how to get the property namespace from dbpedia (dbpedia-owl.genre in my example) I dont want to hard code it. Can any one help me plz...

Thanks a lot


Your initial question makes me think that you want something like Jena schemagen, which will automatically generate a collection of Java constants from the identifier URI's used in an ontology. However, the DbPedia OWL schema is rather large, and I think that schemagen may not generate a useful result (I haven't tried it). If so, you could always select a subset of resources and properties that you are interested in, and run schemagen on that subset.

However, your clarification comment, in which you talk about using other properties like latitude, etc, makes me think that you're asking a different question: namely, how to avoid having particular properties hard-coded into SPARQL queries. Whether this is a problem for you depends entirely on the problem you're trying to solve and the architecture of your code. It's perfectly possible for a program to maintain many SPARQL query strings, and just select the one that it needs for a particular job. That's a common usage pattern.

However, there are legitimate use cases where you want to take a general query string - for example select * where {?s ?p "foo"} - and ensure that one of the variables is bound in advance to a particular value. While it's possible to do this with string manipulation, there's a more elegant way. For example, to take the above query, and pre-bind ?p to the property dc:creator, you can do:

String q = "select * where {?s ?p \"foo\"}";
QuerySolutionMap qsm = new QuerySolutionMap();
qsm.bind( "p", DC.creator );
Query query = QueryFactory.create( q );
QueryExecution exec = QueryExecutionFactory.create( query, model, qsm );
ResultSet rs = exec.execSelect();

See also this blog posting for additional information, or the JavaDoc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜