Hi there,
I am trying to interact with Fiskmo Machine Translation Engine through jshell.
Basically, I run the Fiskmo MT, input some text and I can get the translated text:
This works under Cygwin's Terminal. But when I am trying to use jShell, I cannot get the stdout.
Here is my code:
Here is how to test this:
1. Download and install Fiskmo MT Engine from here: https://github.com/Helsinki-NLP/OPUS-CAT
2. Install one machine translation model like Chinese to English which can be downloaded from here: https://object.pouta.csc.fi/Tatoeba-MT-models/zho-eng/opus-2020-07-17.zip
3. Use my test code and modify the path.
I am trying to interact with Fiskmo Machine Translation Engine through jshell.
Basically, I run the Fiskmo MT, input some text and I can get the translated text:
B4X:
spm_encode.exe --model source.spm | marian.exe decode --log-level=warn -c decoder.yml
我爱 中国!
▁I ▁love ▁China !
This works under Cygwin's Terminal. But when I am trying to use jShell, I cannot get the stdout.
Here is my code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("main") 'Load the layout file.
MainForm.Show
TextArea1.Text="我爱中国!"
RunMarian
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub RunMarian
sh.Initialize("sh","cmd",Array("/c","StartSentencePieceMtPipe.bat","C:\Users\xulihang\AppData\Local\fiskmo\models\zh-en\opus-2020-07-17-zh2en"))
sh.InputStreamEnabled=True
sh.Encoding="UTF8"
sh.WorkingDirectory="E:\Download\FiskmoMTEngine"
sh.RunWithOutputEvents(-1)
'sh.Run(-1)
End Sub
Sub Button1_MouseClicked (EventData As MouseEvent)
sh.WriteToInputStream(TextArea1.Text.GetBytes("UTF8"))
End Sub
Sub sh_StdOut (Buffer() As Byte, Length As Int)
Log("out")
Dim translation As String=BytesToString(Buffer,0,Length,"UTF8").Replace(" ","").Replace("▁"," ").Trim
Log(translation)
TextArea2.Text=translation
End Sub
Sub sh_StdErr (Buffer() As Byte, Length As Int)
Log("err")
Log(BytesToString(Buffer,0,Length,"UTF8"))
End Sub
Here is how to test this:
1. Download and install Fiskmo MT Engine from here: https://github.com/Helsinki-NLP/OPUS-CAT
2. Install one machine translation model like Chinese to English which can be downloaded from here: https://object.pouta.csc.fi/Tatoeba-MT-models/zho-eng/opus-2020-07-17.zip
3. Use my test code and modify the path.