1717from datetime import timedelta
1818from typing import Dict , List , Union
1919
20- import pystache
20+ import chevron
2121import regex as re
2222import soundswallower
2323from lxml import etree
5353
5454@dataclass
5555class WordSequence :
56- """ Sequence of "unit" XML elements
56+ """Sequence of "unit" XML elements
5757
5858 By default, the unit elements are the <w> elements.
5959
@@ -69,7 +69,7 @@ class WordSequence:
6969
7070
7171def get_sequences (xml , xml_filename , unit = "w" , anchor = "anchor" ) -> List [WordSequence ]:
72- """ Return the list of anchor-separated word sequences in xml
72+ """Return the list of anchor-separated word sequences in xml
7373
7474 Args:
7575 xml (etree): xml structure in which to search for words and anchors
@@ -122,7 +122,7 @@ def get_sequences(xml, xml_filename, unit="w", anchor="anchor") -> List[WordSequ
122122
123123
124124def split_silences (words : List [dict ], final_end , excluded_segments : List [dict ]) -> None :
125- """ split the silences between words, making sure we don't step over any
125+ """split the silences between words, making sure we don't step over any
126126 excluded segment boundaries
127127
128128 Args:
@@ -170,7 +170,7 @@ def align_audio( # noqa: C901
170170 g2p_fallbacks = None ,
171171 verbose_g2p_warnings = False ,
172172):
173- """ Align an XML input file to an audio file.
173+ """Align an XML input file to an audio file.
174174
175175 Args:
176176 xml_path (str): Path to XML input file in TEI-like format
@@ -429,7 +429,7 @@ def save_readalong(
429429 output_xhtml : bool = False ,
430430 audiofile : str ,
431431):
432- """ Save the results from align_audio() into the otuput files required for a
432+ """Save the results from align_audio() into the otuput files required for a
433433 readalong
434434
435435 Args:
@@ -529,7 +529,7 @@ def save_readalong(
529529
530530
531531def return_word_from_id (xml : etree , el_id : str ) -> str :
532- """ Given an XML document, return the innertext at id
532+ """Given an XML document, return the innertext at id
533533
534534 Args:
535535 xml (etree): XML document
@@ -542,7 +542,7 @@ def return_word_from_id(xml: etree, el_id: str) -> str:
542542
543543
544544def return_words_and_sentences (results ):
545- """ Parse xml into word and sentence 'tier' data
545+ """Parse xml into word and sentence 'tier' data
546546
547547 Args:
548548 results([TODO type]): [TODO description]
@@ -587,7 +587,7 @@ def return_words_and_sentences(results):
587587
588588
589589def write_to_text_grid (words : List [dict ], sentences : List [dict ], duration : float ):
590- """ Write results to Praat TextGrid. Because we are using pympi, we can also export to Elan EAF.
590+ """Write results to Praat TextGrid. Because we are using pympi, we can also export to Elan EAF.
591591
592592 Args:
593593 words (List[dict]): List of word times containing start, end, and value keys
@@ -629,7 +629,7 @@ def float_to_timedelta(n: float) -> str:
629629
630630
631631def write_to_subtitles (data : Union [List [dict ], List [List [dict ]]]):
632- """ Returns WebVTT object from data.
632+ """Returns WebVTT object from data.
633633
634634 Args:
635635 data (Union[List[dict], List[List[dict]]]):
@@ -659,7 +659,7 @@ def write_to_subtitles(data: Union[List[dict], List[List[dict]]]):
659659
660660
661661def convert_to_xhtml (tokenized_xml , title = "Book" ):
662- """ Do a simple and not at all foolproof conversion to XHTML.
662+ """Do a simple and not at all foolproof conversion to XHTML.
663663
664664 Args:
665665 tokenized_xml (etree): xml etree with tokens, converted in place
@@ -715,7 +715,7 @@ def convert_to_xhtml(tokenized_xml, title="Book"):
715715
716716
717717def create_input_tei (** kwargs ):
718- """ Create input xml in TEI standard.
718+ """Create input xml in TEI standard.
719719 Uses readlines to infer paragraph and sentence structure from plain text.
720720 TODO: Check if path, if it's just plain text, then render that instead of reading from the file
721721 Assumes a double blank line marks a page break, and a single blank line
@@ -780,7 +780,7 @@ def create_input_tei(**kwargs):
780780 paragraphs .append ({"sentences" : sentences })
781781 if paragraphs :
782782 pages .append ({"paragraphs" : paragraphs })
783- xml = pystache .render (TEI_TEMPLATE , {** kwargs , ** {"pages" : pages }})
783+ xml = chevron .render (TEI_TEMPLATE , {** kwargs , ** {"pages" : pages }})
784784 outfile .write (xml .encode ("utf-8" ))
785785 outfile .flush ()
786786 outfile .close ()
0 commit comments