przetwarzanie_jezyka_natura.../E/maxmatch.py

23 lines
640 B
Python
Raw Normal View History

2023-01-19 21:22:01 +01:00
import pandas as pd
def max_match(sentence: str, dictionary: list) -> list:
if not sentence:
return []
sen_len = len(sentence)
for i in range(sen_len - 1, -1, -1):
firstword = sentence[0:i]
remainder = sentence[i:sen_len]
if firstword in dictionary:
return [firstword] + max_match(remainder, dictionary)
firstword = sentence[0]
remainder = sentence[1:sen_len]
return [firstword] + max_match(remainder, dictionary)
pm = pd.read_csv("PoliMorf-0.6.7.tab", delimiter="\t", header=None)
polish_dict = list(pm[0])
result = max_match("Alamakota", polish_dict)
print(result)