def getCandidateSynSets(self, wordNet: WordNet, fsm: FsmMorphologicalAnalyzer, leafList: list, index: int) -> list:
     twoPrevious = None
     previous = None
     twoNext = None
     next = None
     current = leafList[index].getLayerInfo()
     if index > 1:
         twoPrevious = leafList[index - 2].getLayerInfo()
     if index > 0:
         previous = leafList[index - 1].getLayerInfo()
     if index != len(leafList) - 1:
         next = leafList[index + 1].getLayerInfo()
     if index < len(leafList) - 2:
         twoNext = leafList[index + 2].getLayerInfo()
     synSets = wordNet.constructSynSets(current.getMorphologicalParseAt(0).getWord().getName(),
                 current.getMorphologicalParseAt(0), current.getMetamorphicParseAt(0), fsm)
     if twoPrevious is not None and twoPrevious.getMorphologicalParseAt(0) is not None and previous.getMorphologicalParseAt(0) is not None:
         synSets.extend(wordNet.constructIdiomSynSets(fsm, twoPrevious.getMorphologicalParseAt(0), twoPrevious.getMetamorphicParseAt(0),
                                                      previous.getMorphologicalParseAt(0), previous.getMetamorphicParseAt(0),
                                                      current.getMorphologicalParseAt(0), current.getMetamorphicParseAt(0)))
     if previous is not None and previous.getMorphologicalParseAt(0) is not None and next is not None and next.getMorphologicalParseAt(0) is not None:
         synSets.extend(wordNet.constructIdiomSynSets(fsm, previous.getMorphologicalParseAt(0), previous.getMetamorphicParseAt(0),
                                                      current.getMorphologicalParseAt(0), current.getMetamorphicParseAt(0),
                                                      next.getMorphologicalParseAt(0), next.getMetamorphicParseAt(0)))
     if next is not None and next.getMorphologicalParseAt(0) is not None and twoNext is not None and twoNext.getMorphologicalParseAt(0) is not None:
         synSets.extend(wordNet.constructIdiomSynSets(fsm, current.getMorphologicalParseAt(0), current.getMetamorphicParseAt(0),
                                                      next.getMorphologicalParseAt(0), next.getMetamorphicParseAt(0),
                                                      twoNext.getMorphologicalParseAt(0), twoNext.getMetamorphicParseAt(0)))
     if previous is not None and previous.getMorphologicalParseAt(0) is not None:
         synSets.extend(wordNet.constructIdiomSynSets(fsm, previous.getMorphologicalParseAt(0), previous.getMetamorphicParseAt(0),
                                                      current.getMorphologicalParseAt(0), current.getMetamorphicParseAt(0)))
     if next is not None and next.getMorphologicalParseAt(0) is not None:
         synSets.extend(wordNet.constructIdiomSynSets(fsm, current.getMorphologicalParseAt(0), current.getMetamorphicParseAt(0),
                                                      next.getMorphologicalParseAt(0), next.getMetamorphicParseAt(0)))
     return synSets
 def getCandidateSynSets(self, wordNet: WordNet,
                         fsm: FsmMorphologicalAnalyzer,
                         sentence: AnnotatedSentence, index: int) -> list:
     twoPrevious = None
     previous = None
     twoNext = None
     next = None
     current = sentence.getWord(index)
     if index > 1:
         twoPrevious = sentence.getWord(index - 2)
     if index > 0:
         previous = sentence.getWord(index - 1)
     if index != sentence.wordCount() - 1:
         next = sentence.getWord(index + 1)
     if index < sentence.wordCount() - 2:
         twoNext = sentence.getWord(index + 2)
     synSets = wordNet.constructSynSets(
         current.getParse().getWord().getName(), current.getParse(),
         current.getMetamorphicParse(), fsm)
     if twoPrevious is not None and twoPrevious.getParse(
     ) is not None and previous.getParse() is not None:
         synSets.extend(
             wordNet.constructIdiomSynSets(
                 fsm, twoPrevious.getParse(),
                 twoPrevious.getMetamorphicParse(), previous.getParse(),
                 previous.getMetamorphicParse(), current.getParse(),
                 current.getMetamorphicParse()))
     if previous is not None and previous.getParse(
     ) is not None and next is not None and next.getParse() is not None:
         synSets.extend(
             wordNet.constructIdiomSynSets(fsm, previous.getParse(),
                                           previous.getMetamorphicParse(),
                                           current.getParse(),
                                           current.getMetamorphicParse(),
                                           next.getParse(),
                                           next.getMetamorphicParse()))
     if next is not None and next.getParse(
     ) is not None and twoNext is not None and twoNext.getParse(
     ) is not None:
         synSets.extend(
             wordNet.constructIdiomSynSets(fsm, current.getParse(),
                                           current.getMetamorphicParse(),
                                           next.getParse(),
                                           next.getMetamorphicParse(),
                                           twoNext.getParse(),
                                           twoNext.getMetamorphicParse()))
     if previous is not None and previous.getParse() is not None:
         synSets.extend(
             wordNet.constructIdiomSynSets(fsm, previous.getParse(),
                                           previous.getMetamorphicParse(),
                                           current.getParse(),
                                           current.getMetamorphicParse()))
     if next is not None and next.getParse() is not None:
         synSets.extend(
             wordNet.constructIdiomSynSets(fsm, current.getParse(),
                                           current.getMetamorphicParse(),
                                           next.getParse(),
                                           next.getMetamorphicParse()))
     return synSets
    def constructSynSets(self, wordNet: WordNet, fsm: FsmMorphologicalAnalyzer,
                         wordIndex: int) -> list:
        """
        Creates a list of synset candidates for the i'th word in the sentence. It combines the results of
        1. All possible synsets containing the i'th word in the sentence
        2. All possible synsets containing 2-word expressions, which contains the i'th word in the sentence
        3. All possible synsets containing 3-word expressions, which contains the i'th word in the sentence

        PARAMETERS
        ----------
        wordNet : WordNet
            Turkish wordnet
        fsm : FsmMorphologicalAnalyzer
            Turkish morphological analyzer
        wordIndex : int
            Word index

        RETURNS
        -------
        list
            List of synset candidates containing all possible root forms and multiword expressions.
        """
        word = self.getWord(wordIndex)
        possibleSynSets = []
        if isinstance(word, AnnotatedWord):
            morphologicalParse = word.getParse()
            metamorphicParse = word.getMetamorphicParse()
            possibleSynSets.extend(
                wordNet.constructSynSets(
                    morphologicalParse.getWord().getName(), morphologicalParse,
                    metamorphicParse, fsm))
            firstPrecedingWord = None
            secondPrecedingWord = None
            firstSucceedingWord = None
            secondSucceedingWord = None
            if wordIndex > 0:
                firstPrecedingWord = self.getWord(wordIndex - 1)
                if wordIndex > 1:
                    secondPrecedingWord = self.getWord(wordIndex - 2)
            if self.wordCount() > wordIndex + 1:
                firstSucceedingWord = self.getWord(wordIndex + 1)
                if self.wordCount() > wordIndex + 2:
                    secondSucceedingWord = self.getWord(wordIndex + 2)
            if firstPrecedingWord is not None and isinstance(
                    firstPrecedingWord, AnnotatedWord):
                if secondPrecedingWord is not None and isinstance(
                        secondPrecedingWord, AnnotatedWord):
                    possibleSynSets.extend(
                        wordNet.constructIdiomSynSets(
                            fsm, secondPrecedingWord.getParse(),
                            secondPrecedingWord.getMetamorphicParse(),
                            firstPrecedingWord.getParse(),
                            firstPrecedingWord.getMetamorphicParse(),
                            word.getParse(), word.getMetamorphicParse()))
                possibleSynSets.extend(
                    wordNet.constructIdiomSynSets(
                        fsm, firstPrecedingWord.getParse(),
                        firstPrecedingWord.getMetamorphicParse(),
                        word.getParse(), word.getMetamorphicParse()))
            if firstSucceedingWord is not None and isinstance(
                    firstSucceedingWord, AnnotatedWord):
                if secondSucceedingWord is not None and isinstance(
                        secondSucceedingWord, AnnotatedWord):
                    possibleSynSets.extend(
                        wordNet.constructIdiomSynSets(
                            fsm, word.getParse(), word.getMetamorphicParse(),
                            firstSucceedingWord.getParse(),
                            firstSucceedingWord.getMetamorphicParse(),
                            secondSucceedingWord.getParse(),
                            secondSucceedingWord.getMetamorphicParse()))
                possibleSynSets.extend(
                    wordNet.constructIdiomSynSets(
                        fsm, word.getParse(), word.getMetamorphicParse(),
                        firstSucceedingWord.getParse(),
                        firstSucceedingWord.getMetamorphicParse()))
        return possibleSynSets