Ejemplo n.º 1
0
class TestParseOntologyClass(unittest.TestCase):

    """
    Used to test the loading and parsing of RDF graphs (owl files) as eltk ontologies
    """

    def setUp(self):
        self.gold=Ontology(identifier = URIRef(u'http://purl.org/linguistics/data/myonto/'))
        self.gold.parse(ELTK_HOME+"/examples/inputfiles/test_ontology.owl")


    def testEntityReference(self):
        #test simple reference: name and uri
        self.assertEqual(self.gold.MyClass1.name,'MyClass1')
        self.assertEqual(self.gold.MyClass1.uri,u'http://www.test.org/test_ontology.owl#MyClass1')

    def testEntityReference_nonascii(self):
        #test reference with non-ascii char's
        
        #class
        cu=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MyClass_unicoɖe')
        self.assertEqual(OWLClass,type(cu))
        self.assertEqual(u'http://www.test.org/test_ontology.owl#MyClass_unico%C9%96e',cu.uri)
        self.assertEqual(u'MyClass_unico%C9%96e',cu.name)

        #instance
        i=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MYINSTANCEɖ')
        
        #b/c uri isn't quoted in Meta, see note in Meta.py
        self.assertEqual(URIRef(u'http://www.test.org/test_ontology.owl#MYINSTANCEɖ'),i.uri)
        self.assertEqual(u'MYINSTANCEɖ',i.name)




    def testGetEntity_class(self):
        
        #test class as argument
        c=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MyClass1')
        self.assertEqual(OWLClass,type(c))
        self.assertEqual(u'http://www.test.org/test_ontology.owl#MyClass1',c.uri)
        self.assertEqual(u'MyClass1',c.name)



    def testGetEntity_objectproperty(self):
        
        #test obj property as argument
        op=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#myobjectproperty')
        self.assertEqual(OWLObjectProperty,type(op))
        self.assertEqual(u'http://www.test.org/test_ontology.owl#myobjectproperty',op.uri)
        self.assertEqual(u'myobjectproperty',op.name)

    def testGetEntity_dataproperty(self):
        
        #test data property as argument
        dp=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#mydataproperty')
        self.assertEqual(OWLDatatypeProperty,type(dp))
        self.assertEqual(u'http://www.test.org/test_ontology.owl#mydataproperty',dp.uri)
        self.assertEqual(u'mydataproperty',dp.name)


    def testGetEntity_individual(self):
        #test individidual as argument
        
        #test one type
        c1=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MyClass1')
        i1=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MYINSTANCE1')
        self.assertEqual(u'MYINSTANCE1',i1.name)
        self.assertEqual(URIRef(u'http://www.test.org/test_ontology.owl#MYINSTANCE1'),i1.uri)
        self.assertEqual([c1],type(i1)) 
        
        #test two types
        c2=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MyClass2')
        i2=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MYINSTANCE2')
        self.assertTrue((c1 and c2) in type(i2)) 

        #test three types
        c3=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MyClass3')
        i3=self.gold.getEntity(u'http://www.test.org/test_ontology.owl#MYINSTANCE3')
        self.assertTrue((c1 and c2 and c3) in type(i3)) 
Ejemplo n.º 2
0
class TestParseOntologyClass(unittest.TestCase):
    """
    Used to test the loading and parsing of RDF graphs (owl files) as eltk ontologies
    """
    def setUp(self):
        self.gold = Ontology(
            identifier=URIRef(u'http://purl.org/linguistics/data/myonto/'))
        self.gold.parse(ELTK_HOME + "/examples/inputfiles/test_ontology.owl")

    def testEntityReference(self):
        #test simple reference: name and uri
        self.assertEqual(self.gold.MyClass1.name, 'MyClass1')
        self.assertEqual(self.gold.MyClass1.uri,
                         u'http://www.test.org/test_ontology.owl#MyClass1')

    def testEntityReference_nonascii(self):
        #test reference with non-ascii char's

        #class
        cu = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MyClass_unicoɖe')
        self.assertEqual(OWLClass, type(cu))
        self.assertEqual(
            u'http://www.test.org/test_ontology.owl#MyClass_unico%C9%96e',
            cu.uri)
        self.assertEqual(u'MyClass_unico%C9%96e', cu.name)

        #instance
        i = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MYINSTANCEɖ')

        #b/c uri isn't quoted in Meta, see note in Meta.py
        self.assertEqual(
            URIRef(u'http://www.test.org/test_ontology.owl#MYINSTANCEɖ'),
            i.uri)
        self.assertEqual(u'MYINSTANCEɖ', i.name)

    def testGetEntity_class(self):

        #test class as argument
        c = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MyClass1')
        self.assertEqual(OWLClass, type(c))
        self.assertEqual(u'http://www.test.org/test_ontology.owl#MyClass1',
                         c.uri)
        self.assertEqual(u'MyClass1', c.name)

    def testGetEntity_objectproperty(self):

        #test obj property as argument
        op = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#myobjectproperty')
        self.assertEqual(OWLObjectProperty, type(op))
        self.assertEqual(
            u'http://www.test.org/test_ontology.owl#myobjectproperty', op.uri)
        self.assertEqual(u'myobjectproperty', op.name)

    def testGetEntity_dataproperty(self):

        #test data property as argument
        dp = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#mydataproperty')
        self.assertEqual(OWLDatatypeProperty, type(dp))
        self.assertEqual(
            u'http://www.test.org/test_ontology.owl#mydataproperty', dp.uri)
        self.assertEqual(u'mydataproperty', dp.name)

    def testGetEntity_individual(self):
        #test individidual as argument

        #test one type
        c1 = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MyClass1')
        i1 = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MYINSTANCE1')
        self.assertEqual(u'MYINSTANCE1', i1.name)
        self.assertEqual(
            URIRef(u'http://www.test.org/test_ontology.owl#MYINSTANCE1'),
            i1.uri)
        self.assertEqual([c1], type(i1))

        #test two types
        c2 = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MyClass2')
        i2 = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MYINSTANCE2')
        self.assertTrue((c1 and c2) in type(i2))

        #test three types
        c3 = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MyClass3')
        i3 = self.gold.getEntity(
            u'http://www.test.org/test_ontology.owl#MYINSTANCE3')
        self.assertTrue((c1 and c2 and c3) in type(i3))