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

fix encoding issues for Windows users #68

Merged
merged 1 commit into from
Apr 2, 2022
Merged
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
8 changes: 4 additions & 4 deletions comet/cli/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ def score_command() -> None:
if not cfg.disable_cache:
model.set_embedding_cache()

with open(cfg.sources()) as fp:
with open(cfg.sources(), encoding="utf-8") as fp:
sources = [line.strip() for line in fp.readlines()]

translations = []
for path_fr in cfg.translations:
with open(path_fr()) as fp:
with open(path_fr(), encoding="utf-8") as fp:
translations.append([line.strip() for line in fp.readlines()])

if "comet-qe" in cfg.model:
data = {"src": [sources for _ in translations], "mt": translations}
else:
with open(cfg.references()) as fp:
with open(cfg.references(), encoding="utf-8") as fp:
references = [line.strip() for line in fp.readlines()]
data = {
"src": [sources for _ in translations],
Expand Down Expand Up @@ -304,7 +304,7 @@ def score_command() -> None:
print("{}\tscore: {:.4f}".format(files[j], sys_scores[j]))

if isinstance(cfg.to_json, str):
with open(cfg.to_json, "w") as outfile:
with open(cfg.to_json, "w", encoding="utf-8") as outfile:
json.dump(data, outfile, ensure_ascii=False, indent=4)
print("Predictions saved in: {}.".format(cfg.to_json))

Expand Down