Demo entry 6624200



Submitted by anonymous on Jun 14, 2017 at 09:49
Language: Python 3. Code size: 2.3 kB.

class Term:
    def __init__(self, term):
        """Creates a Term object from the ixa-pipes .naf file after introducing the root <term> 

            id          --- the id of the <term> in the .naf file.
            type        --- the type of the <term> in the .naf file.
            lemma       --- the lemma of the <term> in the .naf file.
            pos         --- the pos of the <term> in the .naf file.
            morphofeat  --- the morphofeat of the <term> in the .naf file.
            head        --- the head of the <term> in the .naf file.
            case        --- the case of the <term> in the .naf file.
            span        --- the list of the words of the text that the <term> is referring to.
            word        --- the string containing the words in span.
            ent         --- the Entidad object the Term object is referring or co-referring to.
                            It must be assigned after the Entidad and Coref objects are created 
                            via the method assignEntidad or preferably with the public method 
                            assignEntities in the Terms object. It is initialized as None.
        """ = term.get('id')
        self.type, self.lemma, self.pos, self.morphofeat, self.head, = [None] * 6
        if 'type' in term.attrib.keys():
            self.type = term.get('type')
        if 'lemma' in term.attrib.keys():
            self.lemma = term.get('lemma')
        if 'pos' in term.attrib.keys():
            self.pos = term.get('pos')
        if 'morphofeat' in term.attrib.keys():
            self.morphofeat = term.get('morphofeat')
        if 'head' in term.attrib.keys():
            self.head = term.get('head')
        if 'case' in term.attrib.keys():
   = term.get('case')
        self.span = []
        for wd in term[0]:
        root = term.getparent().getparent()
        text = root[getIndex(root, 'text')]
        self.sent = text[int(self.span[0][1:]) - 1].get("sent")
        self.para = text[int(self.span[0][1:]) - 1].get("para")
        self.word = ' '.join([text[int(wd[1:]) - 1].text for wd in self.span])
        self.ent = None

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).