1

I have a label called forgiveness, and I want to obtain the classes, subclasses, superclasses, properties, and instances of this label using SPARQL query language. Please how do I construct these queries? Your responses are so much appreciated.

9
  • What do you mean by "label"? The word "label" is not part of the RDF concepts. Aug 6, 2012 at 7:09
  • Thanks for responding. Label in this context means a keyword or a string. So I have a keyword called forgiveness, and I want to obtain the classes, subclasses, superclasses, properties, and instances of this label using SPARQL query language. I hope its clear now. Thanks. Aug 6, 2012 at 7:13
  • It's clearer what you mean by "label" but then I don't understand what is a subclass of a label, an instance of a label, etc. Aug 6, 2012 at 10:59
  • I want to obtain the class of this label/keyword first, before obtaining the remaining parameters like the subclass, superclass etc. That's what I mean. Aug 6, 2012 at 14:20
  • I don't think anyone can answer this question without some example data - it doesn't really make sense. Aug 6, 2012 at 14:44

1 Answer 1

3

As stated in the comments, the gist of the question is to find all occurrences of a literal in a data set.

In an RDF triple (sujbect, property, object), a literal can only appear as the object. In this case, we don't care what the subject and property are. All is accepted.

The following query does just that (notice that we only want 'forgiveness' as an English word):

SELECT * WHERE{
 ?subject ?property "forgiveness"@en .
}

Running it against the DBpedia sparql endpoint yields some results. You can try it. I must say this is a very uncommon literal on DBpedia.

Another way to do it would be to use a filter instead of a plain literal. The following query finds 'forgiveness' regardless of the capitalization.

SELECT * WHERE{
 ?subject ?property ?literal .
 FILTER regex(?literal, "forgiveness", "i")
}

The second argument for regex is the pattern to match. You can achieve much more than case-insensitivity. For more information, check the XQuery regular expression language

6
  • Thanks Tom for your inputs. Is it possible for me to get things like the class, subclass, superclass, properties and instances of this literal? Because I want to run this queries on several datasets' sparql endpoints and see which dataset has the most resource about this literal. Aug 7, 2012 at 6:47
  • Literals in plain RDF don't have classes or properties. The queries above return instances. I think you can only find similar information in data sets created in RDF Schema. It's an extension of RDF that's capable of self-description. I'm afraid I can't come up with the right query as I simply don't understand your intentions here. Reading about RDF concepts should help you clarify your questions. Aug 7, 2012 at 6:57
  • 1
    The thing is, a literal itself does not convey information on its meaning. You'd have to reach to the property that refers to it. Here's a short explanation. My queries can be modified to take into account specific restrictions for the property in question. That way, you could extract information on the context in which, your literal appears. Is that what you mean? Aug 7, 2012 at 7:07
  • Tom, I am so confused myself. I had done something like this: SELECT ?uri ?label WHERE { ?uri rdfs:label ?label . filter(?label="Wave"@en) } And this queriy gave me a URI. I was thinking that with the URI, I can go on to find the properties subclasses superclasses etc. Aug 7, 2012 at 7:11
  • @user1577932 rdfs:label serves as a human-readable alternative for the objects URL. In order to find such information about the "Waves" that you find, you have to use the ?uri. The label itself is a dead-end. The following query extracts all information about the object that has "Wave"@en as a label: SELECT ?.uri ?label ?otherproperty ?otherobject WHERE { ?uri rdfs:label ?label . ?uri ?otherproperty ?otherobject. filter(?label="Wave"@en) }. You can also switch ?uri and ?otherobject to get the list of resources that have the labeled resource as a property Aug 7, 2012 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.