LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SemanticRelationData.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
25
26using namespace Lima::LinguisticProcessing;
29using namespace Lima::Common::AnnotationGraphs;
30using namespace Lima::Common::MediaticData;
34using namespace boost;
35
36namespace Lima{
37namespace LinguisticProcessing{
38namespace SemanticAnalysis{
39
41 m_relations()
42{
43
44
45}
46
47
49{
50 m_relations.clear();
51}
52
53
55 const LinguisticGraphVertex& v2,
56 const std::string semanticRelationType)
57{
58#ifdef DEBUG_LP
60#endif
61 SemanticRelation r = SemanticRelation(v1,v2,semanticRelationType);
62 if (m_relations.find(r)==m_relations.end())
63 {
64#ifdef DEBUG_LP
65 LDEBUG << "SemanticRelationData::relation(" << v1 << "," << v2 << ","
66 << semanticRelationType << ") adding";
67#endif
68 m_relations.insert(r);
69 }
70 else
71 {
72#ifdef DEBUG_LP
73 LDEBUG << "SemanticRelationData::relation(" << v1 << "," << v2 << ","
74 << semanticRelationType << ") already found. Do not add it";
75#endif
76 }
77 return true;
78}
79
81{
82#ifdef DEBUG_LP
84#endif
85 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.getData("AnnotationData"));
86
87 if (annotationData->dumpFunction("SemanticRelation") == 0)
88 {
89 annotationData->dumpFunction("SemanticRelation",
91 }
92 auto recoData = std::dynamic_pointer_cast<RecognizerData>(analysis.getData("RecognizerData"));
93
94 for (auto i = m_relations.begin(); i != m_relations.end(); i++)
95 {
96 LinguisticGraphVertex vertex1 = i->get<0>();
97 LinguisticGraphVertex vertex2 = i->get<1>();
98
99 auto matchesVtx1 = annotationData->matches(recoData->getGraphId(),
100 vertex1,
101 "annot");
102 auto matchesVtx2 = annotationData->matches(recoData->getGraphId(),
103 vertex2,
104 "annot");
105
106 if (!annotationData->hasAnnotation(*(matchesVtx1.begin()),
107 *(matchesVtx2.begin()),
108 "SemanticRelation"))
109 {
110 SemanticRelationAnnotation annot(i->get<2>());
111 GenericAnnotation ga(annot);
112 annotationData->annotate(*(matchesVtx1.begin()),
113 *(matchesVtx2.begin()),
114 "SemanticRelation",
115 ga);
116 }
117 else
118 {
119 auto annot = annotationData->annotation(*(matchesVtx1.begin()),
120 *(matchesVtx2.begin()),
121 "SemanticRelation").pointerValue<SemanticRelationAnnotation>();
123 LWARN << "SemanticRelationData::addRelations There is already a SemanticRelation between"
124 << *(matchesVtx1.begin()) << "and" << *(matchesVtx2.begin()) << annot->type();
125 LWARN << "Adding new type" << i->get<2>();
126 QString type = QString::fromUtf8(annot->type().c_str());
127 QStringList typeList = type.split(',');
128 typeList << i->get<2>().c_str();
129 typeList.sort();
130 typeList.removeDuplicates();
131 annot->type(typeList.join(',').toUtf8().constData());
132 LWARN << "Adding type is now" << annot->type();
133 }
134 }
135 m_relations.clear();
136 return true;
137}
138
139
140
141}
142}
143}
This file is the main header file for the data related to annotation graphs.
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
#define SEMANTICANALYSISLOGINIT
Data used for Semantic Relation Annotation.
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
This class allows to convert any object into an annotation by inheritance.
An annotation between two annotation graph vertices denoting the semantic relation(s) holding between...
bool addRelations(AnalysisContent &analysis)
add SemanticRelation instance in the annotationGraph
bool relation(const LinguisticGraphVertex &v1, const LinguisticGraphVertex &v2, const std::string semanticRelationType)
Stores SemanticRelation.
NAUTITIA.