Update lcs.py
Browse files
lcs.py
CHANGED
@@ -23,15 +23,18 @@ def find_common_subsequences(sentence, str_list):
|
|
23 |
words = sentence.split()
|
24 |
common_grams = []
|
25 |
added_phrases = set()
|
26 |
-
index = 1
|
27 |
|
28 |
for n in range(5, 0, -1):
|
29 |
for i in range(len(words) - n + 1):
|
30 |
subseq = " ".join(words[i:i+n])
|
31 |
if is_present(subseq, str_list) and not any(subseq in phrase for phrase in added_phrases):
|
32 |
-
common_grams.append((
|
33 |
added_phrases.add(subseq)
|
34 |
-
index += 1
|
35 |
|
36 |
-
|
|
|
37 |
|
|
|
|
|
|
|
|
|
|
23 |
words = sentence.split()
|
24 |
common_grams = []
|
25 |
added_phrases = set()
|
|
|
26 |
|
27 |
for n in range(5, 0, -1):
|
28 |
for i in range(len(words) - n + 1):
|
29 |
subseq = " ".join(words[i:i+n])
|
30 |
if is_present(subseq, str_list) and not any(subseq in phrase for phrase in added_phrases):
|
31 |
+
common_grams.append((i, subseq))
|
32 |
added_phrases.add(subseq)
|
|
|
33 |
|
34 |
+
# Sort by the first appearance in the original sentence
|
35 |
+
common_grams.sort(key=lambda x: x[0])
|
36 |
|
37 |
+
# Assign indices based on the sorted order
|
38 |
+
indexed_common_grams = [(index + 1, subseq) for index, (_, subseq) in enumerate(common_grams)]
|
39 |
+
|
40 |
+
return indexed_common_grams
|