34namespace LinguisticProcessing {
35namespace AnalysisDumpers {
36namespace EasyXmlDumper {
40 const std::map<std::string,std::string>& relationTypeMapping,
41 const std::map<std::string,std::string>& srcVxTag,
42 const std::map<std::string,std::string>& tgtVxTag,
43 const std::string& enonceId) :
45 m_relationTypeMapping(relationTypeMapping),
48 m_chaines(care.getChaines()),
49 m_vertexToFormeIds(care.getVertexToFormeIds()),
50 m_formesIndex(care.getFormesIndex()),
51 m_relations(care.getRelations()),
52 m_inRelations(care.getInRelations()),
53 m_groupes(care.getGroupes()),
54 m_positionsFormsIds(care.positionsFormsIds()),
55 m_inGroupFormsPositions(care.inGroupFormsPositions())
57 std::map<uint64_t, Groupe>::iterator it, it_end;
58 it = m_groupes.begin(); it_end = m_groupes.end();
59 for (; it != it_end; it++)
61 Groupe& group = (*it).second;
62 Groupe::iterator git, git_end;
63 git = group.begin(); git_end = group.end();
64 for (; git != git_end; git++)
67 LDEBUG <<
"EasyDumper:: setting " << group.
id() <<
" as group of " << git->second;
68 m_formesIdsGroupsIds[git->second]=&group;
76 for (std::vector<Relation*>::iterator it = m_relations.begin(); it != m_relations.end(); it++)
86 dumpConstituants(out);
90void EasyDumper::dumpConstituants(std::ostream& out)
92 std::map< uint64_t, uint64_t >::const_iterator posIt, posIt_end;
93 posIt = m_positionsFormsIds.begin();
94 posIt_end = m_positionsFormsIds.end();
97 std::set< uint64_t > alreadyDumpedForms;
98 for (; posIt != posIt_end; posIt++)
100 uint64_t position = (*posIt).first;
101 uint64_t forme = (*posIt).second;
103 if (m_formesIndex[forme] == 0)
105 LWARN <<
"EasyDumper:: form not found " << forme;
108 if (alreadyDumpedForms.find(position) != alreadyDumpedForms.end())
110 LDEBUG <<
"EasyDumper:: already dumped " << m_formesIndex[forme]->forme;
113 LDEBUG <<
"EasyDumper:: dump " << m_formesIndex[forme]->forme;
114 if (m_inGroupFormsPositions.find(position) == m_inGroupFormsPositions.end())
118 while (sforme.find(
'_') != std::string::npos)
120 LDEBUG <<
"EasyDumper:: remove _ in " << sforme;
121 sforme[sforme.find(
'_')] =
' ';
124 std::ostringstream oss;
125 oss << m_enonceId <<
"F"<< formId;
126 out <<
" <F id=\"" << oss.str() <<
"\">" << sforme <<
"</F>" << std::endl;
127 LDEBUG <<
"EasyDumper:: adding to m_formesIds1: "<<m_formesIndex[forme]->forme<<
" -> " << oss.str();
128 m_formesIds.insert(std::make_pair(forme, oss.str()));
129 alreadyDumpedForms.insert((m_formesIndex[forme])->poslong.position);
134 std::ostringstream sout;
135 if (m_groupes.find(position) == m_groupes.end())
139 Groupe& groupe = m_groupes[position];
140 Groupe::const_iterator groupeIt, groupeIt_end;
141 groupeIt = groupe.begin(); groupeIt_end = groupe.end();
143 std::ostringstream oss;
144 oss << m_enonceId <<
"G" << groupId;
146 sout <<
" <Groupe type=\"" << groupe.type() <<
"\" id=\"" << oss.str() <<
"\">" << std::endl;
147 m_groupeIdGroupStr[groupe.id()] = oss.str();
149 groupeIt = groupe.begin(); groupeIt_end = groupe.end();
151 for (; groupeIt != groupeIt_end; groupeIt++)
153 std::ostringstream oss;
154 oss << m_enonceId <<
"F" << formId;
157 while (sforme.find(
'_') != std::string::npos)
159 LDEBUG <<
"EasyDumper:: remove _ in " << sforme;
160 sforme[sforme.find(
'_')] =
' ';
162 sout <<
" <F id=\"" << oss.str() <<
"\">" << sforme <<
"</F>" << std::endl;
163 m_formesIds.insert(std::make_pair((*groupeIt).second, oss.str()));
164 if (m_formesIndex.find((*groupeIt).second) != m_formesIndex.end())
166 alreadyDumpedForms.insert((m_formesIndex[(*groupeIt).second])->poslong.position);
170 LERROR <<
"Error at " << __FILE__ <<
", line " << __LINE__;
174 sout <<
" </Groupe>" << std::endl;
176 LDEBUG <<
"EasyDumper:: " << sout.str();
184void EasyDumper::dumpRelations(std::ostream& out)
188 if (m_relations.empty())
192 out <<
" <relations>" << std::endl;
194 bool notClosed(
false);
195 std::string previousRelType(
""), previousSrcId(
"");
196 std::string relType(
"");
197 for (std::vector<Relation*>::const_iterator it=m_relations.begin();
198 it!=m_relations.end();
202 relType=m_relationTypeMapping[(*it)->type];
204 LDEBUG <<
"EasyDumper:: relation '"<<relType<<
"'";
205 if (relType==
"")
continue;
208 std::string complement;
210 std::string::size_type i=relType.find(
",");
211 if (i!=std::string::npos)
213 complement=std::string(relType,i+1);
217 std::string::size_type j;
218 while ((i=complement.find(
"=",i)) != std::string::npos
219 && complement[i+1] !=
'"')
221 complement.insert(i+1,
"\"");
222 j=complement.find(
" ",i+1);
223 if (j == std::string::npos)
225 complement.insert(complement.end(),
'"');
230 complement.insert(j,
"\"");
236 std::ostringstream oss;
237 oss << m_enonceId <<
"R" << numRel++;
238 m_relationsIds[*it]=oss.str();
240 std::string srcFormeId=m_formesIds[m_vertexToFormeIds[(*it)->srcVertex]];
241 if (srcFormeId ==
"")
243 LWARN <<
"EasyDumper:: Warning: empty source form id in " << m_enonceId <<
" for vertex " << (*it)->srcVertex;
244 srcFormeId = m_enonceId +
"F0";
246 std::string tgtFormeId=m_formesIds[m_vertexToFormeIds[(*it)->tgtVertex]];
247 if (tgtFormeId ==
"")
249 LWARN <<
"EasyDumper:: Warning: empty target form id in " << m_enonceId <<
" for vertex " << (*it)->tgtVertex;
250 tgtFormeId = m_enonceId +
"F0";
254 std::string tgtVxTag=m_tgtVxTag[relType];
255 LDEBUG <<
"EasyDumper:: tgtVxTag=" << tgtVxTag;
256 std::string::size_type k=tgtVxTag.find(
",");
257 if (k!=std::string::npos)
259 LDEBUG <<
"EasyDumper:: 3-ary relation";
262 LDEBUG <<
"EasyDumper:: first part: " << tgtVxTag;
264 previousRelType=relType;
265 previousSrcId=srcFormeId;
271 tgtVxTag.erase(0,k+1);
272 LDEBUG <<
"EasyDumper:: second part: " << tgtVxTag <<
" ; " << relType <<
"/" << previousRelType <<
" ; " << srcFormeId <<
"/" << previousSrcId <<
"/" << tgtFormeId;
273 if (relType==previousRelType && tgtFormeId==previousSrcId)
275 std::string href = m_enonceId + srcFormeId;
276 if (href == m_enonceId)
280 out <<
" <" << tgtVxTag <<
" xlink:type=\"locator\" xlink:href=\"" << href <<
"\"/>" << std::endl;
281 out <<
" </relation>" << std::endl;
286 std::string href = m_enonceId +
"F0";
287 out <<
" <" << tgtVxTag <<
" xlink:type=\"locator\" xlink:href=\""<<href<<
"\"/>" << std::endl;
288 LWARN <<
"EasyDumper:: Warning: relation " << previousRelType <<
" not continued";
289 out <<
" </relation>" << std::endl;
298 LWARN <<
"EasyDumper:: Warning: non 3-ary relation marked as not closed for relation " << previousRelType;
299 if (relType ==
"COORD")
301 std::string href = m_enonceId +
"F0";
302 out <<
" <coord-d xlink:type=\"locator\" xlink:href=\""<<href<<
"\"/>" << std::endl;
304 out <<
" </relation>" << std::endl;
309 bool coordgOutputed =
false;
310 bool coorddOutputed =
false;
311 out <<
" <relation xlink:type=\"extended\" type=\"" << relType <<
"\" id=\"" << oss.str() <<
"\">" << std::endl;
313 if (relType ==
"JUXT")
315 if (tgtVxTag ==
"coord-g") coordgOutputed =
true;
316 if (tgtVxTag ==
"coord-d") coorddOutputed =
true;
317 if (m_srcVxTag[relType] ==
"coord-g") coordgOutputed =
true;
318 if (m_srcVxTag[relType] ==
"coord-d") coorddOutputed =
true;
319 out <<
" <" << tgtVxTag <<
" xlink:type=\"locator\" xlink:href=\"" << tgtFormeId <<
"\"/>" << std::endl;
320 out <<
" <" << m_srcVxTag[relType] <<
" xlink:type=\"locator\" xlink:href=\"" << srcFormeId <<
"\"/>" << std::endl;
338 if (m_srcVxTag[relType] ==
"coord-g") coordgOutputed =
true;
339 if (m_srcVxTag[relType] ==
"coord-d") coorddOutputed =
true;
340 out <<
" <" << m_srcVxTag[relType] <<
" xlink:type=\"locator\" xlink:href=\"" << srcFormeId <<
"\"/>" << std::endl;
342 if (tgtVxTag ==
"coord-g") coordgOutputed =
true;
343 if (tgtVxTag ==
"coord-d") coorddOutputed =
true;
344 out <<
" <" << tgtVxTag <<
" xlink:type=\"locator\" xlink:href=\"" << tgtFormeId <<
"\"/>" << std::endl;
346 if ((*it)->secondaryVertex != 0)
348 std::string href = m_formesIds[m_vertexToFormeIds[(*it)->secondaryVertex]];
351 LWARN <<
"EasyDumper:: Warning: form id not found for " << (*it)->secondaryVertex;
352 href = m_enonceId +
"F0";
354 coorddOutputed =
true;
355 out <<
" <coord-d xlink:type=\"locator\" xlink:href=\"" << href <<
"\"/>" << std::endl;
357 if (coordgOutputed && !coorddOutputed)
359 std::string href = m_enonceId +
"F0";
360 out <<
" <coord-d xlink:type=\"locator\" xlink:href=\"" << href <<
"\"/>" << std::endl;
361 coorddOutputed =
true;
364 if (! complement.empty())
366 out <<
" <" << complement <<
"/>" << std::endl;
371 out <<
" </relation>" << std::endl;
378 LWARN <<
"EasyDumper:: Warning: relation " << relType <<
" not continued";
379 out <<
" </relation>" << std::endl;
382 out <<
" </relations>" << std::endl;
386void EasyDumper::computeFormeIds()
389 LDEBUG <<
"EasyDumper:: computeFormeIds";
391 for (std::map<uint64_t,Forme*>::const_iterator it=m_formesIndex.begin();
392 it!=m_formesIndex.end();
395 std::ostringstream oss;
397 LDEBUG <<
"EasyDumper:: adding to m_formesIds3: "<<(*it).second->forme<<
" ("<<it->first<<
") -> " << oss.str();
398 m_formesIds[it->first]=oss.str();
400 LDEBUG <<
"EasyDumper:: DONE computeFormeIds";
dump the content of the analysis graph in Easy XML format
void dump(std::ostream &out)
EasyDumper(const ConstituantAndRelationExtractor &care, const std::map< std::string, std::string > &relationTypeMapping, const std::map< std::string, std::string > &srcVxTag, const std::map< std::string, std::string > &tgtVxTag, const std::string &enonceId)
Definition d'un groupe syntaxique.
dump the content of the analysis graph in Easy XML format
std::string transcodeToXmlEntities(const std::string &str)
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
LimaString utf8stdstring2limastring(const std::string &src)