Welcome to mirror list, hosted at ThFree Co, Russian Federation.

client.py « scripts - github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0eb21bd3243cd3d9cf7b7f073b9e1ad2bc04a4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python

from websocket import create_connection
import time
import sys

filePath = sys.argv[1]
batchSize = int(sys.argv[2])
#print filePath
#print batchSize

def translate( batch ):
  ws = create_connection("ws://localhost:8080/translate")

  #batch = batch[:-1]
  #print batch
  ws.send(batch)
  result=ws.recv()
  result = result[:-1]
  print(result)
  ws.close()
  #time.sleep(5)

with open(filePath) as f:
  batchCount = 0
  batch = ""
  for line in f:
    #print line
    batchCount = batchCount + 1
    batch = batch + line 
    if batchCount == batchSize:
      translate(batch)

      batchCount = 0
      batch = ""

  if batchCount:
    translate(batch)