def test_Accuracy(self): correct = 0 total = 0 lesk = Lesk(self.wordNet, self.fsm) treeBank1 = TreeBankDrawable("../../new-trees") treeBank2 = TreeBankDrawable("../../old-trees") for i in range(treeBank1.size()): parseTree1 = treeBank1.get(i) parseTree2 = treeBank2.get(i) lesk.autoSemantic(parseTree1) nodeDrawableCollector1 = NodeDrawableCollector( parseTree1.getRoot(), IsTurkishLeafNode()) leafList1 = nodeDrawableCollector1.collect() nodeDrawableCollector2 = NodeDrawableCollector( parseTree2.getRoot(), IsTurkishLeafNode()) leafList2 = nodeDrawableCollector2.collect() for j in range(len(leafList1)): total = total + 1 parseNode1 = leafList1[j] parseNode2 = leafList2[j] if parseNode1.getLayerData( ViewLayerType.SEMANTICS ) is not None and parseNode1.getLayerData( ViewLayerType.SEMANTICS) == parseNode2.getLayerData( ViewLayerType.SEMANTICS): correct = correct + 1 self.assertEqual(475, total) self.assertEqual(247, correct)
def autoLabelSingleSemantics(self, parseTree: ParseTreeDrawable) -> bool: random.seed(1) nodeDrawableCollector = NodeDrawableCollector(parseTree.getRoot(), IsTurkishLeafNode()) leafList = nodeDrawableCollector.collect() done = False for i in range(len(leafList)): synSets = self.getCandidateSynSets(self.__turkishWordNet, self.__fsm, leafList, i) maxIntersection = -1 for j in range(len(synSets)): synSet = synSets[j] intersectionCount = self.intersection(synSet, leafList) if intersectionCount > maxIntersection: maxIntersection = intersectionCount maxSynSets = [] for j in range(len(synSets)): synSet = synSets[j] if self.intersection(synSet, leafList) == maxIntersection: maxSynSets.append(synSet) if len(maxSynSets) > 0: leafList[i].getLayerInfo().setLayerData( ViewLayerType.SEMANTICS, maxSynSets[randrange(len(maxSynSets))].getId()) done = True return done
def autoLabelSingleSemantics(self, parseTree: ParseTreeDrawable) -> bool: random.seed(1) nodeDrawableCollector = NodeDrawableCollector(parseTree.getRoot(), IsTurkishLeafNode()) leafList = nodeDrawableCollector.collect() for i in range(len(leafList)): synSets = self.getCandidateSynSets(self.__turkishWordNet, self.__fsm, leafList, i) if len(synSets) > 0: leafList[i].getLayerInfo().setLayerData( ViewLayerType.SEMANTICS, synSets[randrange(len(synSets))].getId()) return True
def generateAnnotatedSentence(self, language: str = None) -> AnnotatedSentence: sentence = AnnotatedSentence() if language is None: nodeDrawableCollector = NodeDrawableCollector( self.root, IsTurkishLeafNode()) leafList = nodeDrawableCollector.collect() for parseNode in leafList: if isinstance(parseNode, ParseNodeDrawable): layers = parseNode.getLayerInfo() for i in range(layers.getNumberOfWords()): sentence.addWord(layers.toAnnotatedWord(i)) else: nodeDrawableCollector = NodeDrawableCollector( self.root, IsEnglishLeafNode()) leafList = nodeDrawableCollector.collect() for parseNode in leafList: if isinstance(parseNode, ParseNodeDrawable): newWord = AnnotatedWord( "{" + language + "=" + parseNode.getData().getName() + "}{posTag=" + parseNode.getParent().getData().getName() + "}") sentence.addWord(newWord) return sentence
def autoLabelSingleSemantics(self, parseTree: ParseTreeDrawable) -> bool: nodeDrawableCollector = NodeDrawableCollector(parseTree.getRoot(), IsTurkishLeafNode()) leafList = nodeDrawableCollector.collect() for i in range(len(leafList)): synSets = self.getCandidateSynSets(self.__turkishWordNet, self.__fsm, leafList, i) if len(synSets) > 0: best = self.mostFrequent( synSets, leafList[i].getLayerInfo().getMorphologicalParseAt( 0).getWord().getName()) if best is not None: leafList[i].getLayerInfo().setLayerData( ViewLayerType.SEMANTICS, best.getId()) return True
def autoNER(self, parseTree: ParseTreeDrawable): self.autoDetectPerson(parseTree) self.autoDetectLocation(parseTree) self.autoDetectOrganization(parseTree) self.autoDetectMoney(parseTree) self.autoDetectTime(parseTree) nodeDrawableCollector = NodeDrawableCollector( parseTree.getRoot(), IsTransferable(self.secondLanguage)) leafList = nodeDrawableCollector.collect() for parseNode in leafList: if isinstance(parseNode, ParseNodeDrawable) and not parseNode.layerExists( ViewLayerType.NER): parseNode.getLayerInfo().setLayerData(ViewLayerType.NER, "NONE") parseTree.save()
def autoArgument(self, parseTree: ParseTreeDrawable, frameset: Frameset): nodeDrawableCollector = NodeDrawableCollector( parseTree.getRoot(), IsTransferable(self.secondLanguage)) leafList = nodeDrawableCollector.collect() for parseNode in leafList: if isinstance(parseNode, ParseNodeDrawable) and parseNode.getLayerData( ViewLayerType.PROPBANK) is None: for argumentType in ArgumentType: if frameset.containsArgument( argumentType) and self.autoDetectArgument( parseNode, argumentType): parseNode.getLayerInfo().setLayerData( ViewLayerType.PROPBANK, ArgumentType.getPropbankType(argumentType)) if Word.isPunctuationSymbol( parseNode.getLayerData(self.secondLanguage)): parseNode.getLayerInfo().setLayerData( ViewLayerType.PROPBANK, "NONE") parseTree.save()
def extractNodesWithPredicateVerbs(self, wordNet: WordNet) -> list: nodeDrawableCollector = NodeDrawableCollector( self.root, IsPredicateVerbNode(wordNet)) return nodeDrawableCollector.collect()