I have two classes, A and B, from DBpedia. How can I calculate the distance (number of edges) from each class to a common superclass C, and how can I find this common superclass?
相关问题
- Creating a SPARQL parameterized query using append
- Getting list of persons using SPARQL dbpedia
- Getting list of persons using SPARQL dbpedia
- How can I optimize a SPARQL query that returns opt
- Calculate the depth of subclass in the OWL ontolog
相关文章
- RDF libraries for Scala [closed]
- The difference between blank nodes and variables i
- How to display alert box when no json value is giv
- How to turn a SPARQL/SPIN query/rule into an RDF s
- Triple extraction from a sentance
- Meaning of owl:hasValue?
- boundary for arbitrary property path in SPARQL 1.1
- sparql complete tree from subject
You can do this, but a couple of things should be noted first:
A class D might be a superclass of C by multiple paths, which can cause some difficulties if you're trying to compute length. E.g.,
In this hierarchy, Dell Flatscreen Monitors is a subclass of Computer Hardware by a path of length 2 (DFM → DH → CH) and by a path of length 3 (DFM → FM → M →CH). That's fine, but if you're computing a length from DFM to another subclass of CH, which of those should you use?
owl:Thing
, but that doesn't hold for RDF in general, and you probably won't even get that result from DBpedia because there's no OWL reasoner attached.Assuming that you can work out the details that you need to address those issues, this isn't too hard. It's easiest, in my opinion, to build up this query step by step. First, using a query like this, you can get the superclasses of a class, and the length of the path to each of the superclasses. This does presume that there is a unique path from the subclass to the superclass. If there are multiple paths, I think the length reported will be the sum of the different paths. I'm not sure how you could get around this.
SPARQL results
Now the trick is to use this approach for both the subclasses, and then join the results based on the superclasses that they have in common, using a query like this:
SPARQL results
That query still finds the path lengths for all the common superclasses, not just most specific ones, and it's still not adding the length from
?a
to?super
and the length from?b
to?super
to get the full path length. That's just a bit of arithmetic though. You can order these results by the length, and then limit to just one result so that you're getting the shortest one. As I pointed out, there might not be a unique most specific common subclasses, but the result with the shortest length will be one of the most specific common subclasses.SPARQL results