-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
197 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/public/cantusdata/test/core/helpers/mei_processing/test_mei_tokenizer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from unittest import TestCase | ||
from os import path | ||
from cantusdata.settings import BASE_DIR | ||
from cantusdata.helpers.mei_processing.mei_tokenizer import ( | ||
MEITokenizer, | ||
generate_ngrams, | ||
) | ||
|
||
|
||
class MEITokenizerTestCase(TestCase): | ||
|
||
def test_generate_ngrams(self) -> None: | ||
with self.subTest("Ngrams from 2 to 3"): | ||
sequence = [1, 2, 3, 4, 5] | ||
min_ngram = 2 | ||
max_ngram = 3 | ||
ngrams = list(generate_ngrams(sequence, min_ngram, max_ngram)) | ||
self.assertEqual( | ||
ngrams, | ||
[[1, 2], [2, 3], [3, 4], [4, 5], [1, 2, 3], [2, 3, 4], [3, 4, 5]], | ||
) | ||
with self.subTest("Ngrams from 3 to 5"): | ||
sequence = [1, 2, 3, 4, 5] | ||
min_ngram = 3 | ||
max_ngram = 5 | ||
ngrams = list(generate_ngrams(sequence, min_ngram, max_ngram)) | ||
self.assertEqual( | ||
ngrams, | ||
[ | ||
[1, 2, 3], | ||
[2, 3, 4], | ||
[3, 4, 5], | ||
[1, 2, 3, 4], | ||
[2, 3, 4, 5], | ||
[1, 2, 3, 4, 5], | ||
], | ||
) | ||
|
||
def test_mei_tokenizer(self) -> None: | ||
with self.subTest("Ngrams from 2 to 3"): | ||
tokenizer = MEITokenizer( | ||
path.join( | ||
BASE_DIR, | ||
"cantusdata", | ||
"test", | ||
"core", | ||
"helpers", | ||
"mei_processing", | ||
"test_mei_files", | ||
"cdn-hsmu-m2149l4_001r.mei", | ||
), | ||
min_ngram=2, | ||
max_ngram=3, | ||
) | ||
with self.subTest("Ngrams from 3 to 5"): | ||
tokenizer = MEITokenizer( | ||
path.join( | ||
BASE_DIR, | ||
"cantusdata", | ||
"test", | ||
"core", | ||
"helpers", | ||
"mei_processing", | ||
"test_mei_files", | ||
"cdn-hsmu-m2149l4_001r.mei", | ||
), | ||
min_ngram=3, | ||
max_ngram=5, | ||
) |