0

My final goal is to get the least common ancestor of a class from an owl file ( for example if i choose AP and TP the result should be base ) base-----=AP |----TP

Iam trying to subclass of a class but no result !

for information i tried this and it doent work for me : How to get Least common subsumer in ontology using SPARQL Query?

I need help please

python file :

from owlready2 import *
onto = get_ontology("file://ess.owl").load()
owlready2.JAVA_EXE = "C:\\Program Files (x86)\\Java\jre1.8.0_311\\bin"
print(list(default_world.sparql("""
           SELECT (?x AS ?nb)
           { ?x a owl:Class . }
    """)))
print(list(default_world.sparql("""
           SELECT ?y
           {  "Star" rdfs:subClassOf ?y }
    """)))   ```
  • `"Star" rdfs:subClassOf ?y` is a useless triple pattern as subjects in RDF can't be string literals – UninformedUser Nov 18 '21 at 20:25
  • "doesn't work" is not a helpful description of what you tried and what happened ... and yes, the SPARQL query in the linked answer has to be adapted, you don't have instances, thus, you don't need the `rdf:type` part, provide the two given class URIs instead of the URIs of the instances (in both place, the outer graph pattern as well as the `FILTER NOT EXISTS` pattern The rest remains the same – UninformedUser Nov 18 '21 at 20:32
  • Thanks for your excellent hint, i can now run this query :D SELECT ?subclass WHERE { ?subclass rdfs:subClassOf ; } – Ashraf Jabnoun Nov 18 '21 at 21:12
  • URI=http://www.semanticweb.org/pc/ontologies/2021/10/untitled-ontology-5 Could please help me to adapt this query ? select ?lcs where { ?lcs ^(rdfs:subClassOf*) , ; a owl:Class . filter not exists { ?llcs ^(rdfs:subClassOf*) , ; a owl:Class ; rdfs:subClassOf+ ?lcs . } } OLAP OLAP OLAP OLAP – Ashraf Jabnoun Nov 18 '21 at 21:45
  • hm, what is missing for you? I mean, you should indeed use a `DISTINCT` to omit duplicates, i.e. do `select distinct ?lcs where` - or do you have any other issues? – UninformedUser Nov 20 '21 at 09:03

0 Answers0