Esempio n. 1
0
    def loadFrameFe(self, feNode):
        """
        """
        
        goodNodes = getNoneTextChildNodes(feNode)

        fe = {}
        fe = loadXMLAttributes(fe, feNode.attributes)
        fe['semtypes'] = {}

        for gn in goodNodes:
            if gn.nodeName == 'definition':
                if not fe.has_key('definition'):
                    try:
                        fe['definition'] = gn.childNodes[0].nodeValue
                    except:
                        fe['definition'] = None
                else:
                    print >> sys.stderr, 'Error , fe already have a definition:', fe['definition']
                    return None
            elif gn.nodeName == 'semTypes':
                goodSemTypeNodes = getNoneTextChildNodes(gn)

                for gsn in goodSemTypeNodes:
                    semType = {}
                    loadXMLAttributes(semType, gsn.attributes)
                    fe['semtypes'][semType['ID']] = semType
            else:
                print >> sys.stderr, 'In loadFrameFe, found this node:', gn.nodeName
                return None

        return fe
Esempio n. 2
0
    def loadXML(self, fileName):
        """
        """

        doc = xml.dom.minidom.parse(fileName)

        relationTypeNodes = getNoneTextChildNodes(
            doc.childNodes[1])  #the actual frame-relation-type nodes

        for rtn in relationTypeNodes:
            rt = {}  #dictionary for frame-relation-type
            loadXMLAttributes(rt, rtn.attributes)
            relationNodes = getNoneTextChildNodes(
                rtn)  #the actual frame-relationS nodes
            if len(relationNodes) != 1:
                print >> sys.stderr, 'Got more than one frame-relations node in type:', rt[
                    'name']
                return False
            singleRelationNodes = getNoneTextChildNodes(
                relationNodes[0])  # the actual frame-relation nodes

            singleRelations = {}
            i = 0
            for srn in singleRelationNodes:
                tmp = self.loadSingleRelation(srn)
                if tmp == None:
                    print >> sys.stderr, 'Unable to load relation No.' + str(
                        i), 'for type', rt['name']
                    return False
                singleRelations[tmp['ID']] = tmp

            rt['frame-relations'] = singleRelations
            self['relation-types'][rt['ID']] = rt

        return True
Esempio n. 3
0
    def loadFrameFe(self, feNode):
        """
        """

        goodNodes = getNoneTextChildNodes(feNode)

        fe = {}
        fe = loadXMLAttributes(fe, feNode.attributes)
        fe['semtypes'] = {}

        for gn in goodNodes:
            if gn.nodeName == 'definition':
                if not fe.has_key('definition'):
                    try:
                        fe['definition'] = gn.childNodes[0].nodeValue
                    except:
                        fe['definition'] = None
                else:
                    print >> sys.stderr, 'Error , fe already have a definition:', fe[
                        'definition']
                    return None
            elif gn.nodeName == 'semTypes':
                goodSemTypeNodes = getNoneTextChildNodes(gn)

                for gsn in goodSemTypeNodes:
                    semType = {}
                    loadXMLAttributes(semType, gsn.attributes)
                    fe['semtypes'][semType['ID']] = semType
            else:
                print >> sys.stderr, 'In loadFrameFe, found this node:', gn.nodeName
                return None

        return fe
Esempio n. 4
0
    def loadXML(self, fileName):
        """
        """

        doc = xml.dom.minidom.parse(fileName)

        relationTypeNodes = getNoneTextChildNodes(doc.childNodes[1]) #the actual frame-relation-type nodes

        for rtn in relationTypeNodes:
            rt = {} #dictionary for frame-relation-type
            loadXMLAttributes(rt, rtn.attributes)
            relationNodes = getNoneTextChildNodes(rtn) #the actual frame-relationS nodes
            if len(relationNodes) != 1:
                print >> sys.stderr, 'Got more than one frame-relations node in type:', rt['name']
                return False
            singleRelationNodes = getNoneTextChildNodes(relationNodes[0]) # the actual frame-relation nodes

            singleRelations = {}
            i = 0
            for srn in singleRelationNodes:
                tmp = self.loadSingleRelation(srn)
                if tmp == None:
                    print >> sys.stderr, 'Unable to load relation No.' + str(i), 'for type', rt['name']
                    return False
                singleRelations[tmp['ID']] = tmp

            rt['frame-relations'] = singleRelations
            self['relation-types'][rt['ID']] = rt

        return True
