scriptconv-copyleft 0.6.0a1__tar.gz → 0.7.0a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/PKG-INFO +1 -1
  2. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/tiny_vanya.py +60 -3
  3. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/version.py +1 -1
  4. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft.egg-info/PKG-INFO +1 -1
  5. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_tiny_vanya.py +56 -0
  6. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/LICENSE +0 -0
  7. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/README.md +0 -0
  8. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/pyproject.toml +0 -0
  9. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/__init__.py +0 -0
  10. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/__init__.py +0 -0
  11. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/__init__.py +0 -0
  12. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/COPYING +0 -0
  13. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/LICENSE.md +0 -0
  14. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/__init__.py +0 -0
  15. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/rulebook.txt +0 -0
  16. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/LICENSE +0 -0
  17. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/MODEL_LICENSE.md +0 -0
  18. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/NOTICE +0 -0
  19. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/__init__.py +0 -0
  20. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/codemix.py +0 -0
  21. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/data/LICENSE +0 -0
  22. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/data/en_fast_lexicon.json.gz +0 -0
  23. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/data/ne_heteronyms.tsv.gz +0 -0
  24. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/data/ne_lexicon.tsv.gz +0 -0
  25. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/frontend.py +0 -0
  26. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/inventory.py +0 -0
  27. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/pawp/nepali_rules.py +0 -0
  28. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/reginute/COPYING +0 -0
  29. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/reginute/LICENSE +0 -0
  30. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/reginute/SOURCE +0 -0
  31. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/reginute/lt_kirciai.tsv +0 -0
  32. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/reginute/lt_kreipiniai.tsv +0 -0
  33. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/reginute/lt_raides.tsv +0 -0
  34. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/LICENSE +0 -0
  35. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/NOTICE +0 -0
  36. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/__init__.py +0 -0
  37. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/bilingual.py +0 -0
  38. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/LICENSE +0 -0
  39. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/LICENSE.ruaccent +0 -0
  40. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/caps_words.json.gz +0 -0
  41. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/homograph_defaults.json.gz +0 -0
  42. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/homograph_model.json.gz +0 -0
  43. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/pronunciations.json.gz +0 -0
  44. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/stress_forms.json.gz +0 -0
  45. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/stress_variants.json.gz +0 -0
  46. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/data/yo_words.json.gz +0 -0
  47. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/_vendored/tiny_vanya/text.py +0 -0
  48. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/eu.py +0 -0
  49. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/fa.py +0 -0
  50. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/gl.py +0 -0
  51. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/he.py +0 -0
  52. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/ja.py +0 -0
  53. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/ja_prosody.py +0 -0
  54. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/ko.py +0 -0
  55. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/lt.py +0 -0
  56. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/mul.py +0 -0
  57. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/pawp.py +0 -0
  58. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/phonemizers/th.py +0 -0
  59. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft/readings.py +0 -0
  60. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft.egg-info/SOURCES.txt +0 -0
  61. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft.egg-info/dependency_links.txt +0 -0
  62. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft.egg-info/requires.txt +0 -0
  63. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/scriptconv_copyleft.egg-info/top_level.txt +0 -0
  64. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/setup.cfg +0 -0
  65. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_docs_examples.py +0 -0
  66. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_espeak_acute_stress.py +0 -0
  67. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_espeak_french_english_switch.py +0 -0
  68. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_espeak_get_lang_case.py +0 -0
  69. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_espeak_long_line.py +0 -0
  70. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_espeak_lt_accent.py +0 -0
  71. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_espeak_nul_byte.py +0 -0
  72. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_g2pfa_eraab.py +0 -0
  73. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_hebrew_ipa.py +0 -0
  74. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_lang_default_region.py +0 -0
  75. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_match_lang_direction.py +0 -0
  76. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_match_lang_preferred_value.py +0 -0
  77. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_misaki_en_alphabet.py +0 -0
  78. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_misaki_ja_reader.py +0 -0
  79. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_misaki_vi.py +0 -0
  80. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_misaki_zh_zero.py +0 -0
  81. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_openjtalk_prosody.py +0 -0
  82. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_pawp.py +0 -0
  83. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_phonemizers_base.py +0 -0
  84. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_phonemizers_cjk_ar.py +0 -0
  85. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_phonemizers_friendly_import_errors.py +0 -0
  86. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_phonemizers_identity.py +0 -0
  87. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_phonemizers_misaki_british.py +0 -0
  88. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_phonemizers_punctuation.py +0 -0
  89. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_readings.py +0 -0
  90. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_tltk.py +0 -0
  91. {scriptconv_copyleft-0.6.0a1 → scriptconv_copyleft-0.7.0a1}/tests/test_transphone_extra_declares_auto_installs.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv-copyleft
