Skip to content

Commit

Permalink
Add chunking model unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ophelielacroix committed Oct 16, 2020
1 parent 356a138 commit 0383107
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/test_spacy_model.py
Expand Up @@ -3,7 +3,7 @@
import spacy
import operator
from danlp.download import download_model, DEFAULT_CACHE_DIR, _unzip_process_func
from danlp.models import load_spacy_model
from danlp.models import load_spacy_model, load_spacy_chunking_model
import os

class TestSpacyModel(unittest.TestCase):
Expand All @@ -16,17 +16,22 @@ def test_download(self):
info = spacy.info(model_path)
self.assertListEqual(info['pipeline'], ['tagger', 'parser', 'ner'])
self.assertEqual(info['lang'], 'da')


def test_predictions(self):

nlp = load_spacy_model()
some_text = "Jeg gik en tur med Lars"
some_text = "Jeg gik en tur med Lars Bo Jensen i går"
doc = nlp(some_text)
self.assertTrue(doc.is_parsed)
self.assertTrue(doc.is_nered)
self.assertTrue(doc.is_tagged)


chunker = load_spacy_chunking_model(spacy_model=nlp)
chunks_from_text = chunker.predict(some_text)
chunks_from_tokens = chunker.predict([t.text for t in doc])
self.assertEqual(chunks_from_text, chunks_from_tokens)
self.assertEqual(len(chunks_from_text), len(doc))


class TestSpacySentimentModel(unittest.TestCase):
def test_download(self):
# Download model beforehand
Expand Down

0 comments on commit 0383107

Please sign in to comment.