Skip to content

Reorganization of cg #396

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

Merged
merged 18 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
36af387
Adds subdirectories 'lib' and 'phones' to 'data/phones'. Moves '.phon…
ajmalanoski Mar 26, 2021
6f673f9
Updates 'data/phones/HOWTO.md' to reflect new locations of files
ajmalanoski Mar 26, 2021
528cb1e
Fixes file path in 'data/phones/HOWTO.md'
ajmalanoski Mar 26, 2021
6f8ea4c
Updates outdated components of 'data/phones/HOWTO.md'
ajmalanoski Mar 26, 2021
2d98838
Updates path to phones in 'tests/test_data/test_summary.py'
ajmalanoski Mar 26, 2021
afdb768
Updates changelog
ajmalanoski Mar 26, 2021
a6b079c
Merge branch 'master' into reorganize
ajmalanoski Mar 26, 2021
ba0839a
Renames 'data/cg' to 'data/covering_grammar'
ajmalanoski Mar 26, 2021
8f34b19
Renames covering grammar files to include script info and and transcr…
ajmalanoski Mar 26, 2021
e9ab803
Moves covering grammar/error analysis scripts to 'data/covering_gramm…
ajmalanoski Mar 26, 2021
353d8f8
Adds placeholder README for 'data/covering_grammar/'
ajmalanoski Mar 26, 2021
c33739c
Adds script to make input files for error analysis
ajmalanoski Mar 26, 2021
abd10d0
Removes superfluous comments from 'data/covering_grammar/lib/make_tes…
ajmalanoski Mar 26, 2021
d52822a
Updates changelog
ajmalanoski Mar 26, 2021
f7eefef
Merge branch 'master' of https://github.com/kylebgorman/wikipron into…
ajmalanoski Apr 6, 2021
d0b26ed
Makes (most of the) suggested edits to data/covering_grammar/lib/make…
ajmalanoski Apr 6, 2021
6c164bc
Adds logging config to data/covering_grammar/lib/make_test_file.py. M…
ajmalanoski Apr 6, 2021
0176fe7
Minor style fix
ajmalanoski Apr 6, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Unreleased
- Added `data/cg/tsv/jpn_hira.tsv`. (\#384)
- Enforced final newlines. (\#387)
- Adds all UniMorph languages to morphology. (\#393)
- Added `data/covering_grammar/lib/make_test_file.py` (\#396)

#### Changed

Expand All @@ -45,6 +46,7 @@ Unreleased
- Fixed phone counting in `data/src/generate_phones_summary.py` (\#390, \#392)
- Reorganizes scraping scripts under `data/scrape` (\#394)
- Reorganizes `.phones` files and related scripts under `data/phones` (\#395)
- Reorganizes CG files and related scripts under `data/covering_grammar` (\#395)

### Under `wikipron/` and elsewhere

Expand Down
1 change: 1 addition & 0 deletions data/covering_grammar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(TEMPORARY)
File renamed without changes.
45 changes: 45 additions & 0 deletions data/covering_grammar/lib/make_test_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python

"""Makes test file.

Takes the gold data and the model output, and creates a three-column TSV where
each line has a word, its gold pronunciation, and the predicted pronunciation.
Assumes that the input files have the same words in the same order.
"""

import argparse
import logging


def main(args: argparse.Namespace) -> None:
with open(args.gold, "r") as gf, open(args.pred, "r") as pf:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is a plus here or not but when you're doing a lot of file-opening, contextlib's ExitStack helps a lot: https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack

with open(args.out, "w") as wf:
for i, (g_line, p_line) in enumerate(zip(gf, pf)):
try:
g_data = g_line.split("\t")
p_data = p_line.split("\t")
# Make sure that gold data and predictions have the
# same words
assert g_data[0] == p_data[0]
word = g_data[0]
# Note that we use `strip` to remove the newline
g_pron = g_data[1].strip()
p_pron = p_data[1].strip()
line = "\t".join([word, g_pron, p_pron])
print(line, file=wf)
except AssertionError:
logging.warning(f"{g_data[0]} != {p_data[0]} (line {i})")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"gold", help="TSV with words and correct pronunciations"
)
parser.add_argument(
"pred", help="TSV with words and predicted pronunciations"
)
parser.add_argument(
"-o", "--out", help="file to write to", default="out.tsv"
)
main(parser.parse_args())
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.