def traitement(f): #Fonction pour transformer un fichier .owl ou .rdf en noeuds.json + liens.json ont = Ontology() #Chargement de l'ontologie ont.load(location=mergedlist[f]) #Transformation en JSON edgestemp = '[ ' nodestemp = '[' for cls in ont.classes: if cls.is_named(): nodestemp += str('{"id" : "' + str(cls.uri) + '",') laaaables = ont.get_labels(cls.uri) for labelo in laaaables: nodestemp += str('"label" : "' + labelo + '"') #rajouter une alternative si y'a pas de labels ? (exemple de cmt) for s, p, o in cls.triples: if (o == cls.uri and s.split('/')[0] == "http:"): edgestemp += str('{"from" : "' + str(o) + '", "to" : "' + str(s) + '"},') nodestemp += str("},") nodes = nodestemp[:-1] nodes += str("]") edges = edgestemp[:-1] edges += str("]") #Export des fichiers json #with open('C:/projetPtutTuto/ProjetPtut/environnementPtut/Ontoapp/media/formatjson//liens_'+str(f)+'.json', "w") as text_file: #print(edges, file=text_file) #with open('C:/projetPtutTuto/ProjetPtut/environnementPtut/Ontoapp/media/formatjson//nodes_'+str(f)+'.json', "w") as text_file: #print(nodes, file=text_file) #Nodes,Egdes = nodes, edges #Renvoyer le contenu des variables return (nodes, edges)
__author__ = 'joshhanna' from owllib.ontology import Ontology # TODO: convert to actual tests ont = Ontology() print("loading bfo") ont.load(location="http://www.ifomis.org/bfo/owl") for cls in ont.classes: if cls.is_named(): print("cls:", cls.uri) for s, p, o in cls.triples: print(s, p, o) print("parents") for parent in cls.children: print(parent.uri) print("loading iao") ont.load( location= "https://information-artifact-ontology.googlecode.com/svn/releases/2011-08-04/merged/iao.owl" ) for cls in ont.classes: if cls.is_named(): print("cls:", cls.uri) for s, p, o in cls.triples: print(s, p, o)