Esempio n. 5
0
    def loadFrameLexicalUnit(self, lexunitNode):
        """
        """

        lexunit = {}

        loadXMLAttributes(lexunit, lexunitNode.attributes)

        goodNodes = getNoneTextChildNodes(lexunitNode)

        for gn in goodNodes:
            if gn.nodeName == 'definition':
                try:
                    lexunit['definition'] = gn.childNodes[0].nodeValue
                except:
                    lexunit['definition'] = None
            elif gn.nodeName == 'annotation':
                annoNodes = getNoneTextChildNodes(gn)
                anno = {}
                for an in annoNodes:
                    try:
                        anno[str(an.nodeName)] = an.childNodes[0].nodeValue
                        try:
                            n = int(anno[str(an.nodeName)])
                            anno[str(an.nodeName)] = n
                        except:
                            pass
                    except:
                        anno[str(an.nodeName)] = None
                        print >> sys.stderr, 'Warning!! unable to retrieve', an.nodeName, 'for annotation'
                lexunit['annotation'] = anno
            elif gn.nodeName == 'lexemes':
                goodSemTypeNodes = getNoneTextChildNodes(gn)
                lexemes = {}
                for gsn in goodSemTypeNodes:
                    lexeme = {}
                    loadXMLAttributes(lexeme, gsn.attributes)
                    # store the actual word
                    lexeme['lexeme'] = gsn.childNodes[0].nodeValue
                    lexemes[lexeme['ID']] = lexeme
                lexunit['lexeme'] = lexemes
            elif gn.nodeName == 'semTypes':
                goodSemTypeNodes = getNoneTextChildNodes(gn)
                semTypes = {}
                for gsn in goodSemTypeNodes:
                    semType = {}
                    loadXMLAttributes(semType, gsn.attributes)
                    semTypes[semType['ID']] = semType
                lexunit['semtypes'] = semTypes
            else:
                print >> sys.stderr, 'Error, encounted the node:', gn.nodeName, 'in', lexunitNode.nodeName, 'lexunit'
                return None
        return lexunit
Esempio n. 6
0
    def loadFrameLexicalUnit(self, lexunitNode):
        """
        """

        lexunit = {}

        loadXMLAttributes(lexunit, lexunitNode.attributes)

        goodNodes = getNoneTextChildNodes(lexunitNode)

        for gn in goodNodes:
            if gn.nodeName == 'definition':
                try:
                    lexunit['definition'] = gn.childNodes[0].nodeValue
                except:
                    lexunit['definition'] = None
            elif gn.nodeName == 'annotation':
                annoNodes = getNoneTextChildNodes(gn)
                anno = {}
                for an in annoNodes:
                    try:
                        anno[str(an.nodeName)] = an.childNodes[0].nodeValue
                        try:
                            n = int(anno[str(an.nodeName)])
                            anno[str(an.nodeName)] = n
                        except:
                            pass
                    except:
                        anno[str(an.nodeName)] = None
                        print >> sys.stderr, 'Warning!! unable to retrieve', an.nodeName, 'for annotation'
                lexunit['annotation'] = anno
            elif gn.nodeName == 'lexemes':
                goodSemTypeNodes = getNoneTextChildNodes(gn)
                lexemes = {}
                for gsn in goodSemTypeNodes:
                    lexeme = {}
                    loadXMLAttributes(lexeme, gsn.attributes)
                    # store the actual word
                    lexeme['lexeme'] = gsn.childNodes[0].nodeValue
                    lexemes[lexeme['ID']] = lexeme
                lexunit['lexeme'] = lexemes
            elif gn.nodeName == 'semTypes':
                goodSemTypeNodes = getNoneTextChildNodes(gn)
                semTypes = {}
                for gsn in goodSemTypeNodes:
                    semType = {}
                    loadXMLAttributes(semType, gsn.attributes)
                    semTypes[semType['ID']] = semType
                lexunit['semtypes'] = semTypes
            else:
                print >> sys.stderr, 'Error, encounted the node:', gn.nodeName, 'in', lexunitNode.nodeName, 'lexunit'
                return None
        return lexunit
Esempio n. 7
0
    def loadXMLNode(self, frameNode):
        """
        """

        loadXMLAttributes(self, frameNode.attributes)
        goodNodes = getNoneTextChildNodes(frameNode)

        for node in goodNodes:
            if node.nodeName == 'definition':
                if not self.loadFrameDefinition(node):
                    print >> sys.stderr, 'Unable to read definition node for frame:', self[
                        'ID']
            elif node.nodeName == 'fes':
                if not self.loadFrameFes(node):
                    print >> sys.stderr, 'Unable to read a fes node for frame:', self[
                        'ID']
            elif node.nodeName == 'lexunits':
                if not self.loadFrameLexunits(node):
                    print >> sys.stderr, 'Unable to read a lexunits node for frame:', self[
                        'ID']
            elif node.nodeName == 'semTypes':
                if not self.loadFrameSemtypes(node):
                    print >> sys.stderr, 'Unable to read a semtypes node for frame:', self[
                        'ID']
            else:
                print >> sys.stderr, 'Have no idea how to deal with node type:', node.nodeName
                return False
        return True
