diff options
author | James Zhang <jzhang331@bloomberg.net> | 2015-02-05 22:35:49 +0300 |
---|---|---|
committer | James Zhang <jzhang331@bloomberg.net> | 2015-02-05 22:43:45 +0300 |
commit | 8b61f396a7558bf628c2e94a9583023b9ae34a8c (patch) | |
tree | 2d2cafbe6a6f5b75fe04db26b8e8fd17bcaf4f88 /moses-cmd | |
parent | 70e8eb54ce75feb0a7d4ed00d275e56652c0a914 (diff) |
Simple structure change to make moses main() function available in libmoses.a
Diffstat (limited to 'moses-cmd')
-rw-r--r-- | moses-cmd/Main.cpp | 190 | ||||
-rw-r--r-- | moses-cmd/Main.h | 42 |
2 files changed, 4 insertions, 228 deletions
diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index f88f186b5..7de3206fd 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -20,195 +20,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ /** - * Moses main, for single-threaded and multi-threaded. + * Moses main wrapper for executable for single-threaded and multi-threaded, simply calling decoder_main. **/ -#include <exception> -#include <fstream> -#include <sstream> -#include <vector> - -#include "util/usage.hh" - -#ifdef WIN32 -// Include Visual Leak Detector -//#include <vld.h> -#endif - -#include "moses/IOWrapper.h" -#include "moses/Hypothesis.h" -#include "moses/Manager.h" -#include "moses/StaticData.h" -#include "moses/TypeDef.h" -#include "moses/Util.h" -#include "moses/Timer.h" -#include "moses/TranslationModel/PhraseDictionary.h" -#include "moses/FF/StatefulFeatureFunction.h" -#include "moses/FF/StatelessFeatureFunction.h" -#include "moses/TranslationTask.h" - -#ifdef HAVE_PROTOBUF -#include "hypergraph.pb.h" -#endif - -#ifdef PT_UG -#include <boost/foreach.hpp> -#include "moses/TranslationModel/UG/mmsapt.h" -#include "moses/TranslationModel/UG/generic/program_options/ug_splice_arglist.h" -#endif - -using namespace std; -using namespace Moses; - -namespace Moses -{ - -void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream) -{ - outputSearchGraphStream.setf(std::ios::fixed); - outputSearchGraphStream.precision(6); - StaticData::Instance().GetAllWeights().Save(outputSearchGraphStream); -} - - -} //namespace +#include "moses/ExportInterface.h" /** main function of the command line version of the decoder **/ int main(int argc, char** argv) { - try { - -#ifdef HAVE_PROTOBUF - GOOGLE_PROTOBUF_VERIFY_VERSION; -#endif - - // echo command line, if verbose - IFVERBOSE(1) { - TRACE_ERR("command: "); - for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" "); - TRACE_ERR(endl); - } - - // set number of significant decimals in output - FixPrecision(cout); - FixPrecision(cerr); - - // load all the settings into the Parameter class - // (stores them as strings, or array of strings) - Parameter params; - if (!params.LoadParam(argc,argv)) { - exit(1); - } - - - // initialize all "global" variables, which are stored in StaticData - // note: this also loads models such as the language model, etc. - if (!StaticData::LoadDataStatic(¶ms, argv[0])) { - exit(1); - } - - // setting "-show-weights" -> just dump out weights and exit - if (params.isParamSpecified("show-weights")) { - ShowWeights(); - exit(0); - } - - // shorthand for accessing information in StaticData - const StaticData& staticData = StaticData::Instance(); - - - //initialise random numbers - srand(time(NULL)); - - // set up read/writing class - IFVERBOSE(1) { - PrintUserTime("Created input-output object"); - } - - IOWrapper* ioWrapper = new IOWrapper(); - if (ioWrapper == NULL) { - cerr << "Error; Failed to create IO object" << endl; - exit(1); - } - - // check on weights - const ScoreComponentCollection& weights = staticData.GetAllWeights(); - IFVERBOSE(2) { - TRACE_ERR("The global weight vector looks like this: "); - TRACE_ERR(weights); - TRACE_ERR("\n"); - } - -#ifdef WITH_THREADS - ThreadPool pool(staticData.ThreadCount()); -#endif - - // main loop over set of input sentences - InputType* source = NULL; - size_t lineCount = staticData.GetStartTranslationId(); - while(ioWrapper->ReadInput(staticData.GetInputType(),source)) { - source->SetTranslationId(lineCount); - IFVERBOSE(1) { - ResetUserTime(); - } - - FeatureFunction::CallChangeSource(source); - - // set up task of translating one sentence - TranslationTask* task = new TranslationTask(source, *ioWrapper); - - // execute task -#ifdef WITH_THREADS -#ifdef PT_UG - bool spe = params.isParamSpecified("spe-src"); - if (spe) { - // simulated post-editing: always run single-threaded! - task->Run(); - delete task; - string src,trg,aln; - UTIL_THROW_IF2(!getline(*ioWrapper->spe_src,src), "[" << HERE << "] " - << "missing update data for simulated post-editing."); - UTIL_THROW_IF2(!getline(*ioWrapper->spe_trg,trg), "[" << HERE << "] " - << "missing update data for simulated post-editing."); - UTIL_THROW_IF2(!getline(*ioWrapper->spe_aln,aln), "[" << HERE << "] " - << "missing update data for simulated post-editing."); - BOOST_FOREACH (PhraseDictionary* pd, PhraseDictionary::GetColl()) { - Mmsapt* sapt = dynamic_cast<Mmsapt*>(pd); - if (sapt) sapt->add(src,trg,aln); - VERBOSE(1,"[" << HERE << " added src] " << src << endl); - VERBOSE(1,"[" << HERE << " added trg] " << trg << endl); - VERBOSE(1,"[" << HERE << " added aln] " << aln << endl); - } - } else -#endif - pool.Submit(task); -#else - task->Run(); - delete task; -#endif - - source = NULL; //make sure it doesn't get deleted - ++lineCount; - } - - // we are done, finishing up -#ifdef WITH_THREADS - pool.Stop(true); //flush remaining jobs -#endif - - delete ioWrapper; - FeatureFunction::Destroy(); - - } catch (const std::exception &e) { - std::cerr << "Exception: " << e.what() << std::endl; - return EXIT_FAILURE; - } - - IFVERBOSE(1) util::PrintUsage(std::cerr); - -#ifndef EXIT_RETURN - //This avoids that destructors are called (it can take a long time) - exit(EXIT_SUCCESS); -#else - return EXIT_SUCCESS; -#endif + return decoder_main(argc, argv); } + diff --git a/moses-cmd/Main.h b/moses-cmd/Main.h deleted file mode 100644 index 49fee0219..000000000 --- a/moses-cmd/Main.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -// $Id$ - -/*********************************************************************** -Moses - factored phrase-based language decoder -Copyright (c) 2006 University of Edinburgh -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the University of Edinburgh nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -***********************************************************************/ - -// example file on how to use moses library - - -#include "moses/StaticData.h" - -class IOWrapper; - -int main(int argc, char* argv[]); - |