3
- Version: 0.6.0a1
3
+ Version: 0.7.0a1
4
4
  Summary: scriptconv phonemizer backends whose code or dependencies are copyleft (GPL, LGPL, AGPL)
5
5
  Author-email: TigreGotico <contact@tigregotico.com>
6
6
  License-Expression: Apache-2.0 AND GPL-3.0-only AND GPL-3.0-or-later AND CC-BY-4.0 AND MIT
@@ -37,12 +37,13 @@ Data in ``_vendored/tiny_vanya/data``, read on first use:
37
37
  from __future__ import annotations
38
38
 
39
39
  from functools import cached_property
40
+ from typing import Iterator
40
41
 
41
- from scriptconv.phonemizers.base import BasePhonemizer, _check_alphabet
42
+ from scriptconv.phonemizers.base import CLAUSE_PUNCTUATION, BasePhonemizer, Segment, _check_alphabet
42
43
  from scriptconv.phonemizers.enums import Alphabet
43
44
 
44
45
  from scriptconv_copyleft.phonemizers._vendored.tiny_vanya import bilingual, text
45
- from scriptconv_copyleft.phonemizers._vendored.tiny_vanya.text import Phonemized
46
+ from scriptconv_copyleft.phonemizers._vendored.tiny_vanya.text import NothingToPronounce, Phonemized
46
47
 
47
48
  __all__ = ["TinyVanyaPhonemizer", "Phonemized", "SYMBOLS"]
48
49
 
@@ -50,6 +51,8 @@ SYMBOLS = text.BILINGUAL_SYMBOLS
50
51
  """The 116 symbols of the Tiny Vanya models, in id order."""
51
52
 
52
53
  _STRESS_MARK = {1: "ˈ", 2: "ˌ"}
54
+ _CLAUSE_MARKS = frozenset(CLAUSE_PUNCTUATION.values())
55
+ _SENTENCE_MARKS = frozenset(".?!")
53
56
 
54
57
 
55
58
  class TinyVanyaPhonemizer(BasePhonemizer):
@@ -65,13 +68,19 @@ class TinyVanyaPhonemizer(BasePhonemizer):
65
68
  pronunciations: a pronunciation table ``{"defaults": ..., "variants": ...}``,
66
69
  as in the ``pronunciations`` of a Tiny Vanya model config. ``None``
67
70
  reads the table of ``onnx/m1.json`` that ships with this package.
