30namespace LinguisticProcessing
49 m_language=manager->getInitializationParameters().media;
56 m_trigramMatrix = std::dynamic_pointer_cast<TrigramMatrix>(res);
60 LERROR <<
"No param 'trigramMatrix' in GreedyPosTagger group for language " << (int)m_language;
68 m_bigramMatrix = std::dynamic_pointer_cast<BigramMatrix>(res);
72 LWARN <<
"No param 'bigramMatrix' in GreedyPosTagger group for language " << (int)m_language;
83 LWARN <<
"No ponctuforte microcateg category for GreedyPosTagger ! use category PONCTU_FORTE";
95 LINFO <<
"start greedy posTagging";
97 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"));
99 auto posgraph = std::make_shared<AnalysisGraph>(
"PosGraph", m_language,
false,
true, *anagraph);
103 auto graph = posgraph->getGraph();
106 map<LinguisticGraphVertex,uint64_t> processed;
107 set<LinguisticGraphVertex> toProcess;
108 toProcess.insert(anagraph->firstVertex());
109 set<LinguisticGraphVertex> nextToProcess;
110 set<LinguisticGraphVertex>::iterator toProcessItr;
111 map<LinguisticGraphVertex,uint64_t>::iterator processedItr;
115 while (toProcess.size()!=0)
122 for (toProcessItr=toProcess.begin();
123 toProcessItr!=toProcess.end();
128 processVertex(*toProcessItr, anagraph.get());
129 processed.insert(make_pair(*toProcessItr,out_degree(*toProcessItr,*graph)));
133 boost::tie(inItr,inItrEnd)=in_edges(*toProcessItr,*graph);
134 for (;inItr!=inItrEnd;inItr++)
136 processedItr=processed.find(source(*inItr,*graph));
137 processedItr->second--;
139 if (processedItr->second==0)
142 processed.erase(processedItr);
147 boost::tie(outItr,outItrEnd)=out_edges(*toProcessItr,*graph);
148 for (;outItr!=outItrEnd;outItr++)
156 boost::tie(inItr,inItrEnd)=in_edges(next,*graph);
158 for (;inItr!=inItrEnd;inItr++)
160 if (processed.find(source(*inItr,*graph))==processed.end())
168 nextToProcess.insert(next);
175 toProcess.swap(nextToProcess);
190 if (vx==startVx || vx==endVx)
198 LERROR <<
"MorphoSyntacticData of vertex " << vx <<
" is NULL !";
201 LDEBUG <<
"process vertex : " << vx <<
" : "
207 set<LinguisticCode> micros=posdata->
allValues(*m_microAccessor);
211 if (micros.size()==0)
215 <<
" has no possible dicowords ! build a DicoWord with category 0";
218 else if (micros.size()==1)
221 selectedMicro=*(micros.begin());
222 LDEBUG <<
"GreedyPosTagging : only one choice : " << selectedMicro;
227 set<LinguisticCode>::iterator dwItr,dwMaxTri,dwMaxBi;
233 boost::tie(inItr,inItrEnd)=in_edges(vx,*graph);
234 for (;inItr!=inItrEnd;inItr++)
238 if (predVx==startVx && m2!=0 && !m2->empty())
240 cat2=m_microCatPonctuForte;
245 cat2=m_microAccessor->
readValue(m2->begin()->properties);
248 boost::tie(inItr2,inItr2End)=in_edges(vx,*graph);
249 for (;inItr2!=inItr2End;inItr2++)
253 if (predpredVx==startVx && m1!=0 && !m1->empty())
255 cat1=m_microCatPonctuForte;
259 cat1=m_microAccessor->
readValue(m1->begin()->properties);
262 for (dwItr=micros.begin();dwItr!=micros.end();dwItr++)
264 float p=m_trigramMatrix->freq(cat1,cat2,*dwItr);
276 for (dwItr=micros.begin();dwItr!=micros.end();dwItr++)
278 float p=m_bigramMatrix->freq(cat1,*dwItr);
294 LDEBUG <<
"found trigram : choose " << *dwMaxTri <<
" (p=" << maxTri <<
")";
295 selectedMicro=*dwMaxTri;
300 LDEBUG <<
"found bigram : choose " << *dwMaxBi <<
" (p=" << maxBi <<
")";
301 selectedMicro=*dwMaxBi;
307 LWARN <<
"Found no trigram nor bigram (" << cat1 <<
"," << cat2 <<
") ! try heuristics to find a microcategory";
308 for (dwItr=micros.begin();dwItr!=micros.end();dwItr++)
310 float p=m_bigramMatrix->freq(m_microCatPonctuForte,*dwItr);
319 LDEBUG <<
"found bigram with ponctu forte : choose " << *dwMaxBi <<
" (p=" << maxBi <<
")";
320 selectedMicro=*dwMaxBi;
324 selectedMicro=*(micros.begin());
325 LDEBUG <<
"choose first : " << selectedMicro;
332 posdata->erase(remove_if(posdata->begin(), posdata->end(), cdpp),
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
LinguisticGraph::out_edge_iterator LinguisticGraphOutEdgeIt
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
Defines a Factory to create Object of type Base.
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
LinguisticCode readValue(const LinguisticCode &code) const
read a property in a coded int.
std::string & getParamsValueAtKey(const std::string &key)
return a message when a 'param' was not found
Use this exception to signal an error in one of the configuration files.
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
Holds morphosyntactic informations.
std::set< LinguisticCode > allValues(const Common::PropertyCode::PropertyAccessor &propertyAccessor) const
holds surface data of a token
const LimaString & stringForm() const
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
static const MediaticData & single()
const singleton accessor
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
Declaration of a PosTagger with a simple greedy algorithm.
#define GREEDYPOSTAGGER_CLASSID
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
SimpleFactory< MediaProcessUnit, GreedyPosTagger > greedyPosTaggerFactory(GREEDYPOSTAGGER_CLASSID)