summaryrefslogtreecommitdiff
path: root/realtime
diff options
context:
space:
mode:
authormjdenkowski <michael.j.denkowski@gmail.com>2013-09-11 16:20:36 -0400
committermjdenkowski <michael.j.denkowski@gmail.com>2013-09-11 16:20:36 -0400
commit8b429e08566ffc640c2de0f0eca66c354c8377f9 (patch)
tree060f9dec9743ab8ff71c643c7aa136026735be51 /realtime
parent84e0f04f9c3a156aa9292c6d6dedbbd94b13bd1a (diff)
Find pycdec
Diffstat (limited to 'realtime')
-rw-r--r--realtime/rt/__init__.py15
-rw-r--r--realtime/rt/aligner.py2
-rw-r--r--realtime/rt/decoder.py4
-rw-r--r--realtime/rt/rt.py8
4 files changed, 21 insertions, 8 deletions
diff --git a/realtime/rt/__init__.py b/realtime/rt/__init__.py
index 738777f3..fbde8f4d 100644
--- a/realtime/rt/__init__.py
+++ b/realtime/rt/__init__.py
@@ -1,3 +1,18 @@
+# Add pycdec to the Python path if user hasn't
+import os
+import sys
+try:
+ import cdec
+except ImportError as ie:
+ try:
+ pycdec = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'python')
+ sys.path.append(pycdec)
+ import cdec
+ except:
+ sys.stderr.write('Error: cannot import pycdec. Please check the cdec/python is built.\n')
+ raise ie
+
+# Regular init imports
from rt import *
import aligner
import decoder
diff --git a/realtime/rt/aligner.py b/realtime/rt/aligner.py
index 3c6ea144..80835412 100644
--- a/realtime/rt/aligner.py
+++ b/realtime/rt/aligner.py
@@ -9,7 +9,7 @@ class ForceAligner:
def __init__(self, fwd_params, fwd_err, rev_params, rev_err):
- cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
fast_align = os.path.join(cdec_root, 'word-aligner', 'fast_align')
atools = os.path.join(cdec_root, 'utils', 'atools')
diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py
index 0a202fae..34b5d391 100644
--- a/realtime/rt/decoder.py
+++ b/realtime/rt/decoder.py
@@ -17,7 +17,7 @@ class Decoder:
class CdecDecoder(Decoder):
def __init__(self, config, weights):
- cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
decoder = os.path.join(cdec_root, 'decoder', 'cdec')
decoder_cmd = [decoder, '-c', config, '-w', weights]
logging.info('Executing: {}'.format(' '.join(decoder_cmd)))
@@ -26,7 +26,7 @@ class CdecDecoder(Decoder):
class MIRADecoder(Decoder):
def __init__(self, config, weights):
- cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
mira = os.path.join(cdec_root, 'training', 'mira', 'kbest_cut_mira')
# optimizer=2 step=0.001 best=500, k=500, uniq, stream
mira_cmd = [mira, '-c', config, '-w', weights, '-o', '2', '-C', '0.001', '-b', '500', '-k', '500', '-u', '-t']
diff --git a/realtime/rt/rt.py b/realtime/rt/rt.py
index 892cc217..4dc2de09 100644
--- a/realtime/rt/rt.py
+++ b/realtime/rt/rt.py
@@ -10,9 +10,7 @@ import subprocess
import tempfile
import time
-from cdec.configobj import ConfigObj
-import cdec.sa
-
+import cdec
import aligner
import decoder
import util
@@ -21,7 +19,7 @@ class RealtimeDecoder:
def __init__(self, configdir, tmpdir='/tmp', cache_size=5, norm=False):
- cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+ cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Temporary work dir
self.tmp = tempfile.mkdtemp(dir=tmpdir, prefix='realtime.')
@@ -41,7 +39,7 @@ class RealtimeDecoder:
self.aligner = aligner.ForceAligner(fwd_params, fwd_err, rev_params, rev_err)
# Grammar extractor
- sa_config = ConfigObj(os.path.join(configdir, 'sa.ini'), unrepr=True)
+ sa_config = cdec.ConfigObj(os.path.join(configdir, 'sa.ini'), unrepr=True)
sa_config.filename = os.path.join(self.tmp, 'sa.ini')
util.sa_ini_for_realtime(sa_config, os.path.abspath(configdir))
sa_config.write()