Ejemplo n.º 1
0
class TestCreateOntologyClass(unittest.TestCase):
    
    """
    Used to test the creation of ontologies as objects in the Python OOP environment
    """


    def setUp(self):

        #create onto URI
        self.uri=URIRef(u'http://purl.org/linguistics/test_onto.owl')
        #create onto
        self.myonto=Ontology(self.uri)
        
    def testAddClass(self):
        
       
        #create and add a class
        Lexeme = OWLClass.new(u'http://purl.org/linguistics/gold/Lexeme')
        self.myonto.addEntity(Lexeme)
        
        #ontology has member Lexeme
        self.assertTrue(self.myonto.Lexeme)
        
    def testAddObjectProperty(self):
        
        #create and add an object property
        hasEntry = OWLObjectProperty.new(u'http://purl.org/linguistics/gold/hasEntry')
        self.myonto.addEntity(hasEntry)

        #ontology has member hasEntry
        self.assertTrue(self.myonto.hasEntry) 

    def testAddIndividual(self):

        MyClass = OWLClass.new(u'http://purl.org/linguistics/test_onto/MyClass')
        self.myonto.addEntity(MyClass)

        #print MyClass('MYINDIV',[])
        self.myonto.addEntity(MyClass('MYINDIV',[]))

        #ontology has member MYINDIV
        self.assertTrue(self.myonto.MYINDIV)

    def testAddTriple(self):

         
        MyClass = OWLClass.new(u'http://purl.org/linguistics/test_onto/MyClass')
        myobjprop = OWLObjectProperty.new(u'http://purl.org/linguistics/test_onto/myProp')

        

        #create two individuals
        i1 = MyClass('http://www.test.org/MYINDIV_1',[]) 
        i2 = MyClass('http://www.test.org/MYINDIV_2',[]) 

        self.myonto.add((i1.getURI(),myobjprop.getURI(),i2.getURI()))
        
        answer = []
        
        #iterate over triples
        for x in self.myonto.triples((i1.getURI(),myobjprop.getURI(),i2.getURI())):
            answer.append(x)
        

        #test that triple is really there
        self.assertTrue((i1.getURI(),myobjprop.getURI(),i2.getURI()) in answer)
Ejemplo n.º 2
0
class TestCreateOntologyClass(unittest.TestCase):
    """
    Used to test the creation of ontologies as objects in the Python OOP environment
    """
    def setUp(self):

        #create onto URI
        self.uri = URIRef(u'http://purl.org/linguistics/test_onto.owl')
        #create onto
        self.myonto = Ontology(self.uri)

    def testAddClass(self):

        #create and add a class
        Lexeme = OWLClass.new(u'http://purl.org/linguistics/gold/Lexeme')
        self.myonto.addEntity(Lexeme)

        #ontology has member Lexeme
        self.assertTrue(self.myonto.Lexeme)

    def testAddObjectProperty(self):

        #create and add an object property
        hasEntry = OWLObjectProperty.new(
            u'http://purl.org/linguistics/gold/hasEntry')
        self.myonto.addEntity(hasEntry)

        #ontology has member hasEntry
        self.assertTrue(self.myonto.hasEntry)

    def testAddIndividual(self):

        MyClass = OWLClass.new(
            u'http://purl.org/linguistics/test_onto/MyClass')
        self.myonto.addEntity(MyClass)

        #print MyClass('MYINDIV',[])
        self.myonto.addEntity(MyClass('MYINDIV', []))

        #ontology has member MYINDIV
        self.assertTrue(self.myonto.MYINDIV)

    def testAddTriple(self):

        MyClass = OWLClass.new(
            u'http://purl.org/linguistics/test_onto/MyClass')
        myobjprop = OWLObjectProperty.new(
            u'http://purl.org/linguistics/test_onto/myProp')

        #create two individuals
        i1 = MyClass('http://www.test.org/MYINDIV_1', [])
        i2 = MyClass('http://www.test.org/MYINDIV_2', [])

        self.myonto.add((i1.getURI(), myobjprop.getURI(), i2.getURI()))

        answer = []

        #iterate over triples
        for x in self.myonto.triples(
            (i1.getURI(), myobjprop.getURI(), i2.getURI())):
            answer.append(x)

        #test that triple is really there
        self.assertTrue((i1.getURI(), myobjprop.getURI(),
                         i2.getURI()) in answer)