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
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