LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
entityTransition.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/*************************************************************************
7 *
8 * @file entityTransition.cpp
9 * @author Romaric Besancon (besanconr@zoe.cea.fr)
10 * @date Fri Jul 28 2006
11 * copyright (c) 2006 by CEA
12 *
13 *************************************************************************/
14
15
16#include "entityTransition.h"
21
22using namespace std;
24using namespace Lima::Common::MediaticData;
25using namespace Lima::Common::AnnotationGraphs;
27
28namespace Lima {
29namespace LinguisticProcessing {
30namespace Automaton {
31
32/***********************************************************************/
33// initialization of static members
34LimaString EntityTransition::m_entityAnnotation=Common::Misc::utf8stdstring2limastring("SpecificEntity");
35
36/***********************************************************************/
37// constructors
38/***********************************************************************/
41m_entityType()
42{
43}
44
46TransitionUnit(keep),
47m_entityType(type)
48{
49}
50
52
53std::string EntityTransition::printValue() const {
54 ostringstream oss;
55 oss << "entityT_" << m_entityType;
56 return oss.str();
57}
58
59/***********************************************************************/
60// operators ==
61/***********************************************************************/
63 if ( (type() == tright.type())
64 && (m_entityType == static_cast<const EntityTransition&>(tright).entityType())
65 ) {
66 return compareProperties(tright);
67 }
68 else {
69 return false;
70 }
71}
72
75 const LinguisticGraphVertex& v,
76 AnalysisContent& analysis,
79{
80 // should compare to vertex ?
81 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.getData("AnnotationData"));
82 if (annotationData==0) {
84 LDEBUG << "no annotation graph available !";
85 return false;
86 }
87
88 // find annotationGraphVertex matching the vertex of the current graph
89 std::set<AnnotationGraphVertex> matches = annotationData->matches(graph.getGraphId(), v, "annot");
90 //
91 if (! matches.empty())
92 {
93 AnnotationGraphVertex annotVertex = *(matches.begin());
94 if (annotationData->hasAnnotation(annotVertex, m_entityAnnotation))
95 {
96 const SpecificEntityAnnotation* se =
97 annotationData->annotation(annotVertex, m_entityAnnotation).
98 pointerValue<SpecificEntityAnnotation>();
99
100#ifdef DEBUG_LP
101 AULOGINIT;
102 LDEBUG << "EntityTransition: compare entity types " << m_entityType << " and " << se->getType();
103#endif
104 if (m_entityType == se->getType() || Common::MediaticData::MediaticData::single().isEntityAncestor(se->getType(),m_entityType))
105 {
106 return true;
107 }
108 }
109 }
110
111 // special case, if graph is posgraph, check if vertex corresponds to a specific entity found before pos tagging (i.e. in analysis graph)
112 if (graph.getGraphId()=="PosGraph") {
113
114 std::set< AnnotationGraphVertex > anaVertices = annotationData->matches("PosGraph",v,"AnalysisGraph");
115 // note: anaVertices size should be 0 or 1
116 for (const auto& anaVertex : anaVertices) {
117
118 std::set< AnnotationGraphVertex > matches = annotationData->matches("AnalysisGraph",anaVertex,"annot");
119
120 for (const auto& vx: matches)
121 {
122 if (annotationData->hasAnnotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")))
123 {
124 const SpecificEntityAnnotation* se =
125 annotationData->annotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")).
126 pointerValue<SpecificEntityAnnotation>();
127
128 if (m_entityType == se->getType() || Common::MediaticData::MediaticData::single().isEntityAncestor(se->getType(),m_entityType))
129 {
130 return true;
131 }
132 }
133 }
134 }
135 }
136 return false;
137}
138
139} // namespace end
140} // namespace end
141} // namespace end
This file is the main header file for the data related to annotation graphs.
#define LDEBUG
Definition LimaCommon.h:157
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
#define AULOGINIT
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
bool isEntityAncestor(const EntityType &child, const EntityType &parent) const
bool compare(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &vertex, AnalysisContent &analysis, const LinguisticAnalysisStructure::Token *token, const LinguisticAnalysisStructure::MorphoSyntacticData *data) const override
comparison of the transition with a token : can use the graph and vertex info, associated with genera...
Common::MediaticData::EntityType entityType() const
bool operator==(const TransitionUnit &) const override
bool compareProperties(const TransitionUnit &t) const
An AnalysisData containing a LinguisticGraph with a language and an id.
A representation of a specific entity to store in the annotation graph.
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
LimaString utf8stdstring2limastring(const std::string &src)
NAUTITIA.
QString LimaString
Definition LimaString.h:33
STL namespace.