27#define SAHLOGINIT LOGINIT("LP::SyntacticAnalysis::Hetero")
35namespace LinguisticProcessing {
36namespace SyntacticAnalysis {
48m_linkSubSentences(true),
49m_applySameRuleWhileSuccess(false)
55m_language(s.m_language),
56m_recognizer(s.m_recognizer),
58m_linkSubSentences(s.m_linkSubSentences),
59m_applySameRuleWhileSuccess(s.m_applySameRuleWhileSuccess)
97 LERROR <<
"no parameter 'rules' in SyntacticAnalyzerDepsHetero group for language "
101 std::map<std::string,std::string>& rulesMap=unitConfiguration.
getMapAtKey(
"subSentencesRules");
102 std::map<std::string,std::string>::const_iterator itm, itm_end;
103 itm = rulesMap.begin(); itm_end = rulesMap.end();
104 for (; itm != itm_end; itm++)
107 LINFO <<
"Loading subsentences recognizer " << (*itm).second <<
" for type " << (*itm).first;
117 LERROR <<
"no parameters map 'subSentencesRules' in SyntacticAnalyzerDepsHetero group for language "
124 if (unfold ==
"true")
m_unfold =
true;
130 LINFO <<
"no parameter 'unfold' in SyntacticAnalyzerDepsHetero group for language "
131 << (int)
m_language <<
" ; using default : true";
143 LINFO <<
"no parameter 'linkSubSentences' in SyntacticAnalyzerDepsHetero group for language "
144 << (int)
m_language <<
" ; using default : true";
150 if (val ==
"true" || val ==
"yes") {
167 LINFO <<
"start heterosyntagmatic dependence relations search";
169 auto posgraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph"));
172 LERROR <<
"no AnalysisGraph ! abort";
177 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
180 LERROR <<
"no sentence bounds ! abort";
183 if (sb->getGraphId() !=
"PosGraph") {
184 LERROR <<
"SentenceBounds have been computed on " << sb->getGraphId() <<
" !";
185 LERROR <<
"SyntacticAnalyzer-deps needs SentenceBounds on PosGraph";
189 auto simplificationData = std::dynamic_pointer_cast<SimplificationData>(analysis.
getData(
"SimplificationData"));
190 if (simplificationData==0)
192 simplificationData = std::make_shared<SimplificationData>(posgraph.get());
193 analysis.
setData(
"SimplificationData",simplificationData);
199 for (std::vector<Segment>::const_iterator boundItr=(sb->getSegments()).begin();
200 boundItr!=(sb->getSegments()).end();
206 LDEBUG <<
"analyze sentence from vertex " << beginSentence
207 <<
" to vertex " << endSentence;
210 std::vector<Automaton::RecognizerMatch> result;
231 auto subSentRIt = simplificationData->simplifications(beginSentence).rbegin();
232 auto subSentRIt_end = simplificationData->simplifications(beginSentence).rend();
233 for (; subSentRIt != subSentRIt_end; subSentRIt++)
238 boost::tie(first, last, subSentType) = *subSentRIt;
239 std::vector<Automaton::RecognizerMatch> subSentResult;
241 LDEBUG <<
"Hetero rules on a subsentence: " << boost::target(first,*graph) <<
" / " << boost::source(last,*graph);
245 boost::target(first,*graph),
246 boost::source(last,*graph),
259 LDEBUG <<
"Remove edge " << boost::source(first,*graph) <<
" -> " << boost::target(last,*graph);
261 boost::remove_edge(boost::source(first,*graph),
262 boost::target(last,*graph),
264 if (!boost::edge(boost::source(first,*graph),
265 boost::target(first,*graph),
269 LDEBUG <<
"Add edge " << boost::source(first,*graph) <<
" -> " << boost::target(first,*graph);
271 boost::add_edge(boost::source(first,*graph),
272 boost::target(first,*graph),
275 if (!boost::edge(boost::source(last,*graph),
276 boost::target(last,*graph),
280 LDEBUG <<
"Add edge " << boost::source(last,*graph) <<
" -> " << boost::target(last,*graph);
282 boost::add_edge(boost::source(last,*graph),
283 boost::target(last,*graph),
290 LWARN <<
"No recognizer for subsentence type " << subSentType;
295 LDEBUG <<
"Link subsentence to main one " << boost::target(first,*graph) <<
"/"
296 << boost::source(last,*graph) <<
"/" << beginSentence <<
"/"
300 subSentRecognizer->apply(*posgraph,
301 boost::target(first,*graph),
302 boost::source(last,*graph),
319 recopyCoordinationStrings(analysis);
328 LDEBUG <<
"SyntacticAnalyzerDepsHetero::recopyCoordinationStrings";
332 auto syntacticData = std::dynamic_pointer_cast<SyntacticData>(analysis.
getData(
"SyntacticData"));
333 if (syntacticData==0)
336 LERROR <<
"no syntacticData ! abort";
340 auto simplificationData = std::dynamic_pointer_cast<SimplificationData>(analysis.
getData(
"SimplificationData"));
341 if (simplificationData==0)
344 LERROR <<
"no simplificationData ! abort";
352 for (std::map< std::string, std::vector< LinguisticGraphVertex > >::const_iterator dit = simplificationData->coordStringsDefs().begin(); dit != simplificationData->coordStringsDefs().end(); dit++)
354 if (simplificationData->coordStrings().find((*dit).first) == simplificationData->coordStrings().end())
358 LDEBUG <<
"SyntacticAnalyzerDepsHetero::recopyCoordinationStrings no same string for definition " << (*dit).first;
362 const std::vector< LinguisticGraphVertex >& stringDef = (*dit).second;
363 const std::vector< std::vector< LinguisticGraphVertex > >& sameStrings = (*simplificationData->coordStrings().find((*dit).first)).second;
365 LDEBUG <<
"SyntacticAnalyzerDepsHetero::recopyCoordinationStrings there is " << sameStrings.size() <<
" same strings for " << (*dit).first;
368 for (std::vector< std::vector< LinguisticGraphVertex > >::const_iterator ssit = sameStrings.begin(); ssit != sameStrings.end(); ssit++)
370 const std::vector< LinguisticGraphVertex >& sameString = *ssit;
371 std::vector< LinguisticGraphVertex >::const_iterator stringDefIt = stringDef.begin();
372 std::vector< LinguisticGraphVertex >::const_iterator sameStringIt = sameString.begin();
374 for (; stringDefIt != stringDef.end(); stringDefIt++, sameStringIt++)
384 boost::tie(depIt, depIt_end) = out_edges(depStringDefVx, *depGraph);
385 for (; depIt != depIt_end; depIt++)
389 if (std::find(stringDef.begin(), stringDef.end(), depTargV) != stringDef.end())
continue;
391 std::pair< LinguisticGraphEdge, bool > sameStringEdge = boost::edge(depSameStringVx, depTargV, *depGraph);
392 if (!sameStringEdge.second)
395 LDEBUG <<
"SyntacticAnalyzerDepsHetero::recopyCoordinationStrings create edge " << depSameStringVx <<
" -("<<relationName<<
")-> " << depTargV;
397 std::pair<DependencyGraphEdge,bool> newSameStringEdge = boost::add_edge(depSameStringVx, depTargV, *depGraph);
398 if (newSameStringEdge.second)
400 relTypeMap[newSameStringEdge.first] = relTypeMap[*depIt];
406 boost::tie(depInIt, depInIt_end) = in_edges(depStringDefVx, *depGraph);
407 for (; depInIt != depInIt_end; depInIt++)
411 if (std::find(stringDef.begin(), stringDef.end(), depSrcV) != stringDef.end())
continue;
413 std::pair< LinguisticGraphEdge, bool > sameStringEdge = boost::edge(depSameStringVx, depSrcV, *depGraph);
414 if (!sameStringEdge.second)
416 std::pair<DependencyGraphEdge,bool> newSameStringEdge = boost::add_edge(depSameStringVx, depSrcV, *depGraph);
417 if (newSameStringEdge.second)
420 LDEBUG <<
"SyntacticAnalyzerDepsHetero::recopyCoordinationStrings create edge " << depSameStringVx <<
" <-("<<relationName<<
")- " << depSrcV;
422 relTypeMap[newSameStringEdge.first] = relTypeMap[*depInIt];
DependencyGraph::in_edge_iterator DependencyGraphInEdgeIt
DependencyGraph::out_edge_iterator DependencyGraphOutEdgeIt
boost::property_map< DependencyGraph, edge_deprel_type_t >::type EdgeDepRelTypePropertyMap
DependencyGraph::vertex_descriptor DependencyGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, DepVertexProperties, DepEdgeProperties > DependencyGraph
The dependency graph class.
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.
Defines a Factory to create Object of type Base.
Data used for the simplification of sentences allowing easier heterosyntagmatic analysis.
process unit to extract heterosyntagmatic dependency relations
#define SYNTACTICANALYZERDEPSHETERO_CLASSID
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.
std::string & getParamsValueAtKey(const std::string &key)
std::map< std::string, std::string > & getMapAtKey(const std::string &key)
return a message when a 'map' was not found
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
std::map< Common::MediaticData::SyntacticRelationId, std::shared_ptr< Automaton::Recognizer > > m_subSentRecognizers
SyntacticAnalyzerDepsHetero()
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.
SyntacticAnalyzerDepsHetero & operator=(const SyntacticAnalyzerDepsHetero &)
bool m_applySameRuleWhileSuccess
std::shared_ptr< Automaton::Recognizer > m_recognizer
virtual ~SyntacticAnalyzerDepsHetero()
static const LinguisticResources & single()
const singleton accessor
This file contains a class to control log of informations about time, such as logging cumulated time ...
SimpleFactory< MediaProcessUnit, SyntacticAnalyzerDepsHetero > syntacticAnalyzerDepsHeteroFactory(SYNTACTICANALYZERDEPSHETERO_CLASSID)