LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SentenceBoundariesTransfer.cpp
Go to the documentation of this file.
1// Copyright 2019 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
7#include "SegmentationData.h"
17
18using namespace Lima::Common::AnnotationGraphs;
21
22namespace Lima {
23namespace LinguisticProcessing {
24namespace LinguisticAnalysisStructure {
25
27
36
37
38SentenceBoundariesTransferPrivate::SentenceBoundariesTransferPrivate()
39{
40}
41
42
43SentenceBoundariesTransferPrivate::~SentenceBoundariesTransferPrivate()
44{
45}
46
47
53
54
59
61 GroupConfigurationStructure& unitConfiguration,
62 Manager* manager)
63{
64 LIMA_UNUSED(unitConfiguration);
65 LIMA_UNUSED(manager);
66}
67
68
70 AnalysisContent& analysis) const
71{
72 Lima::TimeUtilsController timer("SentenceBoundariesTransfer");
73
75 LINFO << "SentenceBoundariesTransfer::process start transfering sentence bounds from AnalysisGraph to PosGraph";
76
77 auto sb = static_cast<SegmentationData*>(analysis.getData("SentenceBoundaries").get());
78 if (sb == nullptr)
79 {
81 LERROR << "SentenceBoundariesTransfer::process no SentenceBounds";
82 return MISSING_DATA;
83 }
84 if (sb->getGraphId() == "PosGraph")
85 {
87 LINFO << "SentenceBoundariesTransfer: sentence bounds are already on PosGraph. Nothing to do.";
88 return SUCCESS_ID;
89 }
90
91 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("AnalysisGraph"));
92 if (anagraph == nullptr)
93 {
94 LERROR << "SentenceBoundariesTransfer::process no graph 'AnalysisGraph' available !";
95 return MISSING_DATA;
96 }
97 auto posgraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("PosGraph"));
98 if (posgraph == nullptr)
99 {
100 LERROR << "SentenceBoundariesTransfer::process no graph 'PosGraph' available !";
101 return MISSING_DATA;
102 }
103 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.getData("AnnotationData"));
104 if (annotationData == nullptr)
105 {
106 LERROR << "SentenceBoundariesTransfer::process: no annotation graph available !";
107 return MISSING_DATA;
108 }
109
110 auto newSb = new SegmentationData("PosGraph");
111 for (const auto& segment: sb->getSegments())
112 {
113 auto firstVxMatches = annotationData->matches("AnalysisGraph",
114 segment.getFirstVertex(),
115 "PosGraph");
116 if (segment.getFirstVertex() == 0)
117 firstVxMatches.insert(0);
118 if (firstVxMatches.empty())
119 {
120 LERROR << "SentenceBoundariesTransfer::process: no PoS graph vertex for segment first AnalysisGraph vextex"
121 << segment.getFirstVertex();
122 continue;
123 }
124 auto lastVxMatches = annotationData->matches("AnalysisGraph",
125 segment.getLastVertex(),
126 "PosGraph");
127 if (segment.getFirstVertex() == 1)
128 firstVxMatches.insert(1);
129 if (lastVxMatches.empty())
130 {
131 LERROR << "SentenceBoundariesTransfer::process: no PoS graph vertex for segment last AnalysisGraph vextex"
132 << segment.getLastVertex();
133 continue;
134 }
135 Segment newSegment("sentence", *firstVxMatches.begin(), *lastVxMatches.begin(), posgraph.get());
136 newSb->add(newSegment);
137 }
138
139 analysis.removeData("SentenceBoundaries");
140 analysis.setData("SentenceBoundaries", newSb);
141 return SUCCESS_ID;
142}
143
144
145}
146
147}
148
149}
This file is the main header file for the data related to annotation graphs.
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LINFO
Definition LimaCommon.h:158
#define LERROR
Definition LimaCommon.h:161
#define DUMPERLOGINIT
#define SEGMENTATIONLOGINIT
#define SENTENCEBOUNDARIESTRANSFER_CLASSID
Defines a Factory to create Object of type Base.
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
void removeData(const QString &id)
remove the analysisData with the given id
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
void setData(const QString &id, std::shared_ptr< AnalysisData > data)
set an analysisData with the given id.
Manage initialization of InitializableObjects using configuration module and parameters.
The pipeline unit transfers sentence boundaries found on the AnalysisGraph to tho PosGraph as request...
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
This file contains a class to control log of informations about time, such as logging cumulated time ...
SimpleFactory< MediaProcessUnit, SentenceBoundariesTransfer > sentenceBoundariesTransferFactory(SENTENCEBOUNDARIESTRANSFER_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ SUCCESS_ID
Definition LimaCommon.h:237
@ MISSING_DATA
Definition LimaCommon.h:243
launch exception related to the configuration file parsing