Beispiel #1
0
        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)
Beispiel #2
0
	def _load_directs(self):
		"""
		loads all of the direct imports, creating ontologies for each of them
		:return:
		"""
		uris = [o for o in self.graph.objects(self.uri, OWL.imports)]

		entities = set()

		for uri in uris:
			ont = Ontology()
			ont.load(location=uri)
			entities.add(ont)

		return entities
Beispiel #3
0
    def setUpClass(cls):
        cls.entityWithoutOntology = Entity()
        ontology = Ontology()
        print("loading test ontology")
        ontology.load(location="http://130.88.198.11/co-ode-files/ontologies/pizza.owl")

        # Get a valid class to test against
        iceCreamClass = ontology.getEntityFromURI('http://www.co-ode.org/ontologies/pizza/pizza.owl#IceCream')
        print('Found '+ iceCreamClass.uri.__str__())
        cls.validClass = iceCreamClass
        
        # Get a valid Individual to test against
        # TODO: cannot get an individual via uri?
        # americaIndividual = ontology.getEntityFromURI('http://www.co-ode.org/ontologies/pizza/pizza.owl#America')
        # print('Found '+ americaIndividual.uri.__str__())
        # cls.validIndiv = americaIndividual
                
        # Get a valid Property to test against
        hasBase = ontology.getEntityFromURI('http://www.co-ode.org/ontologies/pizza/pizza.owl#hasBase')
        print('Found '+ hasBase.uri.__str__())
        cls.validProperty = hasBase
Beispiel #4
0
__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)
Beispiel #5
0
import rdflib
from rdflib import *
from rdflib import Graph
from owllib.ontology import Ontology
from rdflib import URIRef
import os

# Une méthode pour vider la mémoire car en python il y a toujours des soucis avec la mem , si elle vous pose problème vous l'enlevez tout simplement 
def clearall():
    all = [var for var in globals() if var[0] != "_"]
    for var in all:
        del globals()[var]
repertoire = 'C:/projetPtutTuto/ProjetPtut/environnementPtut/Ontoapp/media/'
file=os.listdir(repertoire)
ont = Ontology()
for i in range(0,len(file)):
ont.load(location=repertoire+file[i])
#ont.load(location=r'G:\PtutOnto\aeo.owl')
# ont.load(location=r'G:\PtutOnto\cmt.owl')
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:"):
Beispiel #6
0
indiv = self.convert(indiv)
type_uris = set(self.graph.objects(indiv.uri, RDF.type))
types = [cls for cls in self.classes if cls.uri in type_uris]

parent_uris = set(self.graph.objects(prop.uri, RDFS.subPropertyOf))
children_uris = set(self.graph.objects(RDFS.subPropertyOf, prop.uri))
parents = [aprop for aprop in self.properties if aprop.uri in parent_uris]
children = [aprop for aprop in self.properties if aprop.uri in children_uris]






MyOntology =Ontology()
MyOntology.load(source='/Onto/RevealMeRDF.owl')
Reveal = RDFOntology(source='/Onto/RevealMeRDF.owl')
c = list(Reveal.classes)[30]
print(prettyuri(c))
base,symbol = os.path.dirname(c.replace('#', '/')), os.path.basename(c.replace('#', '/'))
print(base, symbol)
base_prefix = Reveal.find_namespace_prefix(base)
print(base_prefix)
print(Reveal.namespace_dict)





Beispiel #7
0
# coding=utf-8

from rdflib import RDF, RDFS, OWL
from rdflib.term import URIRef, Literal

from owllib.ontology import Ontology
from owllib.entities import Class

ont = Ontology()
ont.load(location='ont/syntax.n3')
uri = URIRef('123')
label = Literal('测试', lang='zh-hans')
# cls = Class()
# cls.triples.add((uri, RDF.type, OWL.Class))
# cls.triples.add((uri, RDFS.label, label))
# ont.classes.add(cls)
# ont.sync_entity_to_graph(cls)
ont.classes.add(Class(uri, None, {label}))
ont.sync_to_graph()
ont.sync_from_graph()

for cls in ont.classes:
    if cls.is_named:
        print(cls.labels)
        for s, p, o in cls.triples:
            print(s, p, o)

ont.graph.serialize('ont/test.n3', format='n3')
Beispiel #8
0
__author__ = 'joshhanna'

from owllib.ontology import Ontology
from rdflib import URIRef

#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)

print("loading dron")
Beispiel #9
0
from owllib.ontology import Ontology
from rdflib import URIRef

import re

ont = Ontology()
ont.load(source="final.rdf")


mentions = {}
global mentions

def get_name(url):
  return url.split("#")[-1]


def create_namespace():
  l = {}
  f = open("final.rdf").read()
  n = re.findall("<[^/\!\?].* ", f)
  for i in n:
    s = i[1:].strip()
    namespace, property = s.split(":")
    l[property] = namespace
  return l


def get_types(triple):
    if get_name(triple[1]) == "type" and get_name(triple[2]) != "Class":
        return get_name(triple[0])