def setUp(self) -> None: self.parse1 = MorphologicalParse("bayan+NOUN+A3SG+PNON+NOM") self.parse2 = MorphologicalParse("yaşa+VERB+POS^DB+ADJ+PRESPART") self.parse3 = MorphologicalParse("serbest+ADJ") self.parse4 = MorphologicalParse( "et+VERB^DB+VERB+PASS^DB+VERB+ABLE+NEG+AOR+A3SG") self.parse5 = MorphologicalParse( "sür+VERB^DB+VERB+CAUS^DB+VERB+PASS+POS^DB+NOUN+INF2+A3SG+P3SG+NOM" ) self.parse6 = MorphologicalParse( "değiş+VERB^DB+VERB+CAUS^DB+VERB+PASS+POS^DB+VERB+ABLE+AOR^DB+ADJ+ZERO" ) self.parse7 = MorphologicalParse( "iyi+ADJ^DB+VERB+BECOME^DB+VERB+CAUS^DB+VERB+PASS+POS^DB+VERB+ABLE^DB+NOUN+INF2+A3PL+P3PL+ABL" ) self.parse8 = MorphologicalParse("değil+ADJ^DB+VERB+ZERO+PAST+A3SG") self.parse9 = MorphologicalParse("hazır+ADJ^DB+VERB+ZERO+PAST+A3SG")
def setLayerValue(self, layerValue: str): self.items = [] if isinstance(layerValue, str): self.layerValue = layerValue if layerValue is not None: splitWords = self.layerValue.split(" ") for word in splitWords: self.items.append(MorphologicalParse(word)) elif isinstance(layerValue, MorphologicalParse): parse = layerValue self.layerValue = parse.getTransitionList() self.items.append(parse)
def setParse(self, parseString: MorphologicalParse): """ Sets the morphological parse layer of the word. PARAMETERS ---------- parseString : str The new morphological parse of the word in string form. """ if parseString is not None: self.__parse = MorphologicalParse(parseString) else: self.__parse = None
def __init__(self, fileName=None): """ Constructor which creates a list of sentences and a CounterHashMap of wordList. """ super().__init__() if fileName is not None: inputFile = open(fileName, "r", encoding="utf8") lines = inputFile.readlines() newSentence = Sentence() for line in lines: word = line[:line.index("\t")] parse = line[line.index("\t") + 1:] if len(word) > 0 and len(parse) > 0: newWord = DisambiguatedWord(word, MorphologicalParse(parse.strip())) if word == "<S>": newSentence = Sentence() elif word == "</S>": self.addSentence(newSentence) elif word == "<DOC>" or word == "</DOC>" or word == "<TITLE>" or word == "</TITLE>": pass else: newSentence.addWord(newWord) inputFile.close()
def __init__(self, word: str, layerType=None): """ Constructor for the AnnotatedWord class. Gets the word with its annotation layers as input and sets the corresponding layers. PARAMETERS ---------- word : str Input word with annotation layers """ self.__parse = None self.__metamorphicParse = None self.__semantic = None self.__namedEntityType = None self.__argument = None self.__frameElement = None self.__shallowParse = None self.__universalDependency = None if layerType is None: splitLayers = re.compile("[{}]").split(word) for layer in splitLayers: if len(layer) == 0: continue if "=" not in layer: self.name = layer continue layerType = layer[:layer.index("=")] layerValue = layer[layer.index("=") + 1:] if layerType == "turkish": self.name = layerValue elif layerType == "morphologicalAnalysis": self.__parse = MorphologicalParse(layerValue) elif layerType == "metaMorphemes": self.__metamorphicParse = MetamorphicParse(layerValue) elif layerType == "namedEntity": self.__namedEntityType = NamedEntityType.getNamedEntityType( layerValue) elif layerType == "propbank": self.__argument = Argument(layerValue) elif layerType == "framenet": self.__frameElement = FrameElement(layerValue) elif layerType == "shallowParse": self.__shallowParse = layerValue elif layerType == "semantics": self.__semantic = layerValue elif layerType == "universalDependency": values = layerValue.split("$") self.__universalDependency = UniversalDependencyRelation( int(values[0]), values[1]) elif isinstance(layerType, NamedEntityType): super().__init__(word) self.__namedEntityType = layerType self.__argument = Argument("NONE") elif isinstance(layerType, MorphologicalParse): super().__init__(word) self.__parse = layerType self.__namedEntityType = NamedEntityType.NONE self.__argument = Argument("NONE") elif isinstance(layerType, FsmParse): super().__init__(word) self.__parse = layerType self.__namedEntityType = NamedEntityType.NONE self.setMetamorphicParse(layerType.withList()) self.__argument = Argument("NONE")