28using namespace boost::tuples;
30typedef boost::color_traits<boost::default_color_type>
Color;
43namespace LinguisticProcessing
59 delete m_bowGenerator;
69 m_bowGenerator->
init(unitConfiguration, m_language);
77 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.
getData(
"LinguisticMetaData"));
81 LERROR <<
"no LinguisticMetaData ! abort";
85 std::ofstream outputStream;
86 if (!
openLogFile(outputStream,metadata->getMetaData(
"FileName"))) {
88 LERROR <<
"Error: cannot open log file";
93 auto syntacticData = std::dynamic_pointer_cast<const SyntacticData>(analysis.
getData(
"SyntacticData"));
96 LERROR <<
"no SyntacticData ! abort";
100 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"));
103 LERROR <<
"no AnalysisGraph ! abort";
106 auto posgraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph"));
109 LERROR <<
"no PosGraph ! abort";
112 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
115 LERROR <<
"no SentenceBounds ! abort";
118 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
119 if (annotationData==0)
121 LERROR <<
"no annotation graph available !";
125 std::set< std::pair<size_t, size_t> > alreadyDumped;
127 outputStream <<
"<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
128 outputStream <<
"<compounds_dump>" << std::endl;
133 std::vector<Segment>::iterator sbItr=(sb->getSegments()).begin();
135 uint64_t sentNum = 1;
137 while (sbItr!=(sb->getSegments()).end())
142 dumpLimaData(outputStream,
149 annotationData.get());
155 outputStream <<
"</compounds_dump>" << std::endl;
156 outputStream.close();
165void CompoundsXmlLogger::dumpLimaData(
174 const uint64_t offsetBegin)
const
180 os <<
"<sentence num=\"" << sentNum <<
"\" >" << std::endl;
182 os <<
"<compounds>" << std::endl;
188 std::set< std::string > alreadyStored;
189 std::set<LinguisticGraphVertex> visited;
190 std::queue<LinguisticGraphVertex> toVisit;
194 while (!toVisit.empty())
202 for (boost::tie(outItr,outItrEnd)=out_edges(v,lposgraph);
207 if (visited.find(next)==visited.end())
209 visited.insert(next);
214 if (v != firstVx && v != lastVx)
220 std::set< AnnotationGraphVertex > cpdsHeads = annotationData->
matches(
"PosGraph", v,
"cpdHead");
221 if (!cpdsHeads.empty())
223 std::set< AnnotationGraphVertex >::const_iterator cpdsHeadsIt, cpdsHeadsIt_end;
224 cpdsHeadsIt = cpdsHeads.begin(); cpdsHeadsIt_end = cpdsHeads.end();
225 for (; cpdsHeadsIt != cpdsHeadsIt_end; cpdsHeadsIt++)
228 std::vector<std::pair< boost::shared_ptr< BoWRelation >, boost::shared_ptr< BoWToken > > > bowTokens =
229 m_bowGenerator->
buildTermFor(agv, agv, lanagraph, lposgraph, offsetBegin,
230 syntacticData, annotationData, visited);
231 for (
auto bowItr=bowTokens.begin();
232 bowItr!=bowTokens.end();
235 std::string elem = (*bowItr).second->getIdUTF8String();
236 if (alreadyStored.find(elem) != alreadyStored.end())
242 outputCompound(os,&*(*bowItr).second,offsetBegin);
243 alreadyStored.insert(elem);
250 os <<
"</compounds>" << std::endl;
251 os <<
"</sentence>" << std::endl;
259uint64_t CompoundsXmlLogger::getPosition(
const uint64_t position,
260 const uint64_t offsetBegin)
const
262 return (offsetBegin+position);
266void CompoundsXmlLogger::outputCompound(
269 const uint64_t offsetBegin)
const
272 LDEBUG <<
"Outputing compound: " << compound;
273 auto pos = getPosition(compound->
getPosition(),offsetBegin);
277 os <<
"<compound pos=\"" << pos <<
"\" form=\"" << form.toStdString()
278 <<
"\" cat=\"" << cat <<
"\" >" << std::endl;
283 auto partIt = term->getParts().cbegin();
284 auto partIt_end = term->getParts().cend();
285 for (
auto partId = uint64_t(0); partIt != partIt_end; partIt++, partId++)
287 boost::shared_ptr< BoWToken > partTok = (*partIt).get<1>();
289 os <<
"<part head=\"" << std::boolalpha << (partId == headId) <<
"\" >" << std::endl;
290 if (boost::dynamic_pointer_cast<BoWComplexToken>(partTok))
292 outputCompound(os, &*partTok, offsetBegin);
296 LDEBUG <<
" part: " << *partTok;
297 uint64_t partPos = getPosition(partTok->getPosition(),offsetBegin);
300 os <<
"<word pos=\"" << partPos <<
"\" form=\""
301 << partForm.toStdString()
302 <<
"\" cat=\"" << partCat <<
"\" />" << std::endl;
304 os <<
"</part>" << std::endl;
307 os <<
"</compound>" << std::endl;
This file is the main header file for the data related to annotation graphs.
#define COMPOUNDSXMLLOGGER_CLASSID
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.
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
Holds an annotation graph and gives an API to manipulate it.
std::set< AnnotationGraphVertex > matches(const std::string &first, AnnotationGraphVertex firstVx, const std::string &second) const
Gets the set of vertices matched in the second graph by the given vertex of the first graph.
This is a complex token for an index.
uint64_t getHead() const
add a part in the list of parts of the complex token.
This class contains the representation of an element of the bag of words.
LinguisticCode getCategory(void) const
uint64_t getPosition(void) const override
virtual Lima::LimaString getLemma(void) const
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
A generic process unit to log information in files: contains some common informations such as : outpu...
bool openLogFile(std::ofstream &output, const std::string &sourceFile) const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
Parameters retrived in the configuration file:
std::vector< std::pair< boost::shared_ptr< Common::BagOfWords::BoWRelation >, boost::shared_ptr< Common::BagOfWords::BoWToken > > > buildTermFor(const AnnotationGraphVertex &vx, const AnnotationGraphVertex &tgt, const LinguisticGraph &anagraph, const LinguisticGraph &posgraph, const uint64_t offset, const SyntacticAnalysis::SyntacticData *syntacticData, const Common::AnnotationGraphs::AnnotationData *annotationData, std::set< LinguisticGraphVertex > &visited) const
Creates the terms reachable from the given annotation vertex.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, MediaId language)
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual ~CompoundsXmlLogger()
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.
This class points to a graph, its dependency graph and the structure that holds the maping between th...
static const MediaticData & single()
const singleton accessor
This file contains a class to control log of informations about time, such as logging cumulated time ...
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
boost::color_traits< boost::default_color_type > Color
SimpleFactory< MediaProcessUnit, CompoundsXmlLogger > compoundsXmlLoggerFactory(COMPOUNDSXMLLOGGER_CLASSID)