summaryrefslogtreecommitdiff
path: root/python/cdec/sa
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-06-28 13:49:53 +0200
committerPatrick Simianer <p@simianer.de>2015-06-28 13:49:53 +0200
commit5707c6176b354c65d34125e2444208868eee3541 (patch)
treee69595d35251dab61c5f3a72be0249f1e868e9c3 /python/cdec/sa
parent96379c9adef0a1c5b970e7765369e85833514405 (diff)
drop
Diffstat (limited to 'python/cdec/sa')
-rw-r--r--python/cdec/sa/extract.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/python/cdec/sa/extract.py b/python/cdec/sa/extract.py
index 37234e9e..88ad2170 100644
--- a/python/cdec/sa/extract.py
+++ b/python/cdec/sa/extract.py
@@ -105,6 +105,7 @@ def stream_extract2(url):
socket.bind(url)
sys.stderr.write("[extractor] sending hello ...\n")
socket.send("hello")
+ default_context = "default_context"
while True:
line = socket.recv()
if line.strip() == "shutdown":
@@ -113,18 +114,25 @@ def stream_extract2(url):
if not line:
break
fields = re.split('\s*\|\|\|\s*', line.strip())
+ # error
+ if len(fields) == 1:
+ socket.send("[extractor] error: can't process input '{}'".format(line.strip()))
# context ||| cmd
if len(fields) == 2:
(context, cmd) = fields
+ assert(context == default_context)
if cmd.lower() == 'drop':
if online:
extractor.drop_ctx(context)
- sock.send('[extractor] drop {}'.format(context))
+ socket.send("[extractor] dropping context '{}'".format(context))
else:
- sock.send('[extractor] Error: online mode not set. Skipping line: {}'.format(line.strip()))
+ socket.send("[extractor] error: online mode not set, skipping input: {}".format(line.strip()))
+ else:
+ socket.send("[extractor] don't know command '{}'".format(cmd))
# context ||| sentence ||| grammar_file
elif len(fields) == 3:
(context, sentence, grammar_file) = fields
+ assert(context == default_context)
with (gzip.open if compress else open)(grammar_file, 'w') as output:
for rule in extractor.grammar(sentence, context):
output.write(str(rule)+'\n')
@@ -132,10 +140,11 @@ def stream_extract2(url):
# context ||| sentence ||| reference ||| alignment
elif len(fields) == 4:
(context, sentence, reference, alignment) = fields
+ assert(context == default_context)
extractor.add_instance(sentence, reference, alignment, context)
- socket.send('[extractor] learn (context: {})'.format(context))
+ socket.send("[extractor] learning (context: '{}')".format(context))
else:
- socket.send('[extractor] Error: see README.md for stream mode usage. Skipping line: {}'.format(line.strip()))
+ socket.send("[extractor] error, skipping input: '{}'".format(line.strip()))
socket.send("off")
socket.close()