00001 #include <set>
00002 #include "moses/PP/TargetConstituentBoundariesLeftPhraseProperty.h"
00003 #include "moses/FactorCollection.h"
00004 #include "moses/Util.h"
00005 #include <iostream>
00006 #include <queue>
00007 #include <ostream>
00008
00009 namespace Moses
00010 {
00011
00012 void TargetConstituentBoundariesLeftPhraseProperty::ProcessValue(const std::string &value)
00013 {
00014 FactorCollection &factorCollection = FactorCollection::Instance();
00015 std::vector<std::string> tokens;
00016 Tokenize(tokens, value, " ");
00017 std::vector<std::string>::const_iterator tokenIter = tokens.begin();
00018 while (tokenIter != tokens.end()) {
00019 try {
00020
00021 std::vector<std::string> constituents;
00022 Tokenize(constituents, *tokenIter, "<");
00023 ++tokenIter;
00024 float count = std::atof( tokenIter->c_str() );
00025 ++tokenIter;
00026
00027 std::set<const Factor* > dedup;
00028
00029 for ( std::vector<std::string>::iterator constituentIter = constituents.begin();
00030 constituentIter != constituents.end(); ++constituentIter ) {
00031
00032 const Factor* constituentFactor = factorCollection.AddFactor(*constituentIter,false);
00033
00034 std::pair< std::set<const Factor* >::iterator, bool > dedupIns =
00035 dedup.insert(constituentFactor);
00036 if ( dedupIns.second ) {
00037
00038 std::pair< TargetConstituentBoundariesLeftCollection::iterator, bool > inserted =
00039 m_constituentsCollection.insert(std::make_pair(constituentFactor,count));
00040 if ( !inserted.second ) {
00041 (inserted.first)->second += count;
00042 }
00043 }
00044 }
00045
00046 } catch (const std::exception &e) {
00047 UTIL_THROW2("TargetConstituentBoundariesLeftPhraseProperty: Read error. Flawed property? " << value);
00048 }
00049 }
00050 };
00051
00052 void TargetConstituentBoundariesLeftPhraseProperty::Print(std::ostream& out) const
00053 {
00054 for ( TargetConstituentBoundariesLeftCollection::const_iterator it = m_constituentsCollection.begin();
00055 it != m_constituentsCollection.end(); ++it ) {
00056 if ( it != m_constituentsCollection.begin() ) {
00057 out << " ";
00058 }
00059 out << *(it->first) << " " << it->second;
00060 }
00061 }
00062
00063 }
00064