Measuring distance between classes in RDF / OWL plots

Maybe someone can give me a hint. Is it possible to measure the distance between two concepts / classes related to the same ontology?

For example, suppose I have an ontology with an astronomical class and a telescope class. There is a connection between them, but this is not a direct connection. Astronomy has a parent class called Science, and the telescope has a parent class called Optical Instrument, which belongs to its parent element, Instrumentation, which belongs to the Empical Science class, which finally belongs to the Science class.

Thus, there is an indirect connection between the telescope and astronomy, and I want to know the number of steps required to reach one class, starting from another.

Is there a simple SPARQL query that resolves this issue? Or are there any better ways to make this work? Or is it impossible to find it with the semantic web paradigm?

Any hint would be greatly appreciated.

+6
source share
3 answers

In my understanding, SPARQL does not contain recursive constructions in order to be able to measure an indirect connection of arbitrary length. The best you can do is prepare a set of queries distance_1(a, b) , distance_2(a, b) ... to check for a specific distance between two concepts.

Another alternative is to discover this information using technology other than SPARQL, for example, to write a graph moving algorithm in Python using RDFlib.

+4
source

SPARQL provides the ability to search for arbitrary length paths in a graph, but there is no mechanism to tell you the length of this path.

So you can do something like:

 SELECT * WHERE { ?s ex:property+ ?o } 

The syntax is very similar to regex, so you can do alternatives, limited power, etc.

+5
source

Since you explicitly mentioned that you are talking about classes, and they will be in the same ontology, you can safely assume that they will always be connected (because ultimately both will be subclasses of “Thing”, right?). On the other hand, the path that I mentioned in parentheses (Class1 → ... → Thing <-... <- Class2) is trivial, so I assume that you want to find ... all existing paths between two classes in other words, all existing paths between two peaks. It's true? Or are you looking for the shortest path? Your question is not very clear in this aspect, can you clarify it?

As far as I know, there is no simple SPARQL construct that will list all the paths between classes or the shortest path. However, some semantic web stores contain graph traversal algorithms, such as width search or depth search, please refer to:

You can also find the source code for the following project very useful:

+2
source

Source: https://habr.com/ru/post/900051/


All Articles