Beispiel #1
0
 def __init__(self, graph, subject):
     Annotation.__init__(self, graph, subject)
     try:
         self.__type = graph.objects(subject, DCTERMS.type).next().toPython()
     except StopIteration:
         self.__type = None
     try:
         self.__selectedText = graph.objects(subject, FISE.term('selected-text')).next().value
     except StopIteration:
         self.__selectedText = None
     try:
         self.__selectionContext = graph.objects(subject, FISE.term('selection-context')).next().value
     except StopIteration:
         self.__selectionContext = None
     try:
         self.__start = graph.objects(subject, FISE.term('start')).next().value
     except StopIteration:
         self.__start = None
     try:
         self.__end = graph.objects(subject, FISE.term('end')).next().value
     except StopIteration:
         self.__end = None
     try:
         self.__language = graph.objects(subject, DCTERMS.language).next().value
     except StopIteration:
         if self.__selectionContext:
             self.__language = graph.objects(subject, FISE.term('selection-context')).next().language
         else:
             self.__language = None
Beispiel #2
0
def parseEnhancement(graph, subject):
    types = graph.objects(subject, RDF.type)
    for type in types:
        if type == FISE.term("TextAnnotation"):
            return TextAnnotation(graph, subject)
        elif type == FISE.term("EntityAnnotation"):
            return EntityAnnotation(graph, subject, parseEntity(graph, subject))

    return None
Beispiel #3
0
 def __init__(self, graph, subject, entity):
     Annotation.__init__(self, graph, subject)
     self.__entityLabel = graph.objects(subject, FISE.term('entity-label')).next().value
     self.__entityReference = graph.objects(subject, FISE.term('entity-reference')).next().toPython()
     try:
         self.__site = graph.objects(subject, ENTITY_HUB.site).next().value
     except StopIteration:
         self.__site = None
     types = graph.objects(subject, FISE.term('entity-type'))
     self.__entityTypes = [t.toPython() for t in types]
     self.__entity = entity
Beispiel #4
0
def parseEntity(graph, subject):
    reference = graph.objects(subject, FISE.term('entity-reference')).next()
    if reference:
        triples = list(graph.triples((reference, None, None)))
        try:
            site = graph.objects(subject, ENTITY_HUB.site).next().value
        except StopIteration: # Some engines are not able to return site
            site = None

        return Entity(reference, site, triples)
    return None
Beispiel #5
0
 def __init__(self, graph, subject):
     Enhancement.__init__(self, graph, subject)
     self.__extractedFrom = graph.objects(subject, FISE.term("extracted-from")).next().toPython()
     self.__confidence = float(graph.objects(subject, FISE.term("confidence")).next().value)
Beispiel #6
0
def parseEnhancementStructure(strGraph, format):
    graph = Graph()
    graph.parse(data=strGraph, format=format)
    enhancements = {subject:parseEnhancement(graph, subject) for subject in graph.subjects(RDF.type, FISE.term('Enhancement'))}
    __processRelations(graph, enhancements)
    return EnhancerResult(graph, enhancements.values())