I have a nested list of strings:
[['Start', 'двигаться', 'другая', 'сторона', 'света', 'надолго', 'скоро'],
['Start', 'двигаться', 'другая', 'сторона', 'света', 'чтобы', 'посмотреть'],
['Start', 'двигаться', 'новая', 'планета'],
['Start', 'двигаться', 'сторона', 'признание', 'суверенитет', 'израильский'],
['Start', 'двигаться', 'сторона', 'признание', 'высот', 'на'],
['Start', 'двигаться', 'сторона', 'признание', 'высот', 'оккупировать'],
['Start', 'двигаться', 'сторона', 'признание', 'высот', 'Голанский'],
['Start', 'двигаться', 'сторона', 'признание', 'и']]
I need an algorithm to find first longest common sequence for two or more words in the list (in this case all sublists has two first common elements 'Start', 'двигаться'
), make a string from them, move to next elements, find next longest common for two or more ('сторона', 'света', 'надолго'
and 'сторона', 'признание'
in this case) if a sublist has this common element, make next string from it. If there are no common elements, just add the rest words as a single string. And so on. If there is one element left in sequence, add it to the previous string. A single common element also does not count as a sequence. Resulting sequences can be of any length and split may start from the first element. Desires output:
[['Start двигаться', 'другая сторона света', 'надолго скоро'],
['Start двигаться', 'другая сторона света', 'чтобы посмотреть'],
['Start двигаться', 'новая планета'],
['Start двигаться', 'сторона признание', 'суверенитет израильский'],
['Start двигаться', 'сторона признание', 'высот на'],
['Start двигаться', 'сторона признание', 'высот оккупировать'],
['Start двигаться', 'сторона признание', 'высот Голанский'],
['Start двигаться', 'сторона признание и']]
I've checked other LCS topics but didn't find a solution.