diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18e5383..9f6d2f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,7 +83,7 @@ jobs: echo $GITHUB_WORKSPACE df -h ls -al '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/' - ls -al '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.26.28720' + # ls -al '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.26.28720' ls -al '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/v142' # ls -al '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.16.27012/x64/Microsoft.VC141.CRT' ls -al '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/'*/x64/Microsoft.*.CRT @@ -163,12 +163,12 @@ jobs: with: name: wheels path: main/dist/* - - name: Copy Windows vc_redist - run: | - mkdir -p vc_redist - cp '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.26.28720'/vc_redist.x64.exe vc_redist/ - cp '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.26.28720'/x64/Microsoft.*.CRT/* vc_redist/ - - uses: actions/upload-artifact@v2 - with: - name: vc_redist - path: vc_redist/* + # - name: Copy Windows vc_redist + # run: | + # mkdir -p vc_redist + # cp '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.26.28720'/vc_redist.x64.exe vc_redist/ + # cp '/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.26.28720'/x64/Microsoft.*.CRT/* vc_redist/ + # - uses: actions/upload-artifact@v2 + # with: + # name: vc_redist + # path: vc_redist/* diff --git a/Justfile b/Justfile index 1e061a5..a070fa8 100644 --- a/Justfile +++ b/Justfile @@ -32,3 +32,6 @@ setup-linux-develop kaldi_root_dir: ln -sr {{kaldi_root_dir}}/src/fstbin/fstaddselfloops kaldi_active_grammar/exec/linux/ ln -sr {{kaldi_root_dir}}/src/dragonfly/libkaldi-dragonfly.so kaldi_active_grammar/exec/linux/ ln -sr {{kaldi_root_dir}}/src/dragonflybin/compile-graph-agf kaldi_active_grammar/exec/linux/ + +test_model model_dir: + cd {{invocation_directory()}} && rm -rf kaldi_model kaldi_model.tmp && cp -rp {{model_dir}} kaldi_model diff --git a/kaldi_active_grammar/compiler.py b/kaldi_active_grammar/compiler.py index e8212c1..0b9b80f 100644 --- a/kaldi_active_grammar/compiler.py +++ b/kaldi_active_grammar/compiler.py @@ -4,7 +4,7 @@ # Licensed under the AGPL-3.0; see LICENSE.txt file. # -import base64, collections, copy, logging, multiprocessing, os, re, shlex, shutil, subprocess +import collections, copy, logging, multiprocessing, os, re, shlex, shutil, subprocess import concurrent.futures from contextlib import contextmanager from io import open @@ -12,7 +12,7 @@ from six.moves import range, zip from . import _log, KaldiError -from .utils import ExternalProcess, debug_timer, lazy_readonly_property, load_symbol_table, platform, show_donation_message, symbol_table_lookup, touch_file +from .utils import ExternalProcess, debug_timer, load_symbol_table, platform, show_donation_message, symbol_table_lookup, touch_file from .wfst import WFST from .model import Model import kaldi_active_grammar.alternative_dictation as alternative_dictation diff --git a/kaldi_active_grammar/model.py b/kaldi_active_grammar/model.py index 580c094..70fa99b 100644 --- a/kaldi_active_grammar/model.py +++ b/kaldi_active_grammar/model.py @@ -7,7 +7,7 @@ import os, re, shutil from io import open -from six import text_type +from six import PY2, text_type import requests try: @@ -383,7 +383,7 @@ def reset_user_lexicon(self): def convert_generic_model_to_agf(src_dir, model_dir): from .compiler import Compiler - if six.PY2: + if PY2: from .kaldi import augment_phones_txt_py2 as augment_phones_txt, augment_words_txt_py2 as augment_words_txt else: from .kaldi import augment_phones_txt, augment_words_txt diff --git a/kaldi_active_grammar/wfst.py b/kaldi_active_grammar/wfst.py index ce68394..208c7ac 100644 --- a/kaldi_active_grammar/wfst.py +++ b/kaldi_active_grammar/wfst.py @@ -36,7 +36,7 @@ def clear(self): def iter_arcs(self): return itertools.chain.from_iterable(itervalues(self._arc_table_dict)) - def state_is_final(self, state): + def is_state_final(self, state): return (self._state_table[state] != 0) def add_state(self, weight=None, initial=False, final=False): @@ -84,12 +84,14 @@ def label_is_silent(self, label): return ((label in self.silent_labels) or (label.startswith('#nonterm'))) def scale_weights(self, factor): + # Unused factor = float(factor) for arcs in itervalues(self._arc_table_dict): for arc in arcs: arc[4] = arc[4] * factor def normalize_weights(self, stochasticity=False): + # Unused for arcs in itervalues(self._arc_table_dict): num_weights = len(arcs) sum_weights = sum(arc[4] for arc in arcs) @@ -99,6 +101,7 @@ def normalize_weights(self, stochasticity=False): def has_eps_path(self, path_src_state, path_dst_state, eps_like_labels=frozenset()): """ Returns True iff there is a epsilon path from src_state to dst_state. Uses BFS. Does not follow nonterminals! """ + # Used in: dragonfly backend compiler. eps_like_labels = frozenset((self.eps, self.eps_disambig)) | frozenset(eps_like_labels) state_queue = collections.deque([path_src_state]) queued = set(state_queue) @@ -115,12 +118,13 @@ def has_eps_path(self, path_src_state, path_dst_state, eps_like_labels=frozenset def does_match(self, target_words, wildcard_nonterms=(), include_silent=False): """ Returns the olabels on a matching path if there is one, False if not. Uses BFS. Wildcard accepts zero or more words. """ + # Used in: KaldiAG compiler. queue = collections.deque() # entries: (state, path of ilabels of arcs to state, index into target_words of remaining words) queue.append((self.start_state, (), 0)) while queue: state, path, target_word_index = queue.popleft() target_word = target_words[target_word_index] if target_word_index < len(target_words) else None - if (target_word is None) and self.state_is_final(state): + if (target_word is None) and self.is_state_final(state): return tuple(olabel for olabel in path if include_silent or not self.label_is_silent(olabel)) for arc in self._arc_table_dict[state]: