LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
coreferentAnnotation.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
7
15
18
19#include <iostream>
20
21
22using namespace boost;
23using namespace std;
24using namespace Lima::Common::Misc;
25using namespace Lima::Common::MediaticData;
26using namespace Lima::Common::AnnotationGraphs;
29
30
31namespace Lima
32{
33namespace LinguisticProcessing
34{
35namespace Coreferences
36{
37
38
40{
42 try
43 {
44 ga.value<CoreferentAnnotation>().dump(os, m_ad);
45 return SUCCESS_ID;
46 }
47 catch (const boost::bad_any_cast& )
48 {
49 LERROR << "This annotation is not a CoreferentAnnotation ; nothing dumped";
50 return UNKNOWN_ERROR;
51 }
52}
53
58 const LinguisticGraph* g,
59 MediaId language,
62 const std::set< LinguisticCode >& inNpCategs,
63 const Common::PropertyCode::PropertyAccessor* microAccessor) const
64{
65 // use PosGraph, should be only one categ
67 if (data ==0 || data->empty()) { return false; };
68 LinguisticCode categ=data->firstValue(*microAccessor);
69 return (inNpCategs.find(categ)!=inNpCategs.end()||GovernedBy(language,utf8stdstring2limastring("COMPADV"))(*anagraph,m_morphVertex,ac));
70}
71
72
73
75 const SyntacticData* sd,
76 MediaId language,
77 std::set<DependencyGraphVertex>* alreadyProcessed) const
78{
80 alreadyProcessed->insert(headNode);
81 CEdgeDepRelTypePropertyMap map = get(edge_deprel_type, *(sd-> dependencyGraph()));
82 DependencyGraphOutEdgeIt it, it_end;
83 boost::tie(it, it_end) = boost::out_edges(headNode, *(sd->dependencyGraph()));
84
85 if (it == it_end) return sd->tokenVertexForDepVertex(headNode);
86 else
87 {
88 for (; it != it_end; it++)
89 {
90 SyntacticRelationId relationId(static_cast<SyntacticRelationId>(map[*it]));
91 std::string relationName = static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(language)).getSyntacticRelationName(relationId);
92
93
94 if (/*static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(language)).isACompoundRel(relationName)||*/relationName=="MOD_N")
95 {
96 headNode = target(*it, *(sd->dependencyGraph())) ;
98 if (alreadyProcessed->find(headNode)==alreadyProcessed->end())
99 return ca.npHeadVertex(sd,language,alreadyProcessed);
100 }
101 }
102 return m_morphVertex;
103 }
104}
105
106
107
109 const LinguisticGraph* g,
110 const std::set< LinguisticCode >& categs,
111 const Common::PropertyCode::PropertyAccessor* microAccessor) const
112{
113 // use PosGraph, should be only one categ
115 if (data ==0 || data->empty()) { return false; };
116 LinguisticCode categ=data->firstValue(*microAccessor);
117 return (categs.find(categ)!=categs.end());
118}
119
120
121
122
123
127 const LinguisticGraph* g,
128 const Common::PropertyCode::PropertyAccessor* macroAccessor,
129 const LinguisticCode& L_PRON) const
130{
132 if (data ==0 || data->empty()) { return false; };
133 return (data->firstValue(*macroAccessor) == L_PRON);
134}
135
136
139 const std::string& definiteRel,
140 const std::set< LinguisticCode >& definiteCategs,
141 const Common::PropertyCode::PropertyAccessor* microAccessor,
142 MediaId language) const
143{
145 CEdgeDepRelTypePropertyMap map = get(edge_deprel_type, *(sd-> dependencyGraph()));
146 CVertexDataPropertyMap dataMap = get(vertex_data, *(sd-> graph()));
147 DependencyGraphInEdgeIt it, it_end;
148 boost::tie(it, it_end) = boost::in_edges(dv, *(sd->dependencyGraph()));
149 for (; it != it_end; it++)
150 {
151 SyntacticRelationId relationId(static_cast<SyntacticRelationId>(map[*it]));
152 std::string relationName = static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(language)).getSyntacticRelationName(relationId);
153
154 if (relationName == definiteRel)
155 {
156 MorphoSyntacticData* data = dataMap[sd->tokenVertexForDepVertex(source(*it, *(sd->dependencyGraph())))];
157 if (data ==0 || data->empty()) { return false; };
158 return (definiteCategs.find(data->firstValue(*microAccessor)) != definiteCategs.end());
159 }
160 }
161 return false;
162}
163
164
165
168 const std::string& pleonRel,
169 MediaId language) const
170{
171// COREFSOLVERLOGINIT;
173 CEdgeDepRelTypePropertyMap map = get(edge_deprel_type, *(sd-> dependencyGraph()));
174 DependencyGraphOutEdgeIt it, it_end;
175 boost::tie(it, it_end) = boost::out_edges(dv, *(sd->dependencyGraph()));
176 for (; it != it_end; it++)
177 {
178 SyntacticRelationId relationId(static_cast<SyntacticRelationId>(map[*it]));
179 std::string relationName = static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(language)).getSyntacticRelationName(relationId);
180
181 if (relationName == pleonRel)
182 {
183 return true;
184 }
185 }
186 return false;
187}
188
189
192 const LinguisticGraph* g,
193 const Common::PropertyCode::PropertyAccessor* macroAccessor,
194 const Common::PropertyCode::PropertyAccessor* microAccessor,
195 const std::map<std::string,LinguisticCode>& tagLocalDef,
196 const std::map<std::string, std::deque<std::string> >& relLocalDef,
197 const std::set< LinguisticCode >& definiteCategs,
198 const std::set< LinguisticCode >& reflexiveReciprocalCategs,
199 const std::set< LinguisticCode >& undefPronounsCategs,
200 const std::set< LinguisticCode >& possPronounsCategs,
201 const Common::PropertyCode::PropertyAccessor* personAccessor,
203 MediaId language) const
204{
205// COREFSOLVERLOGINIT;
206 LinguisticCode L_PRON = (*tagLocalDef.find("PronMacroCategory")).second;
207 std::string pleonRel = *(*relLocalDef.find("PleonasticRelation")).second.begin();
208 std::string defRel = *(*relLocalDef.find("DefiniteRelation")).second.begin();
209 if (isPronoun(g,macroAccessor, L_PRON))
210 {
211 if (isTaggedAsOneOfThese(g,reflexiveReciprocalCategs,microAccessor))
212 {
213 return "reflPron";
214 }
215 if (isN3PPronoun(personAccessor, anagraph))
216 {
217 return "N3Ppron";
218 }
219 if (isTaggedAsOneOfThese(g,undefPronounsCategs,microAccessor))
220 {
221 return "undefPron";
222 }
223 if (isTaggedAsOneOfThese(g,possPronounsCategs,microAccessor))
224 {
225 return "possPron";
226 }
227 Token* token = get(vertex_token, *anagraph->getGraph(), m_morphVertex);
228 if (token != 0 && (limastring2utf8stdstring(token->stringForm())=="on"|| limastring2utf8stdstring(token->stringForm())=="-t-on"||limastring2utf8stdstring(token->stringForm())=="On"))
229 {
230 return "on";
231 }
232 return isPleonastic(sd,pleonRel,language)?"pleon":"other";
233 }
234 else
235 {
236 return isDefinite(sd,defRel,definiteCategs,microAccessor,language)?"def":"undef";
237 }
238}
239// is non-3rd-Person Pronoun
241 const Common::PropertyCode::PropertyAccessor* personAccessor,
242 const LinguisticAnalysisStructure::AnalysisGraph* anagraph) const
243{
244 MorphoSyntacticData* data = get(vertex_data, *anagraph->getGraph(), m_morphVertex);
245 return (data->firstValue(*personAccessor)!=LinguisticCode::fromUInt(48));
246}
247
252 LinguisticGraphVertex& beginSentence) const
253{
254 Token* token = get(vertex_token, *anagraph->getGraph(), beginSentence);
255 return (token != 0 && limastring2utf8stdstring(token->stringForm())==":");
256}
257
260 LinguisticGraphVertex& endSentence) const
261{
262 Token* token = get(vertex_token, *anagraph->getGraph(), endSentence);
263 return (token != 0 && limastring2utf8stdstring(token->stringForm())==":");
264}
265
267 const SyntacticData* sd,
269 AnalysisContent& ac,
270 MediaId language,
271 std::set<DependencyGraphVertex>* alreadyProcessed) const
272{
273 alreadyProcessed->insert(m_morphVertex);
274 if (GovernorOf(language,utf8stdstring2limastring("APPOS"))(*anagraph,m_morphVertex,ac))
275 return true;
276 else
277 {
278 LinguisticGraphVertex head = npHeadVertex(sd,language,new std::set<DependencyGraphVertex>());
279 if (alreadyProcessed->find(head)==alreadyProcessed->end())
280 return CoreferentAnnotation(head,0).isInAppos(sd,anagraph,ac,language,alreadyProcessed);
281 else return false;
282 }
283}
284
286 const SyntacticData* sd,
287 const LinguisticAnalysisStructure::AnalysisGraph* anagraph) const
288{
289 DependencyGraphInEdgeIt it, it_end;
290 boost::tie(it, it_end) = boost::in_edges(m_morphVertex, *(sd->dependencyGraph()));
291 for (; it != it_end; it++)
292 {
293 Token* token = get(vertex_token, *anagraph->getGraph(),source(*it, *(sd->dependencyGraph())));
294 if (token!= 0 && (limastring2utf8stdstring(token->stringForm()) == "quant à"
295 ||limastring2utf8stdstring(token->stringForm()) == "Quant à"
296 ||limastring2utf8stdstring(token->stringForm()) == "quant aux"
297 ||limastring2utf8stdstring(token->stringForm()) == "Quant aux"))
298 {
299 return true;
300 }
301 }
302 return false;
303}
304
306 const SyntacticData* sd,
307 const Common::PropertyCode::PropertyAccessor* macroAccessor,
308 const std::map<std::string,LinguisticCode>& tagLocalDef,
309 MediaId language,
311 AnalysisContent& ac,
312 set<LinguisticGraphVertex>* alreadyProcessed) const
313{
314
315 DependencyGraphOutEdgeIt it, it_end;
316 boost::tie(it, it_end) = boost::out_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
317 if (it == it_end) return false;
318 //else
320 // for each outer relation of *this
321 for (; it != it_end; it++)
322 {
323 qv = target(*it,*anagraph->getGraph());
324 if (CoreferentAnnotation(0,qv).isVerb(macroAccessor,tagLocalDef, anagraph))
325 {
326 // if verb is governed by a "COMPL" relation( = conjonctive subordinate)
327 // if verb is governing a "MOD_N" relation( = relative subordinate)
328 if(/*GovernedBy(language,utf8stdstring2limastring("COMPL"))(*anagraph,qv,ac)||*/GovernorOf(language,utf8stdstring2limastring("MOD_N"))(*anagraph,qv,ac))
329 {
330 return true;
331 }
332 else if (alreadyProcessed->find(qv)==alreadyProcessed->end())
333 {
334 alreadyProcessed->insert(qv);
335 return CoreferentAnnotation(0,qv).isInSubordinate(sd, macroAccessor,tagLocalDef, language, anagraph, ac, alreadyProcessed);
336 }
337 }
338 }
339 if (qv!=0 && alreadyProcessed->find(qv)==alreadyProcessed->end())
340 {
341 alreadyProcessed->insert(qv);
342 return CoreferentAnnotation(0,qv).isInSubordinate(sd, macroAccessor,tagLocalDef, language, anagraph, ac, alreadyProcessed);
343 }
344 //else
345 return false;
346}
347
348
355 const SyntacticData* sd,
356 const std::deque<std::string>& macroDependencyRelation,
357 MediaId language) const
358{
359 CEdgeDepRelTypePropertyMap map = get(edge_deprel_type, *(sd-> dependencyGraph()));
360 DependencyGraphOutEdgeIt it, it_end;
361
362 boost::tie(it, it_end) = boost::out_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
363 if (it == it_end) return false;
364 else
365 {
366 // for each outer relation of anaphora
367 for (; it != it_end; it++)
368 {
369 SyntacticRelationId relationId(static_cast<SyntacticRelationId>(map[*it]));
370 std::string relationName = static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(language)).getSyntacticRelationName(relationId);
371
372 std::deque<std::string>::const_iterator it2;
373 for (it2 = macroDependencyRelation.begin( );
374 it2 != macroDependencyRelation.end( );
375 it2++ )
376 {
377 // check if the outer relation is func relation
378 if (relationName == *it2)
379 {
380 return true;
381 }
382 else if (relationName == "COORD2")
383 {
384// CEdgeDepRelTypePropertyMap map2 = get(edge_deprel_type, *(sd-> dependencyGraph()));
385 DependencyGraphOutEdgeIt it3, it3_end;
386 boost::tie(it3, it3_end) = boost::out_edges(target(*it,*sd-> dependencyGraph()), *(sd->dependencyGraph()));
387 if (it3 == it3_end) return false;
388 // for each outer relation of coordination conjunction
389 for (; it3 != it3_end; it3++)
390 {
391 CoreferentAnnotation ca(0,target(*it3,*sd-> dependencyGraph()));
392 if (ca.isFunctionMasterOf(sd,macroDependencyRelation, language)) return true;
393 }
394 }
395 }
396 }
397 }
398 return false;
399}
400
404 const Common::PropertyCode::PropertyAccessor* macroAccessor,
405 const std::map<std::string,LinguisticCode>& tagLocalDef,
407) const
408{
409// COREFSOLVERLOGINIT;
410 MorphoSyntacticData* data = get(vertex_data, *anagraph->getGraph(), m_morphVertex);
411 if (data ==0 || data->empty()) { return false; };
412 LinguisticCode L_VERB = (*tagLocalDef.find("VerbMacroCategory")).second;
413
414 if(data->firstValue(*macroAccessor)==L_VERB)
415 {
416 return true;
417 }
418 return false;
419}
420
422 const Common::PropertyCode::PropertyAccessor* microAccessor,
424 const LinguisticCode& conjCoord) const
425{
426// COREFSOLVERLOGINIT;
427 MorphoSyntacticData* data = get(vertex_data, *anagraph->getGraph(), m_morphVertex);
428 if (data ==0 || data->empty()) { return false; };
429 if(data->firstValue(*microAccessor)==conjCoord)
430 {
431 return true;
432 }
433 return false;
434}
435
436
438 const SyntacticData* sd,
439 const Common::PropertyCode::PropertyAccessor* genderAccessor,
440 MediaId language,
442 AnalysisContent& ac) const
443 {
444// TimeUtils::logElapsedTime(limastring2utf8stdstring(token->stringForm()));
445 DependencyGraph g = *(sd->dependencyGraph());
446 if (GovernedBy(language, utf8stdstring2limastring("COORD1"))(*anagraph,sd->depVertexForTokenVertex(m_morphVertex),ac))
447 {
448 DependencyGraphInEdgeIt it, it_end;
449 boost::tie(it, it_end) = boost::in_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
450 if (it==it_end) return false;
451 if (GovernedBy(language, utf8stdstring2limastring("COORD2"))(*anagraph,source(*it, *anagraph->getGraph()),ac))
452 {
453 DependencyGraphInEdgeIt it2, it2_end;
454 boost::tie(it2, it2_end) = boost::in_edges(source(*it, g),g);
455 if (it2==it2_end) return false;
456 MorphoSyntacticData* data1 = get(vertex_data, *anagraph->getGraph(), source(*it2, g));
457 if (data1 ==0 || data1->empty()) { return false; };
458 for (MorphoSyntacticData::iterator msdataIt = data1->begin(); msdataIt!=data1->end(); msdataIt++)
459 {
460 if (genderAccessor->readValue(msdataIt->properties)==LinguisticCode::fromUInt(1))
461 return true;
462 else if (CoreferentAnnotation(0, sd->tokenVertexForDepVertex(source(*it2, *(sd->dependencyGraph())))).isGovernedByMasculineCoordinate(sd,genderAccessor,language,anagraph,ac))
463 return true;
464 }
465 }
466 }
467 else if (GovernedBy(language, utf8stdstring2limastring("APPOS"))(*anagraph,sd->depVertexForTokenVertex(m_morphVertex),ac))
468 {
469 DependencyGraphInEdgeIt it, it_end;
470 boost::tie(it, it_end) = boost::in_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
471 if (it==it_end) return false;
472 MorphoSyntacticData* data1 = get(vertex_data, *anagraph->getGraph(), source(*it, g));
473 if (data1 ==0 || data1->empty()) { return false; };
474 for (MorphoSyntacticData::iterator msdataIt = data1->begin(); msdataIt!=data1->end(); msdataIt++)
475 {
476 if (genderAccessor->readValue(msdataIt->properties)==LinguisticCode::fromUInt(1))
477 return true;
478 else return CoreferentAnnotation(0, sd->tokenVertexForDepVertex(source(*it, *(sd->dependencyGraph())))).isGovernedByMasculineCoordinate(sd,genderAccessor,language,anagraph,ac);
479 }
480 }
481 else
482 return false;
483 return false;
484}
485
486// P and N have incompatible agreement features. (gender, number, person)
488 const CoreferentAnnotation& ca,
489 const SyntacticData* sd,
490 const Common::PropertyCode::PropertyAccessor* genderAccessor,
491 const Common::PropertyCode::PropertyAccessor* personAccessor,
492 const Common::PropertyCode::PropertyAccessor* numberAccessor,
493 MediaId language,
495 AnalysisContent& ac) const
496 {
497// COREFSOLVERLOGINIT;
498// TimeUtils::logElapsedTime("init Ac");
499// TimeUtils::updateCurrentTime();
500 // LDEBUG << "isArgumentCompatibleWith";
501 MorphoSyntacticData* data1 = get(vertex_data, *anagraph->getGraph(), m_morphVertex);
502 if (data1 ==0 || data1->empty()) { return false; };
503 bool isPlural = false;
504 for (MorphoSyntacticData::iterator it = data1->begin(); it!=data1->end(); it++)
505 {
506 if (numberAccessor->readValue(it->properties)==LinguisticCode::fromUInt(8))
507 {
508 isPlural = true;
509 break;
510 }
511 }
512 bool isMascPlural = false;
513 for (MorphoSyntacticData::iterator it = data1->begin(); it!=data1->end(); it++)
514 {
515 if (numberAccessor->readValue(it->properties)==LinguisticCode::fromUInt(8)
516 && genderAccessor->readValue(it->properties)==LinguisticCode::fromUInt(1))
517 {
518 isMascPlural = true;
519 break;
520 }
521 }
522 MorphoSyntacticData* data2 = get(vertex_data, *anagraph->getGraph(), ca.m_morphVertex);
523 if (data2 ==0 || data2->empty()) { return false; };
524// TimeUtils::logElapsedTime("before A");
525// TimeUtils::updateCurrentTime();
526 bool genderAgreement = Automaton::GenderAgreement(language)(*anagraph, m_morphVertex, ca.m_morphVertex,ac)
527 || (isMascPlural
528 && ca.isGovernedByMasculineCoordinate(sd,genderAccessor,language,anagraph,ac));
529// TimeUtils::logElapsedTime("GA");
530// TimeUtils::updateCurrentTime();
531 bool NumberAgreement = Automaton::NumberAgreement(language)(*anagraph, m_morphVertex, ca.m_morphVertex,ac)
532 || (isPlural
533 &&
534 (GovernedBy(language, utf8stdstring2limastring("COORD1"))(*anagraph,sd->depVertexForTokenVertex(ca.m_morphVertex),ac)
535 ||
536 GovernedBy(language, utf8stdstring2limastring("APPOS"))(*anagraph,sd->depVertexForTokenVertex(ca.m_morphVertex),ac))
537 );
538// TimeUtils::logElapsedTime("NA");
539// TimeUtils::updateCurrentTime();
540 bool PersonAgreement =
541 (data1->firstValue(*personAccessor)==data2->firstValue(*personAccessor) ||
542 // anaphora = pronom classifi��la 3e personne, candidate = common NP non-classified
543 (data1->firstValue(*personAccessor)==LinguisticCode::fromUInt(48)
544 && data2->firstValue(*personAccessor)==L_NONE));
545// TimeUtils::logElapsedTime("PA");
546// TimeUtils::updateCurrentTime();
547 return (genderAgreement && NumberAgreement && PersonAgreement);
548 }
549
550// P is in the Argument Domain of N <=> P and N are both argument of the same head
552 const CoreferentAnnotation& ca,
553 const SyntacticData* sd,
554 MediaId language,
556 AnalysisContent& ac,
557 const Common::PropertyCode::PropertyAccessor* macroAccessor,
558 const Common::PropertyCode::PropertyAccessor* microAccessor,
559 const std::map<std::string,LinguisticCode>& tagLocalDef,
560 const LinguisticCode& conjCoord,
561 set<LinguisticGraphVertex>* alreadyProcessed) const
562{
563// COREFSOLVERLOGINIT;
564 alreadyProcessed->insert(m_morphVertex);
565// LDEBUG << "isInTheArgumentDomainOf" ;
566// LDEBUG << "check: " << m_morphVertex << "for: " << ca.m_morphVertex;
567 DependencyGraphOutEdgeIt it, it_end;
568 boost::tie(it, it_end) = boost::out_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
569
570 if (it == it_end)
571 {
572 return false;
573 }
574// else
575 // for each head of anaphora
576 for (; it != it_end; it++)
577 {
578
579 DependencyGraphVertex headNode = target(*it, *(sd->dependencyGraph()));
580 // check if this head is also head of candidate (except for the anaphora which are "circumstantial" adjuncts)
581 if ((
582 // laisse les compléments circonstanciels être anaphores d'un antécédent argument
583 !SecondUngovernedBy(language, utf8stdstring2limastring("COD_V"))(*anagraph, npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
584 ||
585 !SecondUngovernedBy(language, utf8stdstring2limastring("CodPrev"))(*anagraph, npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
586 ||
587 !SecondUngovernedBy(language, utf8stdstring2limastring("CoiPrev"))(*anagraph, npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
588 ||
589 !SecondUngovernedBy(language, utf8stdstring2limastring("SUJ_V"))(*anagraph, npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
590 ||
591 !SecondUngovernedBy(language, utf8stdstring2limastring("SujInv"))(*anagraph, npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
592 )
593 &&
594 !SecondUngovernedBy(language, LimaString())(*anagraph, ca.npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
595)
596 {
597 return true;
598 }
599// else
600 {
601 CoreferentAnnotation anaHead(0,sd->tokenVertexForDepVertex(headNode));
602 if (
603 // candidat dirige une quelconque dépendance
604 GovernorOf(language,LimaString())(*anagraph,sd->depVertexForTokenVertex(ca.m_morphVertex),ac)
605 && ( // target(ana) est verbe non subordonné
606// language==
607// &&
608 ( anaHead.isVerb(macroAccessor,tagLocalDef, anagraph)
609 && (
610 !GovernedBy(language,utf8stdstring2limastring("COMPL"))(*anagraph,headNode,ac)
611 &&
612 !GovernedBy(language,utf8stdstring2limastring("SUJ_V_REL"))(*anagraph,headNode,ac)
613// ||
614// !GovernedBy(language,utf8stdstring2limastring("CodPrev"))(*anagraph,headNode,ac)
615 ) )
616 ||
617 // target(ana) est conjonction de coordination et a un COORD1
618 (anaHead.isConjCoord(microAccessor, anagraph,conjCoord) && GovernorOf(language,LimaString())(*anagraph,headNode,ac))
619 )
620 &&
621 // pas encore traité
622 alreadyProcessed->find(anaHead.m_morphVertex)==alreadyProcessed->end())
623 {
624 return anaHead.isInTheArgumentDomainOf(CoreferentAnnotation(0,ca.npHeadVertex(sd,language, new set<DependencyGraphVertex>())), sd, language, anagraph, ac, macroAccessor, microAccessor, tagLocalDef, conjCoord, alreadyProcessed)
625 /* ||
626 ca.isInTheArgumentDomainOf(*this, sd, language, anagraph, ac, macroAccessor, microAccessor, tagLocalDef, conjCoord, alreadyProcessed)*/;
627 }
628 }
629 }
630// TimeUtils::logElapsedTime("fin sf2");
631// TimeUtils::updateCurrentTime();
632 return false;
633}
634
635// P is in the Argument Domain of N <=> P and N are both argument of the same head
637 const CoreferentAnnotation& ca,
638 const SyntacticData* sd,
639 MediaId language,
641 AnalysisContent& ac,
642 const Common::PropertyCode::PropertyAccessor* macroAccessor,
643 const Common::PropertyCode::PropertyAccessor* microAccessor,
644 const std::map<std::string,LinguisticCode>& tagLocalDef,
645 const LinguisticCode& conjCoord,
646 set<LinguisticGraphVertex>* alreadyProcessed) const
647{
648// COREFSOLVERLOGINIT;
649// cerr << "trace" <<endl;
650 alreadyProcessed->insert(m_morphVertex);
651// LDEBUG << "isInTheArgumentDomainOf" ;
652// LDEBUG << "check: " << m_morphVertex << "for: " << ca.m_morphVertex;
653 DependencyGraphOutEdgeIt it, it_end;
654 boost::tie(it, it_end) = boost::out_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
655 if (it == it_end)
656 {
657// TimeUtils::logElapsedTime("fin sf2");
658// TimeUtils::updateCurrentTime();
659 return false;
660 }
661// else
662 // for each head of anaphora
663 for (; it != it_end; it++)
664 {
665// cerr << "trace1" <<endl;
666 DependencyGraphVertex headNode = target(*it, *(sd->dependencyGraph()));
667 // check if this head is also head of candidate
668 if (
669 !SecondUngovernedBy(language, LimaString())(*anagraph, ca.npHeadVertex(sd,language,new set<DependencyGraphVertex>()),headNode,ac)
670 )
671 {
672 /*TimeUtils::logElapsedTime("fin sf2");
673 TimeUtils::updateCurrentTime();
674 */return true;
675 }
676// else
677 {
678// cerr << "trace2" <<endl;
679 CoreferentAnnotation anaHead(0,sd->tokenVertexForDepVertex(headNode));
680 if (
681 // candidat dirige une quelconque dépendance
682 GovernorOf(language,LimaString())(*anagraph,sd->depVertexForTokenVertex(ca.m_morphVertex),ac)
683 &&
684 // pas encore traité
685 alreadyProcessed->find(anaHead.m_morphVertex)==alreadyProcessed->end())
686 {
687 return anaHead.isInTheArgumentDomainOf(CoreferentAnnotation(0,ca.npHeadVertex(sd,language, new set<DependencyGraphVertex>())), sd, language, anagraph, ac, macroAccessor, microAccessor, tagLocalDef, conjCoord, alreadyProcessed)
688 /* ||
689 ca.isInTheArgumentDomainOf(*this, sd, language, anagraph, ac, macroAccessor, microAccessor, tagLocalDef, conjCoord, alreadyProcessed)*/;
690 }
691 }
692 }
693// TimeUtils::logElapsedTime("fin sf2");
694// TimeUtils::updateCurrentTime();
695 return false;
696}
697
698// P is in the Adjunct Domain of N <=> N is an argument of a head H, P is the object of a preposition PREP, PREP is an adjunct of H
700 const CoreferentAnnotation& ca,
702 const LinguisticGraph* graph,
703 const Common::PropertyCode::PropertyAccessor* macroAccessor,
704 const std::map<std::string,LinguisticCode>& tagLocalDef,
705 const std::map<std::string, std::deque<std::string> >& relLocalDef,
706 MediaId language) const
707{
708// COREFSOLVERLOGINIT;
709// LDEBUG << "isInTheAdjunctDomainOf" ;
710 // for each HEAD of candidate
711 DependencyGraphOutEdgeIt it, it_end;
713 boost::tie(it, it_end) = boost::out_edges(headNode, *(sd->dependencyGraph()));
714 if (it == it_end)
715 {
716 return false;
717 }
718 // else
719 for (; it != it_end; it++)
720 {
721 headNode = target(*it, *(sd->dependencyGraph()));
722 if (isInThePrepAdjunctNP(headNode, sd, graph, macroAccessor, tagLocalDef, relLocalDef,language))
723 {
724 return true;
725 }
726 }
727 return false;
728}
729
730// P is the object of a preposition PREP,
731// and PREP is an adjunct of Q
733 const DependencyGraphVertex& qv,
735 const LinguisticGraph* graph,
736 //const Common::PropertyCode::PropertyManager& microManager,
737 const Common::PropertyCode::PropertyAccessor* macroAccessor,
738 const std::map<std::string,LinguisticCode>& tagLocalDef,
739 const std::map<std::string, std::deque<std::string> >& relLocalDef,
740 MediaId language) const
741{
742// COREFSOLVERLOGINIT;
743// LDEBUG << "isInThePrepAdjunctOf";
744 MorphoSyntacticData* data = get(vertex_data, *graph, qv);
745 if (data ==0 || data->empty()) { return false; };
746 LinguisticCode L_VERB = (*tagLocalDef.find("VerbMacroCategory")).second;
747 // if head node is not a verbal form
748 if(data->firstValue(*macroAccessor)==L_VERB)
749 {
750 return false;
751 }
752 //else
753 // for each PREP of anaphora
754 // <=> for each inner relation and if it is a PrepRelation
755
756// CEdgeDepRelTypePropertyMap map = get(edge_deprel_type, *(sd-> dependencyGraph()));
757 DependencyGraphInEdgeIt it2, it2_end;
758 boost::tie(it2, it2_end) = boost::in_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
759 if (it2==it2_end) return false;
760 CoreferentAnnotation catmp(0, sd->tokenVertexForDepVertex(source(*it2, *(sd->dependencyGraph()))));
761 if(catmp.isFunctionMasterOf(sd,(*relLocalDef.find("PrepRelation")).second,language))
762 {
763// // test if PREP is an adjunct of HEAD
764 if (isFunctionMasterOf(sd,(*relLocalDef.find("AdjunctRelation")).second,language))
765 return true;
766 }
767 return false;
768}
769
770// P is an argument of a head H, N is not a pronoun, and N is contained in H.
772 const CoreferentAnnotation& ca,
773 const SyntacticData* sd,
774 //const LinguisticGraph* g,
775 const Common::PropertyCode::PropertyAccessor* macroAccessor,
776 const LinguisticCode& L_PRON,
777 MediaId language,
779 AnalysisContent& ac) const
780{
781// COREFSOLVERLOGINIT;
782// LDEBUG << "sf4" ;
783 const LinguisticGraph* g = anagraph->getGraph();
784 if (ca.isPronoun(g, macroAccessor, L_PRON))
785 {
786 return false;
787 }
788 //else
789 DependencyGraphOutEdgeIt it, it_end;
790 boost::tie(it, it_end) = boost::out_edges(sd->depVertexForTokenVertex(m_morphVertex), *(sd->dependencyGraph()));
791 if (it == it_end)
792 {
793 return false;
794 }
795 //else
796 // for each head of anaphora
797 for (; it != it_end; it++)
798 {
799 DependencyGraphVertex headNode = target(*it, *(sd->dependencyGraph()));
800 if (ca.isContainedIn(headNode, language, anagraph, ac))
801 {
802 return true;
803 }
804 }
805 return false;
806}
807
808// P is in the NP domain of N
809// <=>
810// N is a determiner of a noun Q, and:
811// (i) P is an argument of Q.
812// or (ii) P is an object of a preposition PREP and PREP is an adjunct of Q.
814 const CoreferentAnnotation& ca,
815 const SyntacticData* sd,
816 const Common::PropertyCode::PropertyAccessor* /*macroAccessor*/,
817 const std::map<std::string,LinguisticCode>& /*tagLocalDef*/,
818 const std::map<std::string,std::deque<std::string> >& /*relLocalDef*/,
819 MediaId language,
821 AnalysisContent& /*ac*/
822 ) const
823{
824// COREFSOLVERLOGINIT;
825// LDEBUG << "isInTheNpDomainOf";
826// DependencyGraphVertex* qv = new DependencyGraphVertex();
827// if (ca.isDeterminer(qv,sd, relLocalDef, language, anagraph, ac))
828// {
829// // if this is an argument of qv, return true.
830// DependencyGraphInEdgeIt itQ, itQ_end;
831// boost::tie(itQ, itQ_end) = boost::in_edges(*qv, *(sd->dependencyGraph()));
832// for (;itQ!=itQ_end; itQ++)
833// {
834// DependencyGraphVertex pv = source(*itQ, *(sd->dependencyGraph())) ;
835// if (m_morphVertex==sd->tokenVertexForDepVertex(pv))
836// return true;
837// }
838// // else if this is an object of a preposition PREP and PREP is an adjunct of qv, return true.
839// if (isInThePrepAdjunctNP(*qv,sd, anagraph->getGraph(), macroAccessor, tagLocalDef, relLocalDef))
840// return true;
841//
842// }
843return ca.npHeadVertex(sd, language, new set<DependencyGraphVertex>())==npHeadVertex(sd, language, new set<DependencyGraphVertex>());
844}
845
846// P is contained in a phrase Q <=>
847// (i) P is either an argument or an adjunct of Q (ie. P is immediately contained in Q.
848// or (ii) P is immediately contained in some phrase R, and R is contained in Q.
850 const DependencyGraphVertex& dv,
851 MediaId language,
853 AnalysisContent& ac) const
854{
855// COREFSOLVERLOGINIT;
856// LDEBUG << "isContainedIn";
857 return (!SecondUngovernedBy(language,
858 LimaString())(*anagraph, dv, m_morphVertex ,ac));
859}
860
861
862// !! test if *this is determiner of ANY which is returned by the pointer qv
865 const SyntacticData* sd,
866 const std::map<std::string,std::deque<std::string> >& relLocalDef,
867 MediaId language,
869 AnalysisContent& ac) const
870{
871// COREFSOLVERLOGINIT;
872// LDEBUG << "isDeterminer";
873 std::deque<std::string> detRels = (*relLocalDef.find("NPDeterminerRelation")).second;
874 for (std::deque<std::string>::iterator itDet= detRels.begin(); itDet != detRels.end(); itDet++)
875 {
876 DependencyGraphOutEdgeIt itN, itN_end;
877 boost::tie(itN, itN_end) = boost::out_edges(sd->depVertexForTokenVertex(this->m_morphVertex), *(sd->dependencyGraph()));
878 for (;itN!=itN_end; itN++)
879 {
880 *qv = target(*itN, *(sd->dependencyGraph())) ;
881 bool res = !SecondUngovernedBy(language,
882 utf8stdstring2limastring(*itDet))(*anagraph, m_morphVertex,*qv,ac);
883 return (res);
884 }
885 }
886 return false;
887}
888
889
890// P is a determiner of a noun Q, and N is contained in Q.
892 const CoreferentAnnotation& ca,
893 const SyntacticData* sd,
894 const std::map<std::string,std::deque<std::string> >& relLocalDef,
895 MediaId language,
897 AnalysisContent& ac) const
898{
899// COREFSOLVERLOGINIT;
900// LDEBUG << "sf6";
902// if (this->isDeterminer(qv,sd, relLocalDef, language, anagraph, ac))
903// if (ca.isContainedIn(*qv, language, anagraph, ac))
904// return true;
905// return false;
906 return (this->isDeterminer(qv,sd, relLocalDef, language, anagraph, ac) && ca.isContainedIn(*qv, language, anagraph, ac));
907}
908
909// N is an argument of a verb V,
910// there is an NP Q in the argument domain of N such that Q has no noun determiner,
911// and
912// (i) A is an argument of Q.
913// or (ii) A is an argument of a preposition PREP and PREP is an adjunct of Q.
915 const CoreferentAnnotation& ca,
916 const SyntacticData* sd,
917 const std::map<std::string,LinguisticCode >& tagLocalDef,
918 const std::map<std::string,std::deque<std::string> >& relLocalDef,
919 const Common::PropertyCode::PropertyAccessor* macroAccessor,
920 const Common::PropertyCode::PropertyAccessor* microAccessor,
921 MediaId language,
922 const std::set< LinguisticCode >& inNpCategs,
924 AnalysisContent& ac,
925 const LinguisticCode& conjCoord,
926 std::deque<Vertices>* npCandidates) const
927{
928// Token* token1 = get(vertex_token, *anagraph->getGraph(), m_morphVertex);
929// Token* token2 = get(vertex_token, *anagraph->getGraph(), ca.m_morphVertex);
930// if (token1!=0)
931// TimeUtils::logElapsedTime("token 1 : " + limastring2utf8stdstring(token1->stringForm()));
932// if (token2!=0)
933// TimeUtils::logElapsedTime("token 2 : " + limastring2utf8stdstring(token2->stringForm()));
934// TimeUtils::updateCurrentTime();
935// LinguisticGraph* graph = anagraph->getGraph();
936 std::deque<std::string> detRels = (*relLocalDef.find("NPDeterminerRelation")).second;
937 std::deque<std::string> adjunctRels = (*relLocalDef.find("AdjunctRelation")).second;
938 LinguisticCode L_VERB = (*tagLocalDef.find("VerbMacroCategory")).second;
939 DependencyGraphOutEdgeIt itN, itN_end;
940 boost::tie(itN, itN_end) = boost::out_edges(ca.m_morphVertex, *(sd->dependencyGraph()));
941 // for each token dv of which N is argument
942// TimeUtils::logElapsedTime("before boucle");
943// TimeUtils::updateCurrentTime();
944 for (;itN!=itN_end; itN++)
945 {
946 DependencyGraphVertex dv = target(*itN, *(sd->dependencyGraph())) ;
947 MorphoSyntacticData* data = get(vertex_data, *anagraph->getGraph(), sd->tokenVertexForDepVertex(dv));
948 if (data ==0 || data->empty()) { continue; };
949 // if dv is a verb
950 if (data->firstValue(*macroAccessor) == L_VERB)
951 {
952 // for each token Q which is NP
953// LinguisticGraphVertexIt itg, itg_end;
954// boost::tie(itg, itg_end) = vertices(*anagraph->getGraph());
955// TimeUtils::logElapsedTime("before second boucle");
956// TimeUtils::updateCurrentTime();
957 for (std::deque<Vertices>::iterator itm = npCandidates->begin();
958 itm != npCandidates->end( );
959 itm++)
960 {
961 for (Vertices::iterator candidateItr = (*itm).begin( );
962 candidateItr != (*itm).end( );
963 candidateItr++ )
964 {
965 if ((*candidateItr)->isIncludedInNounPhrase(anagraph->getGraph(), language, anagraph, ac, inNpCategs, microAccessor) )
966 {
967 // if Q is in the argument domain of N
968 // and if Q has no determiner
969 if ((*candidateItr)->isInTheArgumentDomainOf(*this,sd, language, anagraph, ac, macroAccessor, microAccessor, tagLocalDef, conjCoord, new set<LinguisticGraphVertex>()))
970 {
971 bool hasDeterminer = false;
972// TimeUtils::logElapsedTime("before third boucle");
973// TimeUtils::updateCurrentTime();
974 for (std::deque<std::string>::iterator itDet= detRels.begin(); itDet != detRels.end(); itDet++)
975 {
976 if(GovernedBy(language,
977 utf8stdstring2limastring(*itDet))(*anagraph, (*candidateItr)->m_morphVertex,ac))
978 hasDeterminer = true;
979 }
980// TimeUtils::logElapsedTime("end third boucle");
981// TimeUtils::updateCurrentTime();
982 if (!hasDeterminer)
983 {
984 // if A is an argument of Q, return true
985 if (!SecondUngovernedBy(language,
986 LimaString())(*anagraph, m_morphVertex,(*candidateItr)->m_morphVertex,ac))
987 {
988// TimeUtils::logElapsedTime("end aba4");
989// TimeUtils::updateCurrentTime();
990 return true;
991 }
992// // if A is an argument of a preposition PREP and PREP is an adjunct of Q, return true
993// DependencyGraphOutEdgeIt itA, itA_end;
994// boost::tie(itA, itA_end) = boost::out_edges(m_morphVertex, *(sd->dependencyGraph()));
995// // for each token dv of which N is argument
996// for (;itA!=itA_end; itA++)
997// {
998// DependencyGraphVertex dv = target(*itN, *(sd->dependencyGraph())) ;
999// MorphoSyntacticData* data = get(vertex_data, *graph, sd->tokenVertexForDepVertex(dv));
1000// if (data ==0 || data->empty()) { continue; };
1001// // if dv is a prep
1002// if (data->firstValue(*macroAccessor) == L_PREP)
1003// {
1004// for (std::deque<std::string>::iterator itAdju= adjunctRels.begin(); itAdju != adjunctRels.end(); itAdju++)
1005// {
1006// if (!SecondUngovernedBy(language,
1007// utf8stdstring2limastring(*itAdju))(*anagraph, dv,*candidateItr->m_morphVertex,ac))
1008// return true;
1009// }
1010// }
1011// }
1012 }
1013 }
1014 }
1015 }
1016// TimeUtils::logElapsedTime("end secondboucle");
1017// TimeUtils::updateCurrentTime();
1018 }
1019 }
1020 }
1021 /*TimeUtils::logElapsedTime("end aba4");
1022 TimeUtils::updateCurrentTime();
1023 */ return false;
1024}
1025
1026
1027// [higher slot] subj > agent > obj > (iobj|pobj) [lower slot]
1029 const SyntacticData* sd,
1030 const std::map<std::string,std::deque<std::string> >& relLocalDef,
1031 const std::map<std::string, int>& slotValues,
1032 MediaId language) const
1033{
1035 std::map<std::string,std::deque<std::string> >::const_iterator rel = relLocalDef.find("SubjectRelation");
1036 if (rel == relLocalDef.end())
1037 {
1038 LERROR << "\"SubjectRelation\" not defined in s2-lp-xxx.xml";
1039 }
1040 else if (isFunctionMasterOf(sd,(*rel).second, language))
1041 {
1042 return (*slotValues.find("SubjectRelation")).second;
1043 }
1044
1045 rel = relLocalDef.find("AgentRelation");
1046 if (rel == relLocalDef.end())
1047 {
1048 LERROR << "\"AgentRelation\" not defined in s2-lp-xxx.xml";
1049 }
1050 else if(isFunctionMasterOf(sd,(*rel).second,language))
1051 {
1052 return (*slotValues.find("AgentRelation")).second;
1053 }
1054 rel = relLocalDef.find("CODRelation");
1055 if (rel == relLocalDef.end())
1056 {
1057 LERROR << "\"CODRelation\" not defined in s2-lp-xxx.xml";
1058 }
1059 else if (isFunctionMasterOf(sd,(*rel).second,language))
1060 return (*slotValues.find("CODRelation")).second;
1061
1062 rel = relLocalDef.find("COIRelation");
1063 if (rel == relLocalDef.end())
1064 {
1065 LERROR << "\"COIRelation\" not defined in s2-lp-xxx.xml";
1066 }
1067 else if (isFunctionMasterOf(sd,(*rel).second,language))
1068 return (*slotValues.find("COIRelation")).second;
1069
1070 rel = relLocalDef.find("AdjunctRelation");
1071 if (rel == relLocalDef.end())
1072 {
1073 LERROR << "\"AdjunctRelation\" not defined in s2-lp-xxx.xml";
1074 }
1075 else if (isFunctionMasterOf(sd,(*rel).second,language))
1076 return (*slotValues.find("AdjunctRelation")).second;
1077
1078 return 0;
1079}
1080
1081// A is a determiner of a noun Q,
1082// and
1083// (i) Q is in the argument domain of N,
1084// and N fills a higher argument slot than Q.
1085// or (ii) Q is in the adjunct domain of N.
1087 const CoreferentAnnotation& ca,
1088 const SyntacticData* sd,
1089 const std::map<std::string,LinguisticCode>& tagLocalDef,
1090 const std::map<std::string,std::deque<std::string> >& relLocalDef,
1091 const Common::PropertyCode::PropertyAccessor* macroAccessor,
1092 const Common::PropertyCode::PropertyAccessor* microAccessor,
1093 MediaId language,
1095 AnalysisContent& ac,
1096 const std::map<std::string, int>& slotValues,
1097 const LinguisticCode& conjCoord) const
1098{
1099// COREFSOLVERLOGINIT;
1100// LDEBUG << "aba5";
1101 LinguisticGraph* graph = anagraph->getGraph();
1102 LinguisticCode NC = (*tagLocalDef.find("NomCommunMacroCategory")).second;
1103 LinguisticCode NP = (*tagLocalDef.find("NomPropreMacroCategory")).second;
1104 bool res = false;
1106 if (ca.isDeterminer(qv,sd, relLocalDef, language, anagraph, ac))
1107 {
1108 MorphoSyntacticData* data = get(vertex_data,*graph,sd->tokenVertexForDepVertex(*qv));
1109 if (data ==0 || data->empty()) { return false; };
1110 // if *qv is a noun
1111 if (data->firstValue(*macroAccessor) == NC || data->firstValue(*macroAccessor) == NP)
1112 {
1113 // if Q is in the argument domain of N,
1114 CoreferentAnnotation caQ(0,*qv);
1115 if (caQ.isInTheArgumentDomainOf(ca,sd, language, anagraph, ac, macroAccessor, microAccessor, tagLocalDef, conjCoord, new set<LinguisticGraphVertex>()))
1116 {
1117 // and if N fills a higher argument slot than Q.
1118 if (ca.getSlotValue(sd, relLocalDef, slotValues,language) > caQ.getSlotValue(sd, relLocalDef, slotValues,language))
1119 {
1120 return true;
1121 }
1122 }
1123 // or if Q is in the adjunct domain of N.
1124 if (caQ.isInTheAdjunctDomainOf(*this,sd,graph,macroAccessor,tagLocalDef,relLocalDef,language))
1125 {
1126 return true;
1127 }
1128 }
1129 }
1130 return res;
1131}
1132
1133
1134
1135
1139 LinguisticGraph* graph,
1140 SyntacticData* sd,
1141 const Common::PropertyCode::PropertyAccessor* macroAccessor,
1142 const Common::PropertyCode::PropertyAccessor* microAccessor,
1143 const std::map<std::string,LinguisticCode>& tagLocalDef,
1144 const std::map<std::string, std::deque<std::string> >& relLocalDef,
1145 const std::set< LinguisticCode >& definiteCategs,
1146 const std::set< LinguisticCode >& reflexiveReciprocalCategs,
1147 const std::set< LinguisticCode >& undefPronouns,
1148 const std::set< LinguisticCode >& possPronouns,
1149 const bool& resolveDefinites,
1150 const bool& resolveN3PPronouns,
1151 const Common::PropertyCode::PropertyAccessor* personAccessor,
1153 MediaId language)
1154{
1155 int res = 0;
1156 std::string type = referentType(sd,graph,macroAccessor,microAccessor, tagLocalDef, relLocalDef ,definiteCategs, reflexiveReciprocalCategs, undefPronouns,possPronouns, personAccessor, anagraph, language);
1157 categ(type);
1158 // anaphora
1159 if (type=="other"
1160 || (type =="reflPron")
1161 || (resolveDefinites && type =="def")
1162 || (resolveN3PPronouns && type =="N3Ppron") )
1163 {
1164 res += 1;
1165 }
1166 // candidate
1167 if (type!="pleon" && (type!="N3Ppron" || resolveN3PPronouns) && type!="reflPron" && type!="on" && type!="undefPron")
1168 {
1169 res += 10;
1170 }
1171 return res;
1172}
1173
1175 const std::map<std::string,float>& weights,
1176 const SyntacticData* sd,
1177 const Common::PropertyCode::PropertyAccessor* macroAccessor,
1179 MediaId language,
1180 const std::map< std::string,LinguisticCode>& tagLocalDef,
1181 const std::map< std::string,std::deque<std::string> >& relLocalDef,
1182 AnalysisContent& ac,
1183 LinguisticGraphVertex& beginSentence,
1184 LinguisticGraphVertex& endSentence) const
1185 {
1186// COREFSOLVERLOGINIT;
1187 float res =0;
1188 if (weights.find("SentenceRecency")!=weights.end())
1189 {
1190 res += (*weights.find("SentenceRecency")).second;
1191 }
1192 if (weights.find("SubjEmph")!=weights.end() && isFunctionMasterOf(sd,(*relLocalDef.find("SubjectRelation")).second,language))
1193 {
1194 res += weights.find("SubjEmph")->second;
1195 }
1196 if (weights.find("ExistEmph")!=weights.end() && isFunctionMasterOf(sd,(*relLocalDef.find("AttributeRelation")).second,language))
1197 {
1198 res += weights.find("ExistEmph")->second;
1199 }
1200 if (weights.find("CodEmph")!=weights.end() && isFunctionMasterOf(sd,(*relLocalDef.find("CODRelation")).second,language))
1201 {
1202 res += weights.find("CodEmph")->second;
1203 }
1204 if (weights.find("CoiCoblEmph")!=weights.end() && isFunctionMasterOf(sd,(*relLocalDef.find("COIRelation")).second,language))
1205 {
1206 res += weights.find("CoiCoblEmph")->second;
1207 }
1208 if (m_morphVertex == npHeadVertex(sd,language, new set<DependencyGraphVertex>()))
1209 {
1210 res += weights.find("HeadEmph")->second;
1211 }
1212 if (weights.find("NonAdvEmph")!=weights.end() && !CoreferentAnnotation(0,npHeadVertex(sd,language, new set<DependencyGraphVertex>())).isFunctionMasterOf(sd,(*relLocalDef.find("AdjunctRelation")).second,language))
1213 {
1214 res += weights.find("NonAdvEmph")->second;
1215 }
1216 if (weights.find("IsInSubordinate")!=weights.end() && weights.find("IsInSubordinate")->second!=0 && isInSubordinate(sd,macroAccessor,tagLocalDef,language,anagraph,ac, new set<LinguisticGraphVertex>()))
1217 {
1218 res += weights.find("IsInSubordinate")->second;
1219 }
1220 Token* token = get(vertex_token, *anagraph->getGraph(), m_morphVertex);
1221// cerr << token->stringForm() <<endl;
1222 if (weights.find("NoAntecedencyPotential")!=weights.end() && weights.find("NoAntecedencyPotential")->second!=0 && token != 0 && limastring2utf8stdstring(token->stringForm()) == "y")
1223 {
1224 res += weights.find("NoAntecedencyPotential")->second;
1225 }
1226 if (weights.find("Appos")!=weights.end() && weights.find("Appos")->second!=0 && isInAppos(sd,anagraph,ac,language,new std::set<DependencyGraphVertex>()))
1227 {
1228 res += weights.find("Appos")->second;
1229 }
1230 if (weights.find("BeginWithColon")!=weights.end() && weights.find("BeginWithColon")->second!=0 && beginWithColon(anagraph,beginSentence))
1231 {
1232 res += weights.find("BeginWithColon")->second;
1233 }
1234 if (weights.find("EndWithColon")!=weights.end() && weights.find("EndWithColon")->second!=0 && endWithColon(anagraph,endSentence))
1235 {
1236 res += weights.find("EndWithColon")->second;
1237 }
1238 if (weights.find("AntecedencyPotential")!=weights.end() && weights.find("AntecedencyPotential")->second!=0 && isInQuantA(sd,anagraph))
1239 {
1240 res += weights.find("AntecedencyPotential")->second;
1241 }
1242 return res;
1243}
1244
1247 CoreferentAnnotation& antecedent) const
1248{
1250 LDEBUG << "CoreferentAnnotation::writeAnnotation " << m_morphVertex << " refering to " << antecedent.m_morphVertex;
1251
1252 std::set< AnnotationGraphVertex > matches = ad->matches("PosGraph",m_morphVertex,"annot");
1253 if (matches.empty())
1254 {
1256 LERROR << "CoreferentAnnotation::writeAnnotation No annotation graph vertex matches PoS graph vertex " << m_morphVertex << ". This should not happen.";
1257 return AnnotationGraphVertex();
1258 }
1259 AnnotationGraphVertex av = *matches.begin();
1260
1261
1263 {
1265 GenericAnnotation ga(*this);
1266
1267 ad->annotate(av, utf8stdstring2limastring("Coreferent"), ga);
1268 }
1269
1270 std::set< AnnotationGraphVertex > antecedentMatches = ad->matches("PosGraph",antecedent.m_morphVertex,"annot");
1271 if (antecedentMatches.empty())
1272 {
1274 LERROR << "CoreferentAnnotation::writeAnnotation No annotation graph vertex matches PoS graph antecedent vertex " << antecedent.m_morphVertex << ". This should not happen.";
1275 return AnnotationGraphVertex();
1276 }
1277 AnnotationGraphVertex antecedentAv = *antecedentMatches.begin();
1278
1279 if (!ad->hasAnnotation(antecedentAv, Common::Misc::utf8stdstring2limastring("Coreferent")))
1280 {
1282 GenericAnnotation ga(antecedent);
1283
1285 // AnnotationGraphVertex av = ad->createAnnotationVertex();
1286
1287 ad->annotate(antecedentAv, utf8stdstring2limastring("Coreferent"), ga);
1288 }
1289
1291 if (av!=antecedentAv)
1292 {
1293 ad->createAnnotationEdge(av, antecedentAv);
1294 }
1295 return AnnotationGraphVertex(); //unused;
1296}
1297
1299 Common::AnnotationGraphs::AnnotationData::Dumper(),
1300 m_ad(ad)
1301{
1302}
1303
1305{
1306 os << "#" << m_id << ";" << m_categ<< ";" /*<< "V:" << m_morphVertex */;
1307 CoreferentAnnotation antecedent;
1308 bool hasAntecedent = false;
1309 std::set< AnnotationGraphVertex > matches = ad->matches("PosGraph",m_morphVertex,"annot");
1310 if (matches.empty())
1311 {
1313 LERROR << "CoreferentAnnotation::dump No annotation graph vertex matches PoS graph vertex " << m_morphVertex << ". This should not happen.";
1314 return ;
1315 }
1316 AnnotationGraphVertex av = *matches.begin();
1317 AnnotationGraphOutEdgeIt it, it_end;
1318 boost::tie(it, it_end) = boost::out_edges(av, ad->getGraph());
1319 if (it != it_end)
1320 {
1321 for (; it != it_end; it++)
1322 {
1323 GenericAnnotation ga = ad->annotation(boost::target(*it, ad->getGraph()), utf8stdstring2limastring("Coreferent"));
1324 try
1325 {
1326 antecedent = ga.value<CoreferentAnnotation>();
1327 hasAntecedent = true;
1328 break;
1329 }
1330 catch (const boost::bad_any_cast& )
1331 {
1332 continue;
1333 }
1334 }
1335 }
1336 if (hasAntecedent)
1337 {
1338 os << "#" << antecedent.id();
1339 }
1340}
1341
1342void CoreferentAnnotation::outputXml(std::ostream& xmlStream,const LinguisticGraph& g, const AnnotationData* ad) const
1343{
1345 LDEBUG << "CoreferentAnnotation::outputXml";
1346 CoreferentAnnotation antecedent;
1347 bool hasAntecedent = false;
1348 std::set< AnnotationGraphVertex > matches = ad->matches("PosGraph",m_morphVertex,"annot");
1349 if (matches.empty())
1350 {
1352 LERROR << "CoreferentAnnotation::outputXml No annotation graph vertex matches PoS graph vertex " << m_morphVertex << ". This should not happen.";
1353 return ;
1354 }
1355 AnnotationGraphVertex av = *matches.begin();
1356 AnnotationGraphOutEdgeIt it, it_end;
1357 boost::tie(it, it_end) = boost::out_edges(av, ad->getGraph());
1358 if (it != it_end)
1359 {
1360 for (; it != it_end; it++)
1361 {
1362 GenericAnnotation ga = ad->annotation(target(*it, ad->getGraph()), utf8stdstring2limastring("Coreferent"));
1363 try
1364 {
1365 antecedent = ga.value<CoreferentAnnotation>();
1366 hasAntecedent = true;
1367 }
1368 catch (const boost::bad_any_cast& )
1369 {
1370 continue;
1371 }
1372 }
1373 }
1374 if (hasAntecedent)
1375 {
1376 xmlStream << "<COREF ID=\"" << m_id << "\" TYPE=\"IDENT\" REF=\"" << antecedent.id() << "\"";
1377 xmlStream << " SALIENCE=\"" << salience() << "\"";
1378 }
1379 else
1380 {
1381 xmlStream << "<COREF ID=\"" << m_id<<"\"";
1382 }
1383 xmlStream << " CATEG=\"" << categ() << "\">";
1384
1385 Token* token = get(vertex_token, g, m_morphVertex);
1386 if (token != 0)
1387 {
1388 xmlStream << token->stringForm().toStdString();
1389 if (token->status().isAlphaPossessive())
1390 {
1391 xmlStream << "'s ";
1392 }
1393 }
1394 xmlStream << "</COREF>";
1395}
1396
1397
1398} // closing namespace Coreferences
1399} // closing namespace LinguisticProcessing
1400} // closing namespace Lima
This file is the main header file for the data related to annotation graphs.
DependencyGraph::in_edge_iterator DependencyGraphInEdgeIt
DependencyGraph::out_edge_iterator DependencyGraphOutEdgeIt
DependencyGraph::vertex_descriptor DependencyGraphVertex
boost::property_map< DependencyGraph, edge_deprel_type_t >::const_type CEdgeDepRelTypePropertyMap
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, DepVertexProperties, DepEdgeProperties > DependencyGraph
The dependency graph class.
@ edge_deprel_type
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define PROCESSORSLOGINIT
Definition LimaCommon.h:211
boost::property_map< LinguisticGraph, vertex_data_t >::const_type CVertexDataPropertyMap
@ vertex_token
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
@ vertex_data
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
#define COREFSOLVERLOGINIT
#define L_NONE
Definition StdBitset.h:338
Data used for the syntactic analyzis of texts.
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
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.
const GenericAnnotation & annotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
AnnotationGraphEdge createAnnotationEdge(AnnotationGraphVertex s, AnnotationGraphVertex t)
Creates a new annotation edge in the graph.
This class allows to convert any object into an annotation by inheritance.
Holds linguistic data for one language.
const MediaData & mediaData(MediaId media) const
Provide function to read write and check a property.
LinguisticCode readValue(const LinguisticCode &code) const
read a property in a coded int.
static LinguisticCode fromUInt(uint64_t v)
Definition StdBitset.h:65
bool aba4(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, const Common::PropertyCode::PropertyAccessor *macroAccessor, const Common::PropertyCode::PropertyAccessor *microAccessor, MediaId language, const std::set< LinguisticCode > &inNpCategs, LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, const LinguisticCode &conjCoord, std::deque< Vertices > *npCandidates) const
bool endWithColon(const LinguisticAnalysisStructure::AnalysisGraph *anagraph, LinguisticGraphVertex &endSentence) const
int classify(LinguisticGraph *graph, SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *macroAccessor, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, const std::set< LinguisticCode > &definiteCategs, const std::set< LinguisticCode > &reflexiveReciprocalCategs, const std::set< LinguisticCode > &undefPronouns, const std::set< LinguisticCode > &possPronouns, const bool &resolveDefinites, const bool &resolveN3PPronouns, const Common::PropertyCode::PropertyAccessor *personAccessor, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, MediaId language)
main functions of the global algorithm (called by Corefsolver)
std::string referentType(const SyntacticAnalysis::SyntacticData *sd, const LinguisticGraph *g, const Common::PropertyCode::PropertyAccessor *macroAccessor, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, const std::set< LinguisticCode > &definiteCategs, const std::set< LinguisticCode > &reflexiveReciprocalCategs, const std::set< LinguisticCode > &undefPronounsCategs, const std::set< LinguisticCode > &possPronounsCategs, const Common::PropertyCode::PropertyAccessor *personAccessor, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, MediaId language) const
bool isTaggedAsOneOfThese(const LinguisticGraph *g, const std::set< LinguisticCode > &categs, const Common::PropertyCode::PropertyAccessor *microAccessor) const
bool isContainedIn(const DependencyGraphVertex &dv, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
bool isGovernedByMasculineCoordinate(const SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *genderAccessor, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
bool isInTheNpDomainOf(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
bool isDeterminer(DependencyGraphVertex *qv, const SyntacticAnalysis::SyntacticData *sd, const std::map< std::string, std::deque< std::string > > &relLocalDef, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
bool sf4(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *macroAccessor, const LinguisticCode &L_PRON, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
bool isInTheAdjunctDomainOf(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const LinguisticGraph *graph, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, MediaId language) const
void dump(std::ostream &os, const Lima::Common::AnnotationGraphs::AnnotationData *ad) const
float salienceWeighting(const std::map< std::string, float > &weights, const SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *macroAccessor, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, MediaId language, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, AnalysisContent &ac, LinguisticGraphVertex &beginSentence, LinguisticGraphVertex &endSentence) const
bool isInTheArgumentDomainOf(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, const Common::PropertyCode::PropertyAccessor *macroAccessor, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const LinguisticCode &conjCoord, std::set< LinguisticGraphVertex > *alreadyProcessed) const
virtual void outputXml(std::ostream &xmlStream, const LinguisticGraph &g, const Common::AnnotationGraphs::AnnotationData *ad) const
bool isInTheArgumentDomainOf2(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, const Common::PropertyCode::PropertyAccessor *macroAccessor, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const LinguisticCode &conjCoord, std::set< LinguisticGraphVertex > *alreadyProcessed) const
bool beginWithColon(const LinguisticAnalysisStructure::AnalysisGraph *anagraph, LinguisticGraphVertex &beginSentence) const
test functions for the salience weighting
bool isDefinite(const SyntacticAnalysis::SyntacticData *sd, const std::string &definiteRel, const std::set< LinguisticCode > &definiteCategs, const Common::PropertyCode::PropertyAccessor *microAccessor, MediaId language) const
test functions for the initial classification
AnnotationGraphVertex writeAnnotation(Common::AnnotationGraphs::AnnotationData *ad, CoreferentAnnotation &antecedent) const
bool isPronoun(const LinguisticGraph *g, const Common::PropertyCode::PropertyAccessor *macroAccessor, const LinguisticCode &L_PRON) const
test functions for the initial classification
bool isPleonastic(const SyntacticAnalysis::SyntacticData *sd, const std::string &m_pleonRel, MediaId language) const
bool isInThePrepAdjunctNP(const DependencyGraphVertex &qv, const SyntacticAnalysis::SyntacticData *sd, const LinguisticGraph *graph, const Common::PropertyCode::PropertyAccessor *microAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, MediaId language) const
bool isInSubordinate(const SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *macroAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, std::set< LinguisticGraphVertex > *alreadyProcessed) const
bool sf6(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const std::map< std::string, std::deque< std::string > > &relLocalDef, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
int getSlotValue(const SyntacticAnalysis::SyntacticData *sd, const std::map< std::string, std::deque< std::string > > &relLocalDef, const std::map< std::string, int > &slotValues, MediaId language) const
LinguisticGraphVertex npHeadVertex(const SyntacticAnalysis::SyntacticData *sd, MediaId language, std::set< DependencyGraphVertex > *alreadyProcessed) const
bool aba5(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const std::map< std::string, LinguisticCode > &tagLocalDef, const std::map< std::string, std::deque< std::string > > &relLocalDef, const Common::PropertyCode::PropertyAccessor *macroAccessor, const Common::PropertyCode::PropertyAccessor *microAccessor, MediaId language, LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, const std::map< std::string, int > &slotValues, const LinguisticCode &conjCoord) const
bool isConjCoord(const Common::PropertyCode::PropertyAccessor *microAccessor, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, const LinguisticCode &conjCoord) const
bool isAgreementCompatibleWith(const CoreferentAnnotation &ca, const SyntacticAnalysis::SyntacticData *sd, const Common::PropertyCode::PropertyAccessor *genderAccessor, const Common::PropertyCode::PropertyAccessor *personAccessor, const Common::PropertyCode::PropertyAccessor *numberAccessor, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac) const
bool isFunctionMasterOf(const SyntacticAnalysis::SyntacticData *sd, const std::deque< std::string > &macroDependencyRelation, MediaId language) const
returns true if *this governs a macroDependencyRelation (cf.
bool isVerb(const Common::PropertyCode::PropertyAccessor *macroAccessor, const std::map< std::string, LinguisticCode > &tagLocalDef, const LinguisticAnalysisStructure::AnalysisGraph *anagraph) const
test functions for the syntactic filter and the reflexive binding algorithm
bool isIncludedInNounPhrase(const LinguisticGraph *g, MediaId language, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, const std::set< LinguisticCode > &inNpCategs, const Common::PropertyCode::PropertyAccessor *microAccessor) const
general test functions
bool isInAppos(const SyntacticAnalysis::SyntacticData *sd, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, AnalysisContent &ac, MediaId language, std::set< DependencyGraphVertex > *alreadyProcessed) const
bool isInQuantA(const SyntacticAnalysis::SyntacticData *sd, const LinguisticAnalysisStructure::AnalysisGraph *anagraph) const
bool isN3PPronoun(const Common::PropertyCode::PropertyAccessor *personAccessor, const LinguisticAnalysisStructure::AnalysisGraph *anagraph) const
DumpCoreferent(const Lima::Common::AnnotationGraphs::AnnotationData *ad)
virtual int dump(std::ostream &os, Common::AnnotationGraphs::GenericAnnotation &ga) const override
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
LinguisticCode firstValue(const Common::PropertyCode::PropertyAccessor &propertyAccessor) const
Return the first non empty value for the given accessor.
This constraint tests if its argument is governed by a relation of the given type.
This constraint tests if its argument is the governor of a relation of the given type.
This constraint tests if the second argument is not governed by the first one with a relation of the ...
This class points to a graph, its dependency graph and the structure that holds the maping between th...
LinguisticGraphVertex tokenVertexForDepVertex(const DependencyGraphVertex &v) const
DependencyGraphVertex depVertexForTokenVertex(const LinguisticGraphVertex &v) const
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
AnnotationGraph::out_edge_iterator AnnotationGraphOutEdgeIt
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
void annotate(AnnotationGraphVertex v, const LimaString &annot, uint64_t value)
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)
NAUTITIA.
@ UNKNOWN_ERROR
Definition LimaCommon.h:238
@ SUCCESS_ID
Definition LimaCommon.h:237
QString LimaString
Definition LimaString.h:33
STL namespace.