mirror of https://github.com/coqui-ai/TTS.git
refactor(punctuation): remove orphan code for handling lone punctuation
The case of lone punctuation is already handled at the top of restore(). The removed if statement would never be called and would in fact raise an AttributeError because the _punc_index named tuple doesn't have the attribute `mark`.
This commit is contained in:
parent
11ec9f7471
commit
fee474cfe2
|
@ -15,7 +15,6 @@ class PuncPosition(Enum):
|
||||||
BEGIN = 0
|
BEGIN = 0
|
||||||
END = 1
|
END = 1
|
||||||
MIDDLE = 2
|
MIDDLE = 2
|
||||||
ALONE = 3
|
|
||||||
|
|
||||||
|
|
||||||
class Punctuation:
|
class Punctuation:
|
||||||
|
@ -92,7 +91,7 @@ class Punctuation:
|
||||||
return [text], []
|
return [text], []
|
||||||
# the text is only punctuations
|
# the text is only punctuations
|
||||||
if len(matches) == 1 and matches[0].group() == text:
|
if len(matches) == 1 and matches[0].group() == text:
|
||||||
return [], [_PUNC_IDX(text, PuncPosition.ALONE)]
|
return [], [_PUNC_IDX(text, PuncPosition.BEGIN)]
|
||||||
# build a punctuation map to be used later to restore punctuations
|
# build a punctuation map to be used later to restore punctuations
|
||||||
puncs = []
|
puncs = []
|
||||||
for match in matches:
|
for match in matches:
|
||||||
|
@ -147,9 +146,6 @@ class Punctuation:
|
||||||
if current.position == PuncPosition.END:
|
if current.position == PuncPosition.END:
|
||||||
return [text[0] + current.punc] + cls._restore(text[1:], puncs[1:], num + 1)
|
return [text[0] + current.punc] + cls._restore(text[1:], puncs[1:], num + 1)
|
||||||
|
|
||||||
if current.position == PuncPosition.ALONE:
|
|
||||||
return [current.mark] + cls._restore(text, puncs[1:], num + 1)
|
|
||||||
|
|
||||||
# POSITION == MIDDLE
|
# POSITION == MIDDLE
|
||||||
if len(text) == 1: # pragma: nocover
|
if len(text) == 1: # pragma: nocover
|
||||||
# a corner case where the final part of an intermediate
|
# a corner case where the final part of an intermediate
|
||||||
|
|
|
@ -11,6 +11,8 @@ class PunctuationTest(unittest.TestCase):
|
||||||
("This, is my text ... to be striped !! from text", "This is my text to be striped from text"),
|
("This, is my text ... to be striped !! from text", "This is my text to be striped from text"),
|
||||||
("This, is my text ... to be striped from text?", "This is my text to be striped from text"),
|
("This, is my text ... to be striped from text?", "This is my text to be striped from text"),
|
||||||
("This, is my text to be striped from text", "This is my text to be striped from text"),
|
("This, is my text to be striped from text", "This is my text to be striped from text"),
|
||||||
|
(".", ""),
|
||||||
|
(" . ", ""),
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_get_set_puncs(self):
|
def test_get_set_puncs(self):
|
||||||
|
|
Loading…
Reference in New Issue