00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "LoaderFactory.h"
00021
00022 #include "moses/Util.h"
00023 #include "moses/InputFileStream.h"
00024 #include "LoaderCompact.h"
00025 #include "LoaderHiero.h"
00026 #include "LoaderStandard.h"
00027
00028 #include <sstream>
00029 #include <iostream>
00030
00031 using namespace std;
00032
00033 namespace Moses
00034 {
00035
00036
00037
00038 std::auto_ptr<RuleTableLoader>
00039 RuleTableLoaderFactory::
00040 Create(const std::string &path)
00041 {
00042 InputFileStream input(path);
00043 std::string line;
00044
00045 if (std::getline(input, line)) {
00046 std::vector<std::string> tokens;
00047 Tokenize(tokens, line);
00048 if (tokens.size() == 1) {
00049 if (tokens[0] == "1") {
00050 return std::auto_ptr<RuleTableLoader>(new RuleTableLoaderCompact());
00051 }
00052 std::cerr << "Unsupported compact rule table format: " << tokens[0];
00053 return std::auto_ptr<RuleTableLoader>();
00054 } else if (tokens[0] == "[X]" && tokens[1] == "|||") {
00055 return std::auto_ptr<RuleTableLoader>(new RuleTableLoaderHiero());
00056 }
00057
00058 return std::auto_ptr<RuleTableLoader>(new RuleTableLoaderStandard());
00059 } else {
00060
00061 return std::auto_ptr<RuleTableLoader>(new RuleTableLoaderStandard());
00062 }
00063 }
00064
00065 }