Skip to content

Commit

Permalink
fix:expand
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Dec 6, 2024
1 parent 1b11f57 commit 160e086
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ovos_padatious/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import json
import math
from os.path import join
Expand Down Expand Up @@ -47,6 +47,7 @@ def match(self, sent, entities=None):

def save(self, folder):
prefix = join(folder, self.name)
os.makedirs(folder, exist_ok=True)
with open(prefix + '.hash', 'wb') as f:
f.write(self.hash)
self.simple_intent.save(prefix)
Expand Down
2 changes: 2 additions & 0 deletions ovos_padatious/opm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def _match_level(self, utterances, limit, lang=None, message: Optional[Message]
limit (float): required confidence level.
"""
m: IntentHandlerMatch = self.service._match_level(utterances, limit, lang, message)
if not m:
return None
return IntentMatch("Padatious", m.match_type, m.match_data, m.skill_id, m.utterance)

def match_high(self, utterances, lang=None, message=None) -> Optional[IntentMatch]:
Expand Down
6 changes: 3 additions & 3 deletions ovos_padatious/train_data.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 ovos_padatious.util import tokenize, expand_parentheses, remove_comments
from ovos_padatious.util import tokenize, expand_lines


class TrainData(object):
Expand All @@ -25,8 +25,8 @@ def __init__(self):
self.sent_lists = {}

def add_lines(self, name, lines):
lines = remove_comments(lines)
self.sent_lists[name] = sum([expand_parentheses(tokenize(line)) for line in lines], [])
lines = expand_lines(lines)
self.sent_lists[name] = sum([tokenize(line) for line in lines], [])
self.sent_lists[name] = [i for i in self.sent_lists[name] if i]

def remove_lines(self, name):
Expand Down
10 changes: 6 additions & 4 deletions ovos_padatious/trainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from abc import ABCMeta, abstractmethod


class Trainable(object):
class Trainable:
__metaclass__ = ABCMeta

def __init__(self, name, hsh=b''):
self.name = name
self.hash = hsh

def load_hash(self, prefix):
with open(prefix + '.hash', 'rb') as f:
self.hash = f.read()
if os.path.isfile(prefix + '.hash'):
with open(prefix + '.hash', 'rb') as f:
self.hash = f.read()

def save_hash(self, prefix):
os.makedirs(os.path.dirname(prefix), exist_ok=True)
with open(prefix + '.hash', 'wb') as f:
f.write(self.hash)

Expand Down
8 changes: 8 additions & 0 deletions ovos_padatious/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ovos_utils import flatten_list
from ovos_utils.bracket_expansion import expand_template

from xxhash import xxh32
from ovos_padatious.bracket_expansion import SentenceTreeParser

Expand Down Expand Up @@ -92,6 +95,11 @@ def expand_parentheses(sent):
return SentenceTreeParser(sent).expand_parentheses()


def expand_lines(lines):
lines = [expand_template(i) for i in remove_comments(lines)]
return flatten_list(lines)


def remove_comments(lines):
return [i for i in lines if not i.startswith('//')]

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ fann2>=1.0.7, < 1.1.0
xxhash
ovos-plugin-manager>=0.5.0,<1.0.0
ovos-workshop>=0.1.7,<4.0.0
ovos-utils>=0.3.4,<1.0.0
ovos-utils>=0.6.0,<1.0.0
langcodes

0 comments on commit 160e086

Please sign in to comment.