def aggregate_context_data(self,graph_in_memory, contextId="", context_sent=""):
     from oke.oak.TaskContext import TaskContext
     currentContext=TaskContext(contextId)
     #currentContext.contextURI=contextId
     currentContext.isString=context_sent
     entity_info = self.get_task_context_entity(graph_in_memory, contextId)
     from oke.oak.TaskContext import ContextEntity
     
     entity=ContextEntity(entity_info[0][0])
     #entity.entityURI=entity_info[0][0]
     entity.anchorOf=entity_info[0][1]
     entity.beginIndex=entity_info[0][2]
     entity.endIndex=entity_info[0][3]
     entity.taIdentRef=entity_info[0][4]
     
     entity.referenceContext=contextId
     
     entity_labelled_types=self.get_entity_types(graph_in_memory, entity.taIdentRef, contextId)
     from oke.oak.TaskContext import EntityClass
     entityClasses=[]
     for entity_labelled_type in entity_labelled_types:
         entityClass=EntityClass(entity_labelled_type[1])
         entityClass.anchorOf=entity_labelled_type[0]
         #entityClass.uri=entity_labelled_type[1]
         entityClass.subClassOf=entity_labelled_type[2]
         entityClass.beginIndex=entity_labelled_type[3]
         entityClass.endIndex=entity_labelled_type[4]
         entityClass.referenceContext=entity_labelled_type[5]
         entityClass.taIdentRef=entity_labelled_type[6]
         entityClasses.append(entityClass)
     
     entity.isInstOfEntityClasses=entityClasses
     currentContext.entity=entity
     return currentContext        
    def test_ontology_alignment(self):
        from oke.oak.TaskContext import TaskContext
        from oke.oak.TaskContext import ContextEntity
        from oke.oak.TaskContext import EntityClass

        context_data = TaskContext(
            "http://www.ontologydesignpatterns.org/data/oke-challenge/task-2/sentence-1#char=0,150"
        )
        entity = ContextEntity(
            "http://www.ontologydesignpatterns.org/data/oke-challenge/task-2/sentence-1#char=0,12"
        )
        entity.taIdentRef = "http://dbpedia.org/resource/Brian_Banner"

        entityClass1 = EntityClass(
            "http://www.ontologydesignpatterns.org/data/oke-challenge/sentence-1#char=18,35"
        )
        entityClass1.anchorOf = "fictional villain"

        entityClass2 = EntityClass(
            "http://www.ontologydesignpatterns.org/data/oke-challenge/sentence-1#char=28,35"
        )
        entityClass2.anchorOf = "villain"

        entityClasses = set()
        entityClasses.add(entityClass1)
        entityClasses.add(entityClass2)

        entity.isInstOfEntityClasses = entityClasses
        context_data.entity = entity

        suggested_DUL_class_for_alignment = self.ontology_alignment(
            context_data)
        print("suggested alignment for \"fictional villain\":",
              suggested_DUL_class_for_alignment)
 def test_ontology_alignment(self):
     from oke.oak.TaskContext import TaskContext
     from oke.oak.TaskContext import ContextEntity
     from oke.oak.TaskContext import EntityClass
                     
     context_data = TaskContext("http://www.ontologydesignpatterns.org/data/oke-challenge/task-2/sentence-1#char=0,150")
     entity=ContextEntity("http://www.ontologydesignpatterns.org/data/oke-challenge/task-2/sentence-1#char=0,12")
     entity.taIdentRef="http://dbpedia.org/resource/Brian_Banner"
       
     entityClass1=EntityClass("http://www.ontologydesignpatterns.org/data/oke-challenge/sentence-1#char=18,35")
     entityClass1.anchorOf="fictional villain"
       
     entityClass2=EntityClass("http://www.ontologydesignpatterns.org/data/oke-challenge/sentence-1#char=28,35")
     entityClass2.anchorOf="villain"
       
     entityClasses=set()
     entityClasses.add(entityClass1)
     entityClasses.add(entityClass2)
     
     entity.isInstOfEntityClasses=entityClasses
     context_data.entity=entity
     
     suggested_DUL_class_for_alignment =self.ontology_alignment(context_data)
     print("suggested alignment for \"fictional villain\":",suggested_DUL_class_for_alignment)
Esempio n. 4
0
    def aggregate_context_data(self,
                               graph_in_memory,
                               contextId="",
                               context_sent=""):
        from oke.oak.TaskContext import TaskContext
        currentContext = TaskContext(contextId)
        #currentContext.contextURI=contextId
        currentContext.isString = context_sent
        entity_info = self.get_task_context_entity(graph_in_memory, contextId)
        from oke.oak.TaskContext import ContextEntity

        entity = ContextEntity(entity_info[0][0])
        #entity.entityURI=entity_info[0][0]
        entity.anchorOf = entity_info[0][1]
        entity.beginIndex = entity_info[0][2]
        entity.endIndex = entity_info[0][3]
        entity.taIdentRef = entity_info[0][4]

        entity.referenceContext = contextId

        entity_labelled_types = self.get_entity_types(graph_in_memory,
                                                      entity.taIdentRef,
                                                      contextId)
        from oke.oak.TaskContext import EntityClass
        entityClasses = []
        for entity_labelled_type in entity_labelled_types:
            entityClass = EntityClass(entity_labelled_type[1])
            entityClass.anchorOf = entity_labelled_type[0]
            #entityClass.uri=entity_labelled_type[1]
            entityClass.subClassOf = entity_labelled_type[2]
            entityClass.beginIndex = entity_labelled_type[3]
            entityClass.endIndex = entity_labelled_type[4]
            entityClass.referenceContext = entity_labelled_type[5]
            entityClass.taIdentRef = entity_labelled_type[6]
            entityClasses.append(entityClass)

        entity.isInstOfEntityClasses = entityClasses
        currentContext.entity = entity
        return currentContext