Ejemplo n.º 1
0
    def constructIdiomLiterals(self,
                               fsm: FsmMorphologicalAnalyzer,
                               morphologicalParse1: MorphologicalParse,
                               metaParse1: MetamorphicParse,
                               morphologicalParse2: MorphologicalParse,
                               metaParse2: MetamorphicParse,
                               morphologicalParse3: MorphologicalParse = None,
                               metaParse3: MetamorphicParse = None) -> list:
        """
        Returns a list of literals using 3 possible words gathered with the specified morphological parses and
        metamorphic parses.

        PARAMETERS
        ----------
        morphologicalParse1 : MorphologicalParse
            morphological parse to get possible words
        morphologicalParse2 : MorphologicalParse
            morphological parse to get possible words
        morphologicalParse3 : MorphologicalParse
            morphological parse to get possible words
        metaParse1 : MetamorphicParse
            metamorphic parse to get possible words
        metaParse2 : MetamorphicParse
            metamorphic parse to get possible words
        metaParse3 : MetamorphicParse
            metamorphic parse to get possible words
        fsm : FsmMorphologicalAnalyzer
            finite state machine morphological analyzer to be used at getting possible words

        RETURNS
        -------
        list
            A list of literals
        """
        result = []
        possibleWords1 = fsm.getPossibleWords(morphologicalParse1, metaParse1)
        possibleWords2 = fsm.getPossibleWords(morphologicalParse2, metaParse2)
        if morphologicalParse3 is not None and metaParse3 is not None:
            possibleWords3 = fsm.getPossibleWords(morphologicalParse3,
                                                  metaParse3)
            for possibleWord1 in possibleWords1:
                for possibleWord2 in possibleWords2:
                    for possibleWord3 in possibleWords3:
                        result.extend(
                            self.getLiteralsWithName(possibleWord1 + " " +
                                                     possibleWord2 + " " +
                                                     possibleWord3))
        else:
            for possibleWord1 in possibleWords1:
                for possibleWord2 in possibleWords2:
                    result.extend(
                        self.getLiteralsWithName(possibleWord1 + " " +
                                                 possibleWord2))
        return result
Ejemplo n.º 2
0
    def constructLiterals(self, word: str, parse: MorphologicalParse,
                          metaParse: MetamorphicParse,
                          fsm: FsmMorphologicalAnalyzer):
        """
        Creates a list of literals with a specified word, or possible words corresponding to morphological parse.

        PARAMETERS
        ----------
        word : str
            literal String
        parse : MorphologicalParse
            morphological parse to get possible words
        metaParse : MetamorphicParse
            metamorphic parse to get possible words
        fsm : FsmMorphologicalAnalyzer
            finite state machine morphological analyzer to be used at getting possible words

        RETURNS
        -------
        list
            A list of literal
        """
        result = []
        if parse.size() > 0:
            if not parse.isPunctuation() and not parse.isCardinal(
            ) and not parse.isReal():
                possibleWords = fsm.getPossibleWords(parse, metaParse)
                for possibleWord in possibleWords:
                    result.extend(self.getLiteralsWithName(possibleWord))
            else:
                result.extend(self.getLiteralsWithName(word))
        else:
            result.extend(self.getLiteralsWithName(word))
        return result
Ejemplo n.º 3
0
    def constructSynSets(self, word: str, parse: MorphologicalParse,
                         metaParse: MetamorphicParse,
                         fsm: FsmMorphologicalAnalyzer) -> list:
        """
        Creates a list of SynSets with a specified word, or possible words corresponding to morphological parse.

        PARAMETERS
        ----------
        word : str
            literal String  to get SynSets with
        parse : MorphologicalParse
            morphological parse to get SynSets with proper literals
        metaParse : MetamorphicParse
            metamorphic parse to get possible words
        fsm : FsmMorphologicalAnalyzer
            finite state machine morphological analyzer to be used at getting possible words

        RETURNS
        -------
        list
            A list of SynSets
        """
        result = []
        if parse.size() > 0:
            if parse.isProperNoun():
                result.append(self.getSynSetWithLiteral("(özel isim)", 1))
            if parse.isTime():
                result.append(self.getSynSetWithLiteral("(zaman)", 1))
            if parse.isDate():
                result.append(self.getSynSetWithLiteral("(tarih)", 1))
            if parse.isHashTag():
                result.append(self.getSynSetWithLiteral("(hashtag)", 1))
            if parse.isEmail():
                result.append(self.getSynSetWithLiteral("(email)", 1))
            if parse.isOrdinal():
                result.append(
                    self.getSynSetWithLiteral("(sayı sıra sıfatı)", 1))
            if parse.isPercent():
                result.append(self.getSynSetWithLiteral("(yüzde)", 1))
            if parse.isFraction():
                result.append(self.getSynSetWithLiteral("(kesir sayı)", 1))
            if parse.isRange():
                result.append(self.getSynSetWithLiteral("(sayı aralığı)", 1))
            if parse.isReal():
                result.append(self.getSynSetWithLiteral("(reel sayı)", 1))
            if not parse.isPunctuation() and not parse.isCardinal(
            ) and not parse.isReal():
                possibleWords = fsm.getPossibleWords(parse, metaParse)
                for possibleWord in possibleWords:
                    synSets = self.getSynSetsWithLiteral(possibleWord)
                    if len(synSets) > 0:
                        for synSet in synSets:
                            if synSet.getPos() is not None and (
                                    parse.getPos() == "NOUN" or parse.getPos()
                                    == "ADVERB" or parse.getPos() == "VERB"
                                    or parse.getPos() == "ADJ"
                                    or parse.getPos() == "CONJ"):
                                if synSet.getPos() == Pos.NOUN:
                                    if parse.getPos(
                                    ) == "NOUN" or parse.getRootPos(
                                    ) == "NOUN":
                                        result.append(synSet)
                                elif synSet.getPos() == Pos.ADVERB:
                                    if parse.getPos(
                                    ) == "ADVERB" or parse.getRootPos(
                                    ) == "ADVERB":
                                        result.append(synSet)
                                elif synSet.getPos() == Pos.VERB:
                                    if parse.getPos(
                                    ) == "VERB" or parse.getRootPos(
                                    ) == "VERB":
                                        result.append(synSet)
                                elif synSet.getPos() == Pos.ADJECTIVE:
                                    if parse.getPos(
                                    ) == "ADJ" or parse.getRootPos() == "ADJ":
                                        result.append(synSet)
                                elif synSet.getPos() == Pos.CONJUNCTION:
                                    if parse.getPos(
                                    ) == "CONJ" or parse.getRootPos(
                                    ) == "CONJ":
                                        result.append(synSet)
                                else:
                                    result.append(synSet)
                            else:
                                result.append(synSet)
                if len(result) == 0:
                    for possibleWord in possibleWords:
                        synSets = self.getSynSetsWithLiteral(possibleWord)
                        result.extend(synSets)
            else:
                result.extend(self.getSynSetsWithLiteral(word))
            if parse.isCardinal() and len(result) == 0:
                result.append(self.getSynSetWithLiteral("(tam sayı)", 1))
        else:
            result.extend(self.getSynSetsWithLiteral(word))
        return result