Skip to content

Commit c55295d

Browse files
author
Hiromu Hota
committed
Add test_get_ngrams_that_match_in_string
1 parent eb94005 commit c55295d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/utils/data_model_utils/test_visual.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,25 @@ def test_get_horz_ngrams(doc_setup):
141141
"orange",
142142
".",
143143
]
144+
145+
146+
def test_get_ngrams_that_match_in_string(doc_setup):
147+
"""Test if ngrams can be obtained even if they match mention's span in string."""
148+
doc = doc_setup
149+
sentence: Sentence = doc.sentences[0]
150+
# Assert this sentence is visual.
151+
assert sentence.is_visual()
152+
# Assert this sentence is not tabular.
153+
assert not sentence.is_tabular()
154+
155+
# Create 1-gram span mentions
156+
space = MentionNgrams(n_min=1, n_max=1)
157+
mentions = [tc for tc in space.apply(doc)]
158+
assert len(mentions) == len([word for sent in doc.sentences for word in sent.words])
159+
160+
# Pick "is" from the apple sentence that matches "is" in the orange sentence.
161+
mention = mentions[1]
162+
assert mention.get_span() == "is"
163+
# Check if the "is" in the orange sentence can be obtained.
164+
ngrams = list(get_horz_ngrams(mention, from_sentence=False))
165+
assert "is" in ngrams

0 commit comments

Comments
 (0)