예제 #1
0
 def tagInitializedSentence(self, initSen):
     wordTags = initSen.replace("“", "''").replace("”", "''").replace("\"", "''").split()
     sen = []
     for i in xrange(len(wordTags)):
         fwObject = FWObject.getFWObject(wordTags, i)
         word, tag = getWordTag(wordTags[i])
         node = self.findFiredNode(fwObject)
         if node.depth > 0:
             sen.append(word + "/" + node.conclusion)
         else:# Fired at root, return initialized tag
             sen.append(word + "/" + tag)
     return " ".join(sen)
 def tagRawVnSentence(self, DICT, rawLine):
     line = initializeVnSentence(DICT, rawLine)
     sen = []
     wordTags = line.split()
     for i in range(len(wordTags)):
         fwObject = FWObject.getFWObject(wordTags, i)
         word, tag = getWordTag(wordTags[i])
         node = self.findFiredNode(fwObject)
         if node.depth > 0:
             sen.append(word + "/" + node.conclusion)
         else:  # Fired at root, return initialized tag
             sen.append(word + "/" + tag)
     return " ".join(sen)
예제 #3
0
 def tagRawEnSentence(self, DICT, rawLine):
     line = initializeEnSentence(DICT, rawLine)
     sen = []
     wordTags = line.split()
     for i in xrange(len(wordTags)):
         fwObject = FWObject.getFWObject(wordTags, i)
         word, tag = getWordTag(wordTags[i])
         node = self.findFiredNode(fwObject)
         if node.depth > 0:
             sen.append(word + "/" + node.conclusion)
         else:# Fired at root, return initialized tag
             sen.append(word + "/" + tag)
     return " ".join(sen)
예제 #4
0
 def tagInitializedSentence(self, initSen):
     wordTags = initSen.replace("“",
                                "''").replace("”",
                                              "''").replace("\"",
                                                            "''").split()
     sen = []
     for i in range(len(wordTags)):
         fwObject = FWObject.getFWObject(wordTags, i)
         word, tag = getWordTag(wordTags[i])
         node = self.findFiredNode(fwObject)
         if node.depth > 0:
             sen.append(word + "/" + node.conclusion)
         else:  # Fired at root, return initialized tag
             sen.append(word + "/" + tag)
     return " ".join(sen)
예제 #5
0
    def tag(self, tokens):
        tokens = ' '.join(tokens)
        line = initializeSentence(self.DICT, tokens)
        sen = []
        wordTags = line.split()
        for i in xrange(len(wordTags)):
            fwObject = FWObject.getFWObject(wordTags, i)
            word, tag = getWordTag(wordTags[i])
            node = self.findFiredNode(fwObject)

            if node.depth > 0:
                sen.append((word, node.conclusion))
            else:# Fired at root, return initialized tag
                sen.append((word, tag))
        return sen
예제 #6
0
    def tagRawSentence(self, DICT, rawLine):
        # set DICT to "self"to use a preloaded dictionary
        if DICT == "self":
            DICT = self.DICT

        line = initializeSentence(DICT, rawLine)
        sen = []
        wordTags = line.split()
        for i in range(len(wordTags)):
            fwObject = FWObject.getFWObject(wordTags, i)
            word, tag = getWordTag(wordTags[i])
            node = self.findFiredNode(fwObject)
            if node.depth > 0:
                sen.append(word + "/" + node.conclusion)
            else:  # Fired at root, return initialized tag
                sen.append(word + "/" + tag)
        return " ".join(sen)
예제 #7
0
파일: SCRDRTree.py 프로젝트: MittagQI/nectm
    def constructSCRDRtreeFromRDRfile(self, rulesFilePath):

        self.root = Node(FWObject(False), "NN", None, None, None, [], 0)
        currentNode = self.root
        currentDepth = 0

        rulesFile = open(rulesFilePath, "r")
        lines = rulesFile.readlines()

        for i in range(1, len(lines)):
            line = lines[i]
            depth = 0
            for c in line:
                if c == '\t':
                    depth = depth + 1
                else:
                    break

            line = line.strip()
            if len(line) == 0:
                continue

            temp = line.find("cc")
            if temp == 0:
                continue

            condition = getCondition(line.split(" : ", 1)[0].strip())
            conclusion = getConcreteValue(line.split(" : ", 1)[1].strip())

            node = Node(condition, conclusion, None, None, None, [], depth)

            if depth > currentDepth:
                currentNode.exceptChild = node
            elif depth == currentDepth:
                currentNode.elseChild = node
            else:
                while currentNode.depth != depth:
                    currentNode = currentNode.father
                currentNode.elseChild = node

            node.father = currentNode
            currentNode = node
            currentDepth = depth
예제 #8
0
파일: SCRDRTree.py 프로젝트: MittagQI/nectm
def getCondition(strCondition):
    condition = FWObject(False)
    for rule in strCondition.split(" and "):
        rule = rule.strip()
        key = rule[rule.find(".") + 1:rule.find(" ")]
        value = getConcreteValue(rule)

        if key == "prevWord2":
            condition.context[0] = value
        elif key == "prevTag2":
            condition.context[1] = value
        elif key == "prevWord1":
            condition.context[2] = value
        elif key == "prevTag1":
            condition.context[3] = value
        elif key == "word":
            condition.context[4] = value
        elif key == "tag":
            condition.context[5] = value
        elif key == "nextWord1":
            condition.context[6] = value
        elif key == "nextTag1":
            condition.context[7] = value
        elif key == "nextWord2":
            condition.context[8] = value
        elif key == "nextTag2":
            condition.context[9] = value
        elif key == "suffixL2":
            condition.context[10] = value
        elif key == "suffixL3":
            condition.context[11] = value
        elif key == "suffixL4":
            condition.context[12] = value

    return condition