Skip to content

Correctly merge lowercase and uppercase bigrams #24

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions lowercase_ngrams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Merges frequencies of uppercase and lowercase n-grams.

For example, if the input looks like this:

aa bb 5
Aa bb 3
Cc dd 2
ee ff 1

This tool outputs:

aa bb 8
cc dd 2
ee ff 1

"""
from __future__ import print_function

import sys
from collections import Counter

if __name__ == '__main__':
ngram_frequency = Counter()
for line in sys.stdin:
ngram, count = line.split('\t')
ngram, count = ngram.lower(), int(count)
ngram_frequency[ngram] += count

for ngram, count in sorted(ngram_frequency.items()):
print(ngram, count, sep='\t')
4 changes: 4 additions & 0 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def test_segment_12():
]
assert segment(''.join(result)) == result

def test_segment_13():
result = ['hello', 'world']
assert segment(''.join(result)) == result

def test_main():
main(['tests/test.txt'])
result = os.linesep.join(('choose spain', 'this is a test')) + os.linesep
Expand Down
Loading