1

I would like to find the first common superclass(es) between several Wikidata entities.

Let's take a bridge and a cemetery. What is their "smallest" common superclass?

  • A bridge is a subclass of "architectural structure".
  • A cemetery is a subclass of "place of worship", which is a subclass of "architectural structure".

---> Their most specialized common class is "architectural structure".

This Sparql query is close to the solution :

SELECT ?classe ?classeLabel WHERE {

wd:Q12280 wdt:P279* ?classe .
FILTER  EXISTS { wd:Q39614 wdt:P279* ?classe .}

 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

}

Problem: it returns all common classes between both items, not just the first ones. How could I filter the answer to get what I want?

Ettore Rizza
  • 2,800
  • 2
  • 11
  • 23
  • 1
    Well, your query doesn't reflect in any sense the definition of *Least Common Subsumer*(LCV) You're simply querying for all superclasses `A` of `bridge` and `for all superclasses `B` of `cemetery` and then you return classes contained in `A` and `B`. You should check the definition of LCS and see which other condition is necessary. – UninformedUser Dec 26 '17 at 16:42
  • Least Common Subsumer is certainly the phrase I was looking for, but I did not know it existed and could not search Google effectively. – Ettore Rizza Dec 26 '17 at 16:46
  • 1
    Here we go: `SELECT ?classe ?classeLabel WHERE { wd:Q12280 wdt:P279* ?classe . wd:Q39614 wdt:P279* ?classe . filter not exists { ?otherClass wdt:P279 ?classe ; ^wdt:P279* wd:Q12280, wd:Q39614 . } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }` – UninformedUser Dec 26 '17 at 16:47
  • 1
    Note, there is not always a unique LCS! – UninformedUser Dec 26 '17 at 16:47
  • Oh, thank you very much! But could you publish this query in an answer, so I can accept it? – Ettore Rizza Dec 26 '17 at 16:49

1 Answers1

0

If this question is of interest to someone else, here is the SPAQL query I finally use to get the Least common subsumers of more than two items. This is a mix between @AKSW response in comments and the answer to that previous question on SO.

SELECT ?lcs ?lcsLabel WHERE {

    ?lcs ^wdt:P279* wd:Q32815, wd:Q34627, wd:Q16970, wd:Q16560 .
    filter not exists {
    ?sublcs ^wdt:P279* wd:Q32815, wd:Q34627, wd:Q16970, wd:Q16560 ;
          wdt:P279 ?lcs .
      }

      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
    }

Try it.

Ettore Rizza
  • 2,800
  • 2
  • 11
  • 23