73 LDEBUG <<
"Loading selectional preferences from " << fileName;
74 std::ifstream ifl(fileName.c_str(), std::ifstream::binary);
75 size_t linesCounter = 0;
80 LWARN <<
"Selectional preferences definition file not found: " << fileName;
87 while (ifl.good() && !ifl.eof())
89 if ( (line !=
"") && (line[0] !=
'#') )
91 LDEBUG <<
"read line : " << line;
95 size_t next = line.find_first_of(
";", index);
96 if (next == std::string::npos)
98 LERROR <<
"Cannot find first delimiter in line: " << line;
101 std::string target = line.substr(0, next);
104 next=line.find_first_of(
";",index);
105 if (next == std::string::npos)
107 LERROR <<
"Cannot find second delimiter in line: " << line;
113 next=line.find_first_of(
";",index);
114 if (next == std::string::npos)
116 LERROR <<
"Cannot find third delimiter in line: " << line;
119 std::string dependency = line.substr(index, next-index);
122 next=line.find_first_of(
";",index);
123 if (next == std::string::npos)
125 LERROR <<
"Cannot find fourth delimiter in line: " << line;
128 std::string source = line.substr(index, next-index);
131 next=line.find_first_of(
";",index);
132 if (next == std::string::npos)
134 LERROR <<
"Cannot find fifth delimiter in line: " << line;
140 double probability = 0.0;
141 std::string probabilityString = line.substr(index);
142 std::istringstream probabilityStringIss(probabilityString);
143 probabilityStringIss >> probability;
145 boost::tuple< std::string, LinguisticCode, std::string, std::string, LinguisticCode > tuple(target,targetMacro,dependency,source,soureceMacro);
146 m_preferences.insert(std::make_pair(tuple, probability));
157 boost::tuple< std::string, LinguisticCode, std::string, std::string, LinguisticCode > tuple = boost::make_tuple(target, targetCode, dependency, source, sourceCode);
158 std::map< boost::tuple< std::string, LinguisticCode, std::string, std::string, LinguisticCode >, double, compareTuple >::const_iterator preferencesIt = m_preferences.find(tuple);
159 if (preferencesIt == m_preferences.end())
163 LDEBUG <<
"Probability of (" << target <<
", " << targetCode <<
", " << dependency <<
", " << source <<
", " << sourceCode <<
") is " << (*preferencesIt).second;
164 return (*preferencesIt).second;
168 const boost::tuple< std::string, LinguisticCode, std::string, std::string, LinguisticCode >&
t1,
169 const boost::tuple< std::string, LinguisticCode, std::string, std::string, LinguisticCode >&
t2)
const