in src/dfcx_scrapi/builders/intents.py [0:0]
def _include_spaces_to_phrase(self, phrase: List[str], annots: List[str]):
"""Internal method to add spaces to the training phrase list and
make related changes to the annotations list.
Args:
phrase (List[str]):
A list of strings that represents the training phrase.
annots (List[str]):
A list of strings that represents
parameter_id of each part in phrase.
"""
chars_to_ignore_at_beginning = ["'", ",", ".", "?", "!"]
i = 0
while True:
p_curr, a_curr = phrase[i], annots[i]
try:
p_next, a_next = phrase[i+1], annots[i+1]
except IndexError:
break
if a_curr and a_next:
phrase.insert(i+1, " ")
annots.insert(i+1, "")
i += 2
elif a_curr and not a_next:
flag = any(
ch
for ch in chars_to_ignore_at_beginning
if p_next.startswith(ch)
)
if not flag:
phrase[i+1] = " " + p_next
i += 1
elif not a_curr and a_next:
phrase[i] = p_curr + " "
i += 1
elif not a_curr and not a_next:
phrase[i] = p_curr + " " + p_next
del phrase[i+1]
del annots[i+1]