コード例 #1
0
    def test_basic_entity_info(self):
        rdf_content = rdf_prefix + '''
:Entity a owl:Class ;
    rdfs:label "Entity" ;
    skos:definition """Everything that can be described, similar to owl:Thing.""" ;
    :common_properties :label, :title, :description ;
    .
        '''
        ontology = Ontology(rdf_content)
        self.assertEqual(len(ontology.all_classes()), 1)
        for entity in ontology.all_classes():
            self.assertIsInstance(entity, OntologyEntity)
            self.assertIsInstance(entity, OntologyClass)
        self.assertEqual(len(ontology.all_properties()), 0)
        for entity in ontology.all_properties():
            self.assertIsInstance(entity, OntologyEntity)
            self.assertIsInstance(entity, OntologyProperty)
        self.assertEqual(len(ontology.root_classes()), 1)
        for entity in ontology.root_classes():
            self.assertIsInstance(entity, OntologyClass)
            self.assertEqual(len(entity.super_classes()), 0)
コード例 #2
0
    def test_class_hierachy(self):
        rdf_content = rdf_prefix + '''
:Entity a owl:Class ; .
:Group a owl:Class ;
    rdfs:subClassOf :Entity ; .
:Actor a owl:Class ;
    owl:subClassOf :Group ; .
        '''
        ontology = Ontology(rdf_content)
        self.assertEqual(len(ontology.all_classes()), 3)
        entity = ontology.get_entity(DIG.Entity.toPython())
        self.assertIsNotNone(entity)
        self.assertSetEqual(ontology.root_classes(), {entity})
        group = ontology.get_entity(DIG.Group.toPython())
        self.assertIsNotNone(group)
        actor = ontology.get_entity(DIG.Actor.toPython())
        self.assertIsNotNone(actor)
        self.assertSetEqual(group.super_classes(), {entity})
        self.assertSetEqual(actor.super_classes(), {group})
        self.assertSetEqual(actor.super_classes_closure(), {entity, group})