return nbest

This commit is contained in:
Hieu Hoang 2024-03-16 22:50:35 -07:00
parent b35ba85196
commit c41bc4099e
6 changed files with 18 additions and 10 deletions

View File

@ -34,10 +34,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) {
extern "C" EXPORT MosesApiErrorCode __stdcall Translate(Moses2::Moses2Wrapper * pObject, long id, bool nbest, const char* input, char** output) {
if (pObject != NULL)
{
std::string tr = pObject->Translate(input, id);
std::string tr = pObject->Translate(input, id, nbest);
*output = Moses2Wrapper::CopyString(tr.c_str());
return MS_API_OK;
}
@ -91,7 +91,7 @@ int main(int argc, char** argv)
while (std::getline(inFile, input))
{
char* output;
ret = Translate(pObject, id, input.c_str(), &output);
ret = Translate(pObject, id, true, input.c_str(), &output);
assert(ret == MS_API_OK);
cerr << output << flush;

View File

@ -46,9 +46,10 @@ namespace Moses2 {
UpdateLMPath(filePath);
m_system = new System(*m_param);
}
std::string Moses2Wrapper::Translate(const std::string &input , long id) {
std::string Moses2Wrapper::Translate(const std::string &input , long id, bool nbest) {
TranslationTask task(*m_system, input, id);
return task.ReturnTranslation();
return task.ReturnTranslation(nbest);
}
Moses2Wrapper::~Moses2Wrapper() {
delete m_param;

View File

@ -20,7 +20,7 @@ namespace Moses2 {
public:
Moses2Wrapper(const std::string& filePath);
~Moses2Wrapper();
std::string Translate(const std::string& input, long id);
std::string Translate(const std::string& input, long id, bool nbest);
void UpdateLMPath(const std::string& filePath);
static char* CopyString(const char* str);

View File

@ -39,7 +39,7 @@ System::System(const Parameter &paramsArg) :
const PARAM_VEC *section;
// output collectors
if (options.nbest.nbest_size) {
if (options.nbest.nbest_size && options.nbest.output_file_path != "-") {
nbestCollector.reset(new OutputCollector(options.nbest.output_file_path));
}

11
moses2/TranslationTask.cpp Normal file → Executable file
View File

@ -23,14 +23,21 @@ TranslationTask::TranslationTask(System &system,
TranslationTask::~TranslationTask()
{
}
std::string TranslationTask::ReturnTranslation() const
std::string TranslationTask::ReturnTranslation(bool nbest) const
{
m_mgr->Decode();
string out;
out = m_mgr->OutputBest() + "\n";
if (nbest) {
out = m_mgr->OutputNBest() + "\n";
}
else {
out = m_mgr->OutputBest() + "\n";
}
delete m_mgr;
return out;
}
void TranslationTask::Run()
{

2
moses2/TranslationTask.h Normal file → Executable file
View File

@ -16,7 +16,7 @@ public:
TranslationTask(System &system, const std::string &line, long translationId);
virtual ~TranslationTask();
virtual void Run();
virtual std::string ReturnTranslation() const;
virtual std::string ReturnTranslation(bool nbest) const;
protected:
ManagerBase *m_mgr;