LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
recognizerData.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 *
8 * @file recognizerData.h
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Tue Jan 25 2005
11 * @version $Id$
12 * copyright Copyright (C) 2005-2012 by CEA LIST
13 * Project s2lp
14 *
15 * @brief this class contains data useful for recognizer application
16 *
17 *
18 ***********************************************************************/
19
20#ifndef RECOGNIZERDATA_H
21#define RECOGNIZERDATA_H
22
23#include "AutomatonExport.h"
27
28namespace Lima {
29namespace LinguisticProcessing {
30namespace ApplyRecognizer {
31
32#define APPRLOGINIT LOGINIT("LP::ApplyRecognizer")
33
34// class to store results of the application of the recognizer
36 public AnalysisData,
37 public std::vector<std::vector< Automaton::RecognizerMatch > >
38{
39 public:
40 RecognizerResultData(const std::string& sourceGraph);
43 RecognizerResultData& operator = (const RecognizerResultData&);
44
45 void insert(const Automaton::RecognizerMatch& m,
46 const uint64_t sentenceId=0);
47
48 inline const std::string& getGraphId() const { return m_graphId; }
49
50 private:
51 std::string m_graphId;
52};
53
54// class to store information used during the application of the
55// Recognizer (not used afterwards)
57{
58 public:
60 virtual ~RecognizerData();
61
62 // deal with removing vertices
63 // (when alternative create by the rules is the only one kept)
64 bool matchOnRemovedVertices(const Automaton::RecognizerMatch& result) const;
65 void storeVerticesToRemove(const Automaton::RecognizerMatch& result,
66 LinguisticGraph* graph);
67 void clearVerticesToRemove() { m_verticesToRemove.clear(); }
68 void removeVertices(AnalysisContent& analysis) const;
69
70 void setEdgeToBeRemoved(AnalysisContent& analysis, LinguisticGraphEdge e);
71 void clearEdgesToRemove() {m_edgesToRemove.clear();}
72 void removeEdges(AnalysisContent& analysis);
73 bool isEdgeToBeRemoved(LinguisticGraphVertex s, LinguisticGraphVertex t) const;
87 void clearUnreachableVertices(AnalysisContent& analysis,
90 std::set< std::pair<LinguisticGraphVertex, LinguisticGraphVertex > >& storedEdges
91 );
92 void clearUnreachableVertices(AnalysisContent& analysis,
94
95 void setResultData(RecognizerResultData* data);
96 void deleteResultData();
97 void addResult(const Automaton::RecognizerMatch& result);
98 void nextSentence();
99 bool hasStoredResults() const { return (! m_resultData->empty()); }
100
101 inline const std::string& getGraphId() const { return m_resultData->getGraphId(); }
102
103 inline const std::set< LinguisticGraphVertex >& getNextVertices() const { return m_nextVertices; }
104 inline std::set< LinguisticGraphVertex >& getNextVertices() { return m_nextVertices; }
105 inline void setNextVertex(LinguisticGraphVertex v) { m_nextVertices.insert(v); }
106
107 template<typename ValueType>
108 void setEntityFeature(const std::string& name, const ValueType& value)
109 {
110 // if feature already exists, overwrite it
111 // @todo : concat to existing feature
112 m_entityFeatures.setFeature<ValueType>(name,value);
113 }
114 template<typename ValueType>
115 void addEntityFeature(const std::string& name, const ValueType& value)
116 {
117 // add one feature at the end of existing ones
118 m_entityFeatures.addFeature<ValueType>(name,value);
119 }
120 template<typename ValueType>
121 void appendEntityFeature(const std::string& name, const ValueType& value)
122 {
123 // if feature already exists, overwrite it
124 // @todo : concat to existing feature
125 m_entityFeatures.appendFeature<ValueType>(name,value);
126 }
128 {
129 m_embededEntities.insert(vertex);
130 }
132 {
133 return (m_embededEntities.find(vertex) != m_embededEntities.end());
134 }
135 void clearEntityFeatures();
136 Automaton::EntityFeatures& getEntityFeatures() { return m_entityFeatures; }
137
138private:
139
141 RecognizerData& operator = (const RecognizerData&);
142
143 // dictionary code (needed to create alternative vertex (deal with
144 // linguistic properties)
145 std::set<LinguisticGraphVertex> m_verticesToRemove;
146 std::set< std::pair<LinguisticGraphVertex, LinguisticGraphVertex> > m_edgesToRemove;
147 RecognizerResultData* m_resultData;
148 uint64_t m_currentSentence;
149 std::set< LinguisticGraphVertex > m_nextVertices;
150
151 // EntityFeatures : for functions to add features
152 Automaton::EntityFeatures m_entityFeatures;
153 // embededEntities : set of embeded entities
154 std::set< LinguisticGraphVertex > m_embededEntities;
155};
156
157} // end namespace
158} // end namespace
159} // end namespace
160
161#endif
#define LIMA_AUTOMATON_EXPORT
boost::graph_traits< LinguisticGraph >::edge_descriptor LinguisticGraphEdge
typedefs to simplify the access to various graphs elements
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
just for semantics: base class for analysisData
void setEntityFeature(const std::string &name, const ValueType &value)
void addEntityFeature(const std::string &name, const ValueType &value)
std::set< LinguisticGraphVertex > & getNextVertices()
void appendEntityFeature(const std::string &name, const ValueType &value)
void addVertexAsEmbededEntity(const LinguisticGraphVertex &vertex)
const std::set< LinguisticGraphVertex > & getNextVertices() const
bool hasVertexAsEmbededEntity(const LinguisticGraphVertex &vertex) const
a list of generic features: each feature is unique (only one feature for a name)
SimpleFactory< MediaProcessUnit, ApplyRecognizer > ApplyRecognizer(APPLYRECOGNIZER_CLASSID)
NAUTITIA.