Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
daanzu committed Sep 5, 2020
1 parent 15c6df0 commit 8671d8e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/*
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions kaldi_active_grammar/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# 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

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
Expand Down
4 changes: 2 additions & 2 deletions kaldi_active_grammar/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions kaldi_active_grammar/wfst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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]:
Expand Down

0 comments on commit 8671d8e

Please sign in to comment.