4
$\begingroup$

I've a list of Entities from Wikidata

listOfKeys = {"Ambientalismo", "Anoressia", "Aspetto fisico", 
   "Attivismo", "Burocrazia", "COVID-19", "Cambiamento climatico", 
   "Canoni estetici"};

list3 = First[#, Missing["NotFound"]] & /@ (WikidataSearch /@ 
    listOfKeys) //DeleteMissing

Then I defined a function to look for the parent of the Entity and apply it to the element of the list: (this instruction

ExternalIdentifier["WikidataID", 
     "P279", <|"Label" -> "SubclassOf"|>]

means that the ID is P279 and it's human readable meaning is SubclassOf)

findParent := # -> 
   WikidataData[#, 
    ExternalIdentifier["WikidataID", 
     "P279", <|"Label" -> "SubclassOf"|>]] &

Graph[findParent /@ list3]

The result first problem is that the graph should connect an entity to another entity, while I get a list of associations between 1 entity and a list of entities.

enter image description here

$\endgroup$
4
$\begingroup$

Define findParent as:

ClearAll[findParent]
findParent = Thread[# -> WikidataData[#, 
   ExternalIdentifier["WikidataID", "P279", <|"Label" -> "SubclassOf"|>]] ] &; 

edges = Flatten[findParent /@ list3];

Graph[edges, 
 VertexShapeFunction -> 
    (Text[Framed @ Style[#2["Label"] /. _Missing -> #2, Black, 12], #] &), 
 ImageSize -> 900] 

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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