mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-05 15:58:03 +03:00
return nbest
This commit is contained in:
parent
b35ba85196
commit
c41bc4099e
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -39,7 +39,7 @@ System::System(const Parameter ¶msArg) :
|
||||
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
11
moses2/TranslationTask.cpp
Normal file → Executable 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
2
moses2/TranslationTask.h
Normal file → Executable 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;
|
||||
|
Loading…
Reference in New Issue
Block a user