14#include "common/misc/traceUtils.h"
21#include "linguisticProcessing/core/LinguisticAnalysisStructure/SentenceBounds.h"
33namespace LinguisticProcessing
36namespace SpecificEntities
42LinguisticProcessUnit(),
44m_useSentenceBounds(true),
45m_sentenceBoundsData(
"SentenceBounds"),
68 LERROR <<
"No param 'automaton' in SpecificEntitiesRecognizer group for language "
69 << (int)language <<
" !";
75 if (useDicoWords==
"yes" ||
76 useDicoWords==
"true" ||
91 if (useSentenceBounds==
"yes" ||
92 useSentenceBounds==
"true" ||
93 useSentenceBounds==
"1") {
94 m_useSentenceBounds=
true;
97 m_useSentenceBounds=
false;
108 if (! sentenceBoundsData.empty()) {
109 m_sentenceBoundsData=sentenceBoundsData;
124 LWARN <<
"No 'graph' parameter in unit configuration '"
125 << unitConfiguration.
getName() <<
"' ; using PosGraph";
126 m_graph=string(
"PosGraph");
136 LINFO <<
"start process";
138 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
139 if (annotationData==0)
142 if (std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph")) != 0)
144 std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"))->populateAnnotationGraph(annotationData,
"AnalysisGraph");
146 if (std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph")) != 0)
148 std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph"))->populateAnnotationGraph(annotationData,
"PosGraph");
151 analysis.
setData(
"AnnotationData",annotationData);
153 if (m_annotationData->dumpFunction(
"SpecificEntity") == 0)
164 AnalysisGraphId* gid(
new AnalysisGraphId(m_graph));
165 analysis.
setData(
"GraphId",gid);
181 std::set<LinguisticGraphVertex> verticesToRemove;
183 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_graph));
186 std::queue<LinguisticGraphVertex> toVisit;
188 std::set<LinguisticGraphVertex> visited;
192 toVisit.push(anagraph->firstVertex());
193 visited.insert(anagraph->firstVertex());
195 while (!toVisit.empty())
197 std::set<LinguisticGraphVertex> addedVertices;
201 Token* currentToken=tokenMap[currentVertex];
205 bool specificEntityFound(
false);
207 specificEntityFound= findSEFromRecognizer(currentVertex,
225 std::set<LinguisticGraphVertex>::const_iterator addedIt, addedIt_end;
226 addedIt = addedVertices.begin(); addedIt_end = addedVertices.end();
227 for (; addedIt != addedIt_end; addedIt++)
229 if (visited.find(*addedIt) == visited.end())
231 toVisit.push(*addedIt);
232 visited.insert(*addedIt);
238 boost::tie(adjItr,adjItrEnd) = adjacent_vertices(currentVertex,*graph);
239 for (;adjItr!=adjItrEnd;adjItr++)
241 if (addedVertices.find(*adjItr)==addedVertices.end() &&
242 visited.find(*adjItr)==visited.end())
244 toVisit.push(*adjItr);
245 visited.insert(*adjItr);
253 catch (std::exception &exc)
256 LWARN <<
"Exception in Specific Entities : " << exc.what();
271 LDEBUG <<
"SpecificEntitiesRecognizer::processOnEachSentence";
273 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_graph));
276 LERROR <<
"SpecificEntitiesRecognizer::processOnEachSentence: no graph '" << m_graph <<
"' available !!";
281 SentenceBounds* sb=
static_cast<SentenceBounds*
>(analysis.
getData(
"SentenceBounds"));
285 LERROR <<
"SpecificEntitiesRecognizer::processOnEachSentence: no sentence bounds defined ! abort";
288 if (sb->graphId() != m_graph) {
290 LERROR <<
"SpecificEntitiesRecognizer::processOnEachSentence: SentenceBounds are computed on graph '" << sb->graphId() <<
"'";
291 LERROR <<
"can't compute specificEntities on graph '" << m_graph <<
"' !";
296 std::vector< Automaton::RecognizerMatch > seRecognizerResult;
298 SentenceBounds::const_iterator boundItr=sb->begin();
299 while (boundItr!=sb->end())
304 seRecognizerResult.clear();
318 beginSentence=endSentence;
329 LDEBUG <<
"SpecificEntitiesRecognizer::processOnWholeText";
331 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_graph));
334 LERROR <<
"no graph '" << m_graph <<
"' available !!";
339 std::vector< Automaton::RecognizerMatch > seRecognizerResult;
341 m_recognizer->
apply(*anagraph,
342 anagraph->firstVertex(),
343 anagraph->lastVertex(),
375bool SpecificEntitiesRecognizer::findSEFromRecognizer(
382 LDEBUG <<
"SpecificEntitiesRecognizer::findSEFromRecognizer " << currentVertex;
385 std::vector<RecognizerMatch> result;
This file is the main header file for the data related to annotation graphs.
A graph structure for linguistic analysis.
boost::property_map< LinguisticGraph, vertex_token_t >::type VertexTokenPropertyMap
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
LinguisticGraph::adjacency_iterator LinguisticGraphAdjacencyIt
Defines a Factory to create Object of type Base.
#define SPECIFICENTITIESRECOGNIZER_CLASSID
Data used for the syntactic analyzis of texts.
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
void setData(const QString &id, std::shared_ptr< AnalysisData > data)
set an analysisData with the given id.
Holds an annotation graph and gives an API to manipulate it.
std::string & getParamsValueAtKey(const std::string &key)
return a message when a 'param' was not found
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
Use this exception to signal an error in one of the configuration files.
␈rief a class for the definition of a complete recognizer
uint64_t testOnVertex(const LinguisticAnalysisStructure::AnalysisGraph &graph, LinguisticGraphVertex ¤t, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, AnalysisContent &analysis, std::vector< RecognizerMatch > &result, bool stopAtFirstSuccess=true, bool onlyOneSuccessPerType=false, bool applySameRuleWhileSuccess=false) const
test the recognizer on a given vertex : check if this vertex is a trigger and if a rule applies,...
uint64_t apply(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, AnalysisContent &analysis, std::vector< RecognizerMatch > &result, bool testAllVertices=false, bool stopAtFirstSuccess=true, bool onlyOneSuccessPerType=false, bool returnAtFirstSuccess=false, bool applySameRuleWhileSuccess=false) const
apply the recognizer on a graph
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
holds surface data of a token
Definition of a function suitable to be used as a dumper for specific entities annotations of an anno...
LimaStatusCode process(AnalysisContent &analysis) const
Process on data in analysisContent.
virtual ~SpecificEntitiesRecognizer()
SpecificEntitiesRecognizer()
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager)
initialize with parameters from configuration file.
static const LinguisticResources & 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
SimpleFactory< LinguisticProcessUnit, SpecificEntitiesRecognizer > specificEntitiesRecognizer(SPECIFICENTITIESRECOGNIZER_CLASSID)
launch exception related to the configuration file parsing