cleanup debug output

This commit is contained in:
Hieu Hoang 2024-03-15 10:32:29 -07:00
parent 9fe6cd88af
commit 0af3b0b56a
3 changed files with 17 additions and 22 deletions

View File

@ -1,6 +1,5 @@
#include "Moses2Wrapper.h"
#include <iostream>
#include <fstream>
#include <string.h>
@ -34,19 +33,10 @@ extern "C" EXPORT MosesApiErrorCode __stdcall GetMosesSystem(const char* filePat
}
extern "C" EXPORT MosesApiErrorCode __stdcall Translate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char** output) {
ofstream tmpfile;
tmpfile.open("C:\\moses.log", ios::app);
tmpfile << "Start Translate: " << endl;
tmpfile << pObject << " " << endl;
tmpfile << id << " " << endl;
tmpfile << string(input) << endl;
if (pObject != NULL)
{
std::string tr = pObject->Translate(input, id);
tmpfile << "tr=" << tr << endl;
*output = Moses2Wrapper::CopyString(tr.c_str());
tmpfile << "output=" << string(*output) << endl;
return MS_API_OK;
}
else {

14
moses2/Moses2Wrapper.cpp Normal file → Executable file
View File

@ -2,6 +2,8 @@
#include "System.h"
#include "legacy/Parameter.h"
#include "TranslationTask.h"
#include <string.h>
using namespace std;
namespace Moses2 {
//summary :: need to update the LM path at runtime with complete artifact path.
@ -52,4 +54,16 @@ namespace Moses2 {
delete m_param;
delete m_system;
}
char* Moses2Wrapper::CopyString(const char* str) {
int32_t size = (int32_t)strlen(str);
char* obj = (char*)malloc(size + 1);
memcpy(obj, str, size);
obj[size] = '\0';
return obj;
}
void Moses2Wrapper::Free(void* ptr) {
free(ptr);
}
}

15
moses2/Moses2Wrapper.h Normal file → Executable file
View File

@ -1,6 +1,6 @@
#pragma once
#include <string>
#include <string.h>
namespace Moses2 {
class Parameter;
class System;
@ -22,18 +22,9 @@ namespace Moses2 {
~Moses2Wrapper();
std::string Translate(const std::string& input, long id);
void UpdateLMPath(const std::string& filePath);
int getEngineVersion();
static char* CopyString(const char* str) {
int32_t size = (int32_t)strlen(str);
char* obj = (char*)malloc(size + 1);
memcpy(obj, str, size);
obj[size] = '\0';
return obj;
}
static void Free(void* ptr) {
free(ptr);
}
static char* CopyString(const char* str);
static void Free(void* ptr);
};
}