Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lemma_to_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json

result_dict = {}
conflicts = []

with open("lemma.en.txt", "r") as infile:
for line in infile:
if line.startswith(";"):
# ignore comments
continue

split_line = line.strip().split("->")
key_words = split_line[1].split(",")
value = split_line[0].split("/")[0].strip()

if result_dict.get(value):
dup = f"{value}:{result_dict.get(value)} -> {value}:{value}"
print(f"{dup} exists")
conflicts.append(dup)
else:
result_dict[value] = value

for keyword in key_words:
kw = keyword.strip()
if result_dict.get(kw):
dup = f"{kw}:{result_dict.get(kw)} -> {kw}:{value}"
print(f"{dup} exists")
conflicts.append(dup)
continue
result_dict[kw] = value

print(f"{len(result_dict)} items converted")
print(f"{len(conflicts)} items duplicated")

with open("lemma.en.json", "w") as f:
json.dump(result_dict, f)