Skip to content

Commit

Permalink
fix:typing and docstrs
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 16, 2024
1 parent 0f4b21f commit 8fd1df8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
8 changes: 5 additions & 3 deletions ovos_padatious/train_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from typing import Dict, List, Generator

from ovos_padatious.util import tokenize, expand_parentheses, remove_comments


Expand All @@ -27,7 +28,7 @@ class TrainData:
"""

def __init__(self) -> None:
self.sent_lists: Dict[str, List[List[str]]] = {}
self.sent_lists: Dict[str, List[str]] = {}

def add_lines(self, name: str, lines: List[str]) -> None:
"""
Expand All @@ -39,10 +40,11 @@ def add_lines(self, name: str, lines: List[str]) -> None:
"""
lines = remove_comments(lines)
self.sent_lists[name] = [
sent for line in lines
sent
for line in lines
for sent in expand_parentheses(tokenize(line))
if sent
]
self.sent_lists[name] = [sent for sent in self.sent_lists[name] if sent]

def remove_lines(self, name: str) -> None:
"""
Expand Down
27 changes: 2 additions & 25 deletions ovos_padatious/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# limitations under the License.

from xxhash import xxh32
from ovos_utils.bracket_expansion import SentenceTreeParser
# keep import for backwards compat
from ovos_utils.bracket_expansion import SentenceTreeParser, expand_parentheses
from typing import List, Tuple, Dict, Any


Expand Down Expand Up @@ -72,30 +73,6 @@ def update(c: str, i: int) -> None:
return tokens


def expand_parentheses(sent: List[str]) -> List[List[str]]:
"""
Expands sentences with parentheses into all possible alternatives.
For example:
'Will it (rain|pour) (today|tomorrow|)?'
Produces:
'Will it rain today?'
'Will it rain tomorrow?'
'Will it rain?'
'Will it pour today?'
'Will it pour tomorrow?'
'Will it pour?'
Args:
sent (List[str]): List of tokens containing parentheses for expansion.
Returns:
List[List[str]]: List of all possible expanded sentences as token lists.
"""
return SentenceTreeParser(sent).expand_parentheses()


def remove_comments(lines: List[str]) -> List[str]:
"""
Removes comment lines from a list of strings.
Expand Down

0 comments on commit 8fd1df8

Please sign in to comment.