Ejemplo n.º 1
0
 def test_init(self):
     with pytest.raises(TypeError):
         SentenceSubcatalog(True)
     sentence_subcatalog = SentenceSubcatalog(True, 16000, [_LEXICON])
     assert sentence_subcatalog.is_sample == True
     assert sentence_subcatalog.sample_rate == 16000
     assert sentence_subcatalog.lexicon == [_LEXICON]
Ejemplo n.º 2
0
 def test_dumps(self, attributes, subcatalog_sentence):
     sentence_subcatalog = SentenceSubcatalog(
         subcatalog_sentence["isSample"],
         subcatalog_sentence["sampleRate"],
         subcatalog_sentence["lexicon"],
     )
     sentence_subcatalog.attributes = attributes
     assert sentence_subcatalog.dumps() == subcatalog_sentence
Ejemplo n.º 3
0
    def test_eq(self):
        contents1 = {
            "isSample": True,
            "sampleRate": 16000,
            "lexicon": ["mean", "m", "iy", "n"],
            "attributes": [{"name": "gender", "enum": ["male", "female"]}],
        }
        contents2 = {
            "isSample": True,
            "sampleRate": 16000,
            "lexicon": ["mean", "m"],
            "attributes": [{"name": "gender", "enum": ["male", "female"]}],
        }
        sentence_subcatalog1 = SentenceSubcatalog.loads(contents1)
        sentence_subcatalog2 = SentenceSubcatalog.loads(contents1)
        sentence_subcatalog3 = SentenceSubcatalog.loads(contents2)

        assert sentence_subcatalog1 == sentence_subcatalog2
        assert sentence_subcatalog1 != sentence_subcatalog3
Ejemplo n.º 4
0
    def test_dumps(self, categories, keypoints, catalog_contents):
        catalog = Catalog()
        catalog.box2d = Box2DSubcatalog()
        catalog.box3d = Box3DSubcatalog()
        catalog.polygon = PolygonSubcatalog()
        catalog.polyline2d = Polyline2DSubcatalog()
        catalog.sentence = SentenceSubcatalog()

        classificationsubcatalog = ClassificationSubcatalog()
        classificationsubcatalog.categories = categories
        catalog.classification = classificationsubcatalog

        keypoints2dsubcatalog = Keypoints2DSubcatalog()
        keypoints2dsubcatalog._keypoints = [keypoints]
        catalog.keypoints2d = keypoints2dsubcatalog

        assert catalog.dumps() == catalog_contents
Ejemplo n.º 5
0
def _get_subcatalog(lexion_path: str) -> SentenceSubcatalog:
    subcatalog = SentenceSubcatalog()
    with open(lexion_path, encoding="utf-8") as fp:
        for line in islice(fp, 4, None):
            subcatalog.append_lexicon(line.strip().split())
    return subcatalog
Ejemplo n.º 6
0
 def append_lexicon(self):
     sentence_subcatalog = SentenceSubcatalog()
     sentence_subcatalog.append_lexicon(_LEXICON)
     assert sentence_subcatalog.lexicon == [_LEXICON]
Ejemplo n.º 7
0
 def test_loads(self, attributes, subcatalog_sentence):
     sentence_subcatalog = SentenceSubcatalog.loads(subcatalog_sentence)
     assert sentence_subcatalog.is_sample == subcatalog_sentence["isSample"]
     assert sentence_subcatalog.sample_rate == subcatalog_sentence["sampleRate"]
     assert sentence_subcatalog.lexicon == subcatalog_sentence["lexicon"]
     assert sentence_subcatalog.attributes == attributes