def makeFormulas(self):
     """
     The main workhorse method, which extracts formulas from the text.
     """
     formulaDict = {}
     for i in reversed(range(2, 15)):
         if self.verbose:
             print('Поиск n-грамм длины ' + str(i))
         Ngrams = []
         for line in self.poem:
             Ngrams += self.makeNGrams(line, i)
         if self.verbose and len(Ngrams) > 0:
             for item in Ngrams[:-1]:
                 print(item, end=' | ')
             print(Ngrams[-1])
         while True:
             Ngrams = self.filter(Ngrams)
             if len(Ngrams) > 1:
                 basis  = Ngrams[0]
                 formulas2Be = LinkedList()
                 formulas2Be.add(basis)
                 for Ngram in Ngrams[1:]:
                     if Ngram == basis:
                         formulas2Be.add(Ngram)
                 for item in formulas2Be:
                     Ngrams.remove(item)
                 if len(formulas2Be) >= 2:
                     for item in formulas2Be:
                         for word in item.words:
                             self.useMatrix[word.line][word.index] = True
                     formulaDict[basis.key] = formulas2Be
             else:
                 break
     return formulaDict
Ejemplo n.º 2
0
        else:
            new_word = new_word + present_node.get_data()

        present_node = present_node.get_next()
        next_node = next_node.get_next()
        print(present_node.get_data())
        #print(next_node.get_data())

    new_word = new_word + present_node.get_data()
    new_sentence = new_word

    return new_sentence


word_list = LinkedList()
word_list.add("T")
word_list.add("h")
word_list.add("e")
word_list.add("/")
word_list.add("*")
word_list.add("s")
word_list.add("k")
word_list.add("y")
word_list.add("*")
word_list.add("i")
word_list.add("s")
word_list.add("/")
word_list.add("/")
word_list.add("b")
word_list.add("l")
word_list.add("u")
Ejemplo n.º 3
0
from DataStructures import LinkedList

ll = LinkedList()
ll.add(1)
ll.add(2)
ll.add(3)
print(ll)

print(ll.remove())
print(ll)
Ejemplo n.º 4
0
    next_node = present_node.get_next()

    while (present_node.get_next() != None):

        data1 = present_node.get_data()
        data2 = next_node.get_data()

        if data1 == data2:
            print(data1)
            duplicate_list.delete(data1)
            present_node = next_node
            next_node = next_node.get_next()

        if data1 != data2:
            present_node = next_node
            next_node = next_node.get_next()

    duplicate_list.display()
    return duplicate_list


#Add different values to the linked list and test your program
duplicate_list = LinkedList()
duplicate_list.add(30)
duplicate_list.add(40)
duplicate_list.add(40)
duplicate_list.add(40)
duplicate_list.add(40)

print(remove_duplicates(duplicate_list))