Skip to content

Commit

Permalink
Apply suggestions from coderabbit review
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
JarbasAl and coderabbitai[bot] authored Oct 16, 2024
1 parent e7d66d8 commit 56abf91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions ovos_padatious/padaos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from threading import Lock
from typing import Dict, List, Optional, Tuple, Union
from typing import Dict, List, Optional, Union
from ovos_utils.log import LOG


Expand Down Expand Up @@ -207,7 +207,9 @@ def _compile(self) -> None:
}
self.must_compile = False

def _calc_entities(self, query: str, regexes: List[re.Pattern]) -> Dict[str, str]:
from typing import Dict, List, Optional, Union, Iterator

def _calc_entities(self, query: str, regexes: List[re.Pattern]) -> Iterator[Dict[str, str]]:
"""
Calculates entities from a given query using the provided regex patterns.
Expand All @@ -226,7 +228,9 @@ def _calc_entities(self, query: str, regexes: List[re.Pattern]) -> Dict[str, str
for k, v in match.groupdict().items() if v
}

def calc_intents(self, query: str) -> Union[Dict[str, Union[str, Dict[str, str]]], None]:
from typing import Dict, List, Optional, Union, Iterator

def calc_intents(self, query: str) -> Iterator[Dict[str, Union[str, Dict[str, str]]]]:
"""
Calculates intents for a given query.
Expand All @@ -247,15 +251,15 @@ def calc_intents(self, query: str) -> Union[Dict[str, Union[str, Dict[str, str]]
'entities': min(entities, key=lambda x: sum(map(len, x.values())))
}

def calc_intent(self, query: str) -> Union[str, None]:
def calc_intent(self, query: str) -> Dict[str, Union[str, Dict[str, str]]]:
"""
Calculates the most likely intent for a given query.
Args:
query (str): The input query to process.
Returns:
Union[str, None]: The name of the matched intent or None if no match is found.
Dict[str, Union[str, Dict[str, str]]]: A dictionary containing the intent name and entities.
"""
return min(
self.calc_intents(query),
Expand Down
2 changes: 1 addition & 1 deletion ovos_padatious/simple_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Tuple, Optional
from typing import List, Optional
from fann2 import libfann as fann

from ovos_padatious.id_manager import IdManager
Expand Down

0 comments on commit 56abf91

Please sign in to comment.