Esempio n. 8
0
    def loadSingleRelation(self, relationNode):
        """
        """

        frRelation = {}

        loadXMLAttributes(frRelation, relationNode.attributes)

        feNodes = getNoneTextChildNodes(relationNode)
        for fn in feNodes:
            tmp = {}
            loadXMLAttributes(tmp, fn.attributes)
            frRelation[tmp['ID']] = tmp

        return frRelation
Esempio n. 9
0
    def loadFrameSemtypes(self, node):
        """
        """
                    
        goodSemTypeNodes = getNoneTextChildNodes(node)

        semTypes = {}
        for gsn in goodSemTypeNodes:
            semType = {}
            loadXMLAttributes(semType, gsn.attributes)
            semTypes[semType['ID']] = semType

        self['semtypes'] = semTypes

        return True
Esempio n. 10
0
    def loadSingleRelation(self, relationNode):
        """
        """

        frRelation = {}

        loadXMLAttributes(frRelation, relationNode.attributes)

        feNodes = getNoneTextChildNodes(relationNode)
        for fn in feNodes:
            tmp = {}
            loadXMLAttributes(tmp, fn.attributes)
            frRelation[tmp['ID']] = tmp

        return frRelation
Esempio n. 11
0
    def loadFrameSemtypes(self, node):
        """
        """

        goodSemTypeNodes = getNoneTextChildNodes(node)

        semTypes = {}
        for gsn in goodSemTypeNodes:
            semType = {}
            loadXMLAttributes(semType, gsn.attributes)
            semTypes[semType['ID']] = semType

        self['semtypes'] = semTypes

        return True
Esempio n. 12
0
    def loadFrameFes(self, node):
        """
        """
        
        feNodes = getNoneTextChildNodes(node)

        fes = {}

        for feNode in feNodes:
            fe = self.loadFrameFe(feNode)

            if fe == None:
                print >> sys.stderr, 'Got a bad fe'
                return False

            fes[fe['ID']] = fe

        return True
Esempio n. 13
0
    def loadFrameLexunits(self, node):
        """
        """
        
        goodNodes = getNoneTextChildNodes(node)

        i = 0
        for gn in goodNodes:
            lu = self.loadFrameLexicalUnit(gn)

            if lu == None:
                print >> sys.stderr, 'The lu No.' + str(i), 'is bad'
                return False
            i += 1

            self['lexunits'][lu['ID']] = lu

        return True
Esempio n. 14
0
    def loadFrameFes(self, node):
        """
        """

        feNodes = getNoneTextChildNodes(node)

        fes = {}

        for feNode in feNodes:
            fe = self.loadFrameFe(feNode)

            if fe == None:
                print >> sys.stderr, 'Got a bad fe'
                return False

            fes[fe['ID']] = fe

        return True
Esempio n. 15
0
    def loadFrameLexunits(self, node):
        """
        """

        goodNodes = getNoneTextChildNodes(node)

        i = 0
        for gn in goodNodes:
            lu = self.loadFrameLexicalUnit(gn)

            if lu == None:
                print >> sys.stderr, 'The lu No.' + str(i), 'is bad'
                return False
            i += 1

            self['lexunits'][lu['ID']] = lu

        return True
Esempio n. 16
0
    def loadXMLNode(self, frameNode):
        """
        """
        
        loadXMLAttributes(self, frameNode.attributes)
        goodNodes = getNoneTextChildNodes(frameNode)

        for node in goodNodes:
            if node.nodeName == 'definition':
                if not self.loadFrameDefinition(node):
                    print >> sys.stderr, 'Unable to read definition node for frame:', self['ID']
            elif node.nodeName == 'fes':
                if not self.loadFrameFes(node):
                    print >> sys.stderr, 'Unable to read a fes node for frame:', self['ID']
            elif node.nodeName == 'lexunits':
                if not self.loadFrameLexunits(node):
                    print >> sys.stderr, 'Unable to read a lexunits node for frame:', self['ID']
            elif node.nodeName == 'semTypes':
                if not self.loadFrameSemtypes(node):
                    print >> sys.stderr, 'Unable to read a semtypes node for frame:', self['ID']
            else:
                print >> sys.stderr, 'Have no idea how to deal with node type:', node.nodeName
                return False
        return True