LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
ViterbiPosTagger.h
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004-2012 by CEA LIST *
8 * *
9 ***************************************************************************/
10#ifndef LIMA_LINGUISTICPROCESSING_POSTAGGER_VITERBIPOSTAGGER_H
11#define LIMA_LINGUISTICPROCESSING_POSTAGGER_VITERBIPOSTAGGER_H
12
13#include "PosTaggerExport.h"
14#include "viterbiUtils.h"
15#include "frequencyCost.h"
16
21
28
29#include <list>
30#include <vector>
31#include <set>
32#include <map>
33#include <queue>
34
35#include <sstream>
36
37namespace Lima
38{
39
40namespace LinguisticProcessing
41{
42
43namespace PosTagger
44{
45
46#define VITERBIPOSTAGGER_CLASSID "ViterbiPosTagger"
47
51template<typename Cost,typename CostFunction>
53{
54public:
55 ViterbiPosTagger(const CostFunction& costFunction) :
56 m_costFunction(costFunction),
57 m_defaultCateg(),
58 m_stopCategories(),
59 m_microAccessor() {}
60
61 virtual ~ViterbiPosTagger() {}
62
76 void init(
78 Manager* manager) override;
79
80 LimaStatusCode process(AnalysisContent& analysis) const override;
81
82private:
83
84 struct PredData
85 {
86 PredData() :
87 m_cost(),
88 m_predMicro(),
89 m_predIndex(),
90 m_predPredMicros() {}
91 Cost m_cost;
92 LinguisticCode m_predMicro;
93 uint64_t m_predIndex;
94 std::vector<LinguisticCode> m_predPredMicros;
95 // this is used to insert PredData in ordered containers
96 inline bool operator<(const PredData& pd) const { return m_predMicro<pd.m_predMicro; }
97 };
98
99 typedef std::map< LinguisticCode, std::vector<PredData> > MicroCatDataMap;
100 typedef typename std::map< LinguisticCode, std::vector<PredData> >::iterator MicroCatDataMapItr;
101 typedef typename std::vector<PredData>::iterator PredDataVectorItr;
102 typedef typename std::vector<PredData>::const_iterator PredDataVectorCItr;
103
104 struct StepData
105 {
106 LinguisticGraphVertex m_srcVertex; // associated vertex in the graph
107 std::vector<uint64_t> m_predStepIndexes; // direct ancestors in the StepData vector
108 MicroCatDataMap m_microCatsData; // the micro categories associated to the node
109 };
110
111 typedef std::vector<StepData> StepDataVector;
112 typedef typename std::vector<StepData>::iterator StepDataVectorItr;
113
114 struct TargetVertexId
115 {
116 LinguisticGraphVertex m_sourceVx;
117 LinguisticCode m_categ;
118 std::vector<LinguisticCode> m_preds;
119 bool operator<(const TargetVertexId& tvi) const
120 {
121 if (m_sourceVx!=tvi.m_sourceVx) return m_sourceVx<tvi.m_sourceVx;
122 if (m_categ!=tvi.m_categ) return m_categ<tvi.m_categ;
123 return m_preds<tvi.m_preds;
124 }
125 };
126
127 const CostFunction m_costFunction;
128 LinguisticCode m_defaultCateg;
129 std::list<LinguisticCode> m_stopCategories;
130 const Common::PropertyCode::PropertyAccessor* m_microAccessor;
131 MediaId m_language;
132
151 void initializeStepDataFromGraph(
152 const LinguisticGraph* srcgraph,
154 LinguisticCode startMicro,
155 const std::list< LinguisticCode >& predCats,
157 StepDataVector& stepData) const;
158
159 void performViterbiOnStepData(StepDataVector& stepData) const;
160
169 LinguisticGraphVertex reportPathsInGraph(
170 LinguisticGraph* srcgraph,
171 LinguisticGraph* resultgraph,
172 LinguisticGraphVertex startVertex,
173 StepDataVector& stepData,
174 Common::AnnotationGraphs::AnnotationData* annotationData) const;
175
176};
177
179{
180public:
181
182 virtual std::shared_ptr<MediaProcessUnit> create(
184 MediaProcessUnit::Manager* manager) const override ;
185
186private:
187 ViterbiPosTaggerFactory(const std::string& id);
188 static std::unique_ptr< ViterbiPosTaggerFactory > s_instance;
189
190};
191
192
193}
194
195}
196
197}
198
199#include "ViterbiPosTagger.tcc"
200
201#endif
This file is the main header file for the data related to annotation graphs.
A graph structure for linguistic analysis.
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
#define LIMA_POSTAGGER_EXPORT
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
Defines Factory for an Initializable Object.
Manage initialization of InitializableObjects using configuration module and parameters.
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
bool operator<(const LinguisticCode &lhs, const LinguisticCode &rhs)
Definition StdBitset.h:289
launch exception related to the configuration file parsing