71
+ tokens: :meth:`phonemize_segments` yields the Tiny Vanya tokens, not
72
+ IPA: one bounded segment per clause, from ``<bos>`` to ``<eos>``,
73
+ with ``ids`` and ``stress`` streams. The stress is 0 (none),
74
+ 1 (primary) or 2 (secondary) for each symbol.
68
75
  """
69
76
 
70
77
  engine_distribution = "espyak"
71
78
 
72
- def __init__(self, alphabet: Alphabet = Alphabet.IPA, pronunciations: dict | None = None):
79
+ def __init__(self, alphabet: Alphabet = Alphabet.IPA, pronunciations: dict | None = None,
80
+ tokens: bool = False):
73
81
  _check_alphabet(self, alphabet, [Alphabet.IPA])
74
82
  super().__init__(alphabet)
83
+ self.tokens_mode = tokens
75
84
  if pronunciations is not None:
76
85
  self.pronunciations = pronunciations
77
86
 
@@ -97,3 +106,51 @@ class TinyVanyaPhonemizer(BasePhonemizer):
97
106
  return " ".join(
98
107
  "".join(_STRESS_MARK.get(tokens.stress[i], "") + tokens.symbols[i] for i in range(start, end))
99
108
  for start, end in tokens.words)
109
+
110
+ def phonemize_segments(self, text: str, lang: str) -> Iterator[Segment]:
111
+ """The segments of *text*; with ``tokens=True``, the tokens of each clause.
112
+
113
+ A clause ends after a run of ``, . ? ! ; :`` that follows a sound. Its mark is the first
114
+ mark of the run, and it ends a sentence when the run holds ``.``,
115
+ ``?`` or ``!``. The last clause ends a sentence. The text is read
116
+ whole once; text with no word to read gives no segment.
117
+ """
118
+ if not self.tokens_mode:
119
+ yield from super().phonemize_segments(text, lang)
120
+ return
121
+ try:
122
+ whole = self.phonemize_tokens(text, lang)
123
+ except NothingToPronounce:
124
+ return
125
+ symbols = whole.symbols
126
+ last = len(symbols) - 1
127
+ start = index = 1
128
+ sound = False
129
+ clauses = []
130
+ while index < last:
131
+ if symbols[index] == "<unk>" or symbols[index][0] != "<" and any(c.isalpha() for c in symbols[index]):
132
+ sound = True
133
+ elif sound and symbols[index] in _CLAUSE_MARKS:
134
+ end = index
135
+ while end < last and symbols[end] in _CLAUSE_MARKS:
136
+ end += 1
137
+ clauses.append([start, end, symbols[index], bool(_SENTENCE_MARKS.intersection(symbols[index:end]))])
138
+ start = index = end + (end < last and symbols[end] == "<sp>")
139
+ sound = False
140
+ continue
141
+ index += 1
142
+ if start < last:
143
+ clauses.append([start, last, None, True])
144
+ if clauses:
145
+ clauses[-1][3] = True
146
+ for start, end, mark, ends_sentence in clauses:
147
+ yield Segment((symbols[0], *symbols[start:end], symbols[-1]), mark, ends_sentence,
148
+ {"ids": (whole.ids[0], *whole.ids[start:end], whole.ids[-1]),
149
+ "stress": (0, *whole.stress[start:end], 0)},
150
+ bounded=True)
151
+
152
+ def word_break(self) -> Segment:
153
+ """``<sp>`` with its id with ``tokens=True``, else a space."""
154
+ if self.tokens_mode:
155
+ return Segment(("<sp>",), streams={"ids": (SYMBOLS.index("<sp>"),), "stress": (0,)})
156
+ return super().word_break()
@@ -1,6 +1,6 @@
1
1
  # START_VERSION_BLOCK
2
2
  VERSION_MAJOR = 0
3
- VERSION_MINOR = 6
3
+ VERSION_MINOR = 7
4
4
  VERSION_BUILD = 0
5
5
  VERSION_ALPHA = 1
6
6
  # END_VERSION_BLOCK
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv-copyleft
3
- Version: 0.6.0a1
3
+ Version: 0.7.0a1
4
4
  Summary: scriptconv phonemizer backends whose code or dependencies are copyleft (GPL, LGPL, AGPL)
5
5
  Author-email: TigreGotico <contact@tigregotico.com>
6
6
  License-Expression: Apache-2.0 AND GPL-3.0-only AND GPL-3.0-or-later AND CC-BY-4.0 AND MIT
@@ -81,3 +81,59 @@ def test_without_numpy_english_falls_back_to_espyak(monkeypatch):
81
81
  assert tokens.symbols[0] == "<bos>" and tokens.symbols[-1] == "<eos>"
82
82
  assert "<unk>" not in tokens.symbols
83
83
  assert "w" in tokens.symbols
84
+
85
+
86
+ def _parity_row(text):
87
+ return next(row for row in ROWS if row["text"] == text)
88
+
89
+
90
+ def test_tokens_mode_yields_the_tiny_vanya_ids_and_stress():
91
+ row = _parity_row("Привет, как дела?")
92
+ whole = TinyVanyaPhonemizer().phonemize_tokens(row["text"], "ru")
93
+ segments = list(TinyVanyaPhonemizer(tokens=True).phonemize_segments(row["text"], "ru"))
94
+ bos, eos = row["ids"][0], row["ids"][-1]
95
+ cut = row["ids"].index(SYMBOLS.index(",")) + 1
96
+ assert [s.streams["ids"] for s in segments] == [
97
+ (bos, *row["ids"][1:cut], eos), (bos, *row["ids"][cut:-1], eos)]
98
+ assert [s.streams["stress"] for s in segments] == [
99
+ (0, *row["stress"][1:cut], 0), (0, *row["stress"][cut:-1], 0)]
100
+ assert [i for s in segments for i in s.streams["ids"][1:-1]] == list(whole.ids[1:-1])
101
+ assert [s.phonemes for s in segments] == [tuple(SYMBOLS[i] for i in s.streams["ids"]) for s in segments]
102
+
103
+
104
+ def test_tokens_mode_frames_each_clause():
105
+ segments = list(TinyVanyaPhonemizer(tokens=True).phonemize_segments("Да, конечно. Нет", "ru"))
106
+ assert [s.phonemes[0] for s in segments] == ["<bos>"] * 3
107
+ assert [s.phonemes[-1] for s in segments] == ["<eos>"] * 3
108
+ assert [s.mark for s in segments] == [",", ".", None]
109
+ assert [s.ends_sentence for s in segments] == [False, True, True]
110
+ assert all(s.bounded for s in segments)
111
+ assert [s.phonemes[-2] for s in segments[:2]] == [",", "."]
112
+
113
+
114
+ def test_without_tokens_the_segments_are_ipa():
115
+ vanya = TinyVanyaPhonemizer()
116
+ segments = list(vanya.phonemize_segments("Привет! Как дела?", "ru"))
117
+ assert ["".join(s.phonemes) for s in segments] == ["prʲivʲˈet", "kˈɑk dʲiɭˈɑ"]
118
+ assert not any(s.bounded for s in segments)
119
+
120
+
121
+ def test_tokens_mode_last_clause_ends_a_sentence():
122
+ segments = list(TinyVanyaPhonemizer(tokens=True).phonemize_segments("Привет,", "ru"))
123
+ assert [(s.mark, s.ends_sentence) for s in segments] == [(",", True)]
124
+
125
+
126
+ def test_tokens_mode_mark_is_the_first_of_the_run():
127
+ segments = list(TinyVanyaPhonemizer(tokens=True).phonemize_segments("Ну... да?!", "ru"))
128
+ assert segments[-1].mark == "?"
129
+
130
+
131
+ def test_tokens_mode_marks_only_give_no_segment():
132
+ assert list(TinyVanyaPhonemizer(tokens=True).phonemize_segments("?!", "ru")) == []
133
+
134
+
135
+ @pytest.mark.parametrize("text, marks", [("! Привет", [None]), ("— Привет, мир!", [",", "!"])])
136
+ def test_tokens_mode_leading_marks_stay_with_the_next_clause(text, marks):
137
+ segments = list(TinyVanyaPhonemizer(tokens=True).phonemize_segments(text, "ru"))
138
+ assert [s.mark for s in segments] == marks
139
+ assert all("p" in s.phonemes or "mʲ" in s.phonemes for s in segments)