-
Notifications
You must be signed in to change notification settings - Fork 3
Heuristic update #361
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
Heuristic update #361
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| """Test ngram utilities""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from compass.utilities.ngrams import ( | ||
| _check_word, | ||
| _filtered_words, | ||
| sentence_ngram_containment, | ||
| convert_text_to_sentence_ngrams, | ||
| ) | ||
|
|
||
|
|
||
| def test_check_word_filters_common_terms_and_punctuation(): | ||
| """Test `_check_word` rejects stop words and punctuation""" | ||
|
|
||
| assert not _check_word("the") | ||
| assert not _check_word(",") | ||
| assert _check_word("solar") | ||
|
|
||
|
|
||
| def test_filtered_words_removes_noise_tokens(): | ||
| """Test `_filtered_words` only returns significant tokens""" | ||
|
|
||
| sentence = "The solar arrays, and storage!" | ||
| assert _filtered_words(sentence) == [ | ||
| "solar", | ||
| "arrays", | ||
| "storage", | ||
| "!", | ||
| ] | ||
|
|
||
|
|
||
| def test_convert_text_to_sentence_ngrams_multiple_sentences(): | ||
| """Test `convert_text_to_sentence_ngrams` builds ngrams per sentence""" | ||
|
|
||
| text = "The solar arrays store energy. Solar storage thrives." | ||
| assert convert_text_to_sentence_ngrams(text, 2) == [ | ||
| ("solar", "arrays"), | ||
| ("arrays", "store"), | ||
| ("store", "energy"), | ||
| ("solar", "storage"), | ||
| ("storage", "thrives"), | ||
| ] | ||
|
|
||
|
|
||
| def test_sentence_ngram_containment_computes_fraction(): | ||
| """Test `sentence_ngram_containment` returns containment ratio""" | ||
|
|
||
| original = "Solar arrays store energy. Batteries support solar arrays." | ||
| test_text = "Solar arrays store energy. Solar arrays fail." | ||
| result = sentence_ngram_containment(original, test_text, 2) | ||
| assert result == pytest.approx(0.8) | ||
|
|
||
|
|
||
| def test_sentence_ngram_containment_handles_empty_test_text(): | ||
| """Test containment logic handles empty-or-stopword sentences""" | ||
|
|
||
| assert sentence_ngram_containment("", "The and is", 2) == 0.0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main(["-q", "--show-capture=all", Path(__file__), "-rapP"]) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.