LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SegmentFeatureExtractor.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 SegmentFeatureExtractor.cpp
9 * @author Romaric Besancon (romaric.besancon@cea.fr)
10 * @date Mon Feb 7 2011
11 * copyright Copyright (C) 2011 by CEA LIST
12 *
13 ***********************************************************************/
14
19#include <sstream>
20
21using namespace std;
22using namespace boost;
24
25
26namespace Lima {
27namespace LinguisticProcessing {
28
29
31AbstractSegmentFeatureExtractor(MediaId language, const std::string& /*complement*/)
32{
33 m_language=language;
34}
35
36//***********************************************************************
37// factories for feature extractors
43
47
48//***********************************************************************
49// Feature list
50//***********************************************************************
55
57m_language(language)
58{
59}
60
62{
63 for (SegmentFeatures::iterator it=begin(),it_end=end(); it!=it_end; it++) {
64 if (*it) {
65 delete (*it);
66 *it=0;
67 }
68 }
69}
70
71void SegmentFeatures::initialize(const deque<std::string>& featureNames)
72{
73 for (deque<std::string>::const_iterator it=featureNames.begin(),
74 it_end=featureNames.end();it!=it_end;it++)
75 {
76 string featureName=(*it);
77 string complement;
78 string::size_type i=featureName.find(":");
79 if (i!=string::npos) {
80 complement=string(featureName,i+1);
81 featureName=string(featureName,0,i);
82 }
83 push_back(SegmentFeaturePositionFactory.getFactory(featureName)->create(m_language,complement));
84 }
85}
86
88{
89 for (iterator it=begin(),it_end=end(); it!=it_end; it++) {
90 (*it)->update(analysis);
91 }
92}
93
94//***********************************************************************
95// Feature accessors
96//***********************************************************************
97SegmentFeaturePosition::SegmentFeaturePosition(MediaId language, const std::string& complement):
98AbstractSegmentFeatureExtractor(language,complement),
99m_offset(0)
100{}
101
103update(const AnalysisContent& analysis) {
104 // update offset from metadata
105 const LinguisticMetaData* metadata=static_cast<const LinguisticMetaData*>(analysis.getData("LinguisticMetaData").get());
106 if (metadata == 0) {
107 LOGINIT("LP::Segmentation");
108 LWARN << "no LinguisticMetaData ! abort";
109 }
110 else {
111 try {
112 m_offset=atoi(metadata->getMetaData("StartOffset").c_str());
113 }
115 // do nothing: not set in analyzeText (only in analyzeXmlDocuments)
116 }
117 }
118}
119
121getValue(const AnalysisGraph* /*graph*/,
122 const Segment& seg) const
123{
124 ostringstream oss;
125 oss << m_offset+seg.getPosBegin();
126 return oss.str();
127}
128
129//***********************************************************************
130SegmentFeatureLength::SegmentFeatureLength(MediaId language, const std::string& complement):
131AbstractSegmentFeatureExtractor(language,complement)
132{
133}
134
136update(const AnalysisContent& /*analysis*/) {
137}
138
140getValue(const AnalysisGraph* /*graph*/,
141 const Segment& seg) const
142{
143 ostringstream oss;
144 oss << seg.getLength();
145 return oss.str();
146}
147
148//***********************************************************************
149SegmentFeatureType::SegmentFeatureType(MediaId language, const std::string& complement):
150AbstractSegmentFeatureExtractor(language,complement)
151{
152}
153
155update(const AnalysisContent& /*analysis*/) {
156}
157
159getValue(const AnalysisGraph* /*graph*/,
160 const Segment& seg) const
161{
162 return seg.getType();
163}
164
165} // end namespace
166} // end namespace
#define LWARN
Definition LimaCommon.h:160
#define LOGINIT(X)
Definition LimaCommon.h:187
#define SegmentFeatureType_ID
#define SegmentFeaturePosition_ID
#define SegmentFeatureLength_ID
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
AbstractSegmentFeatureExtractor(MediaId language, const std::string &complement="")
An AnalysisData containing a LinguisticGraph with a language and an id.
contains metadata to be kept during the analysis: global generic metadata: file name,...
const std::string & getMetaData(const std::string &id) const
void update(const AnalysisContent &analysis) override
std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph *graph, const Segment &seg) const override
SegmentFeatureLength(MediaId language, const std::string &complement="")
void update(const AnalysisContent &analysis) override
std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph *graph, const Segment &seg) const override
SegmentFeaturePosition(MediaId language, const std::string &complement="")
void update(const AnalysisContent &analysis) override
std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph *graph, const Segment &seg) const override
SegmentFeatureType(MediaId language, const std::string &complement="")
void initialize(const std::deque< std::string > &featureNames)
void update(const AnalysisContent &analysis)
const std::string & getType() const
Defines a Factory that automatically register to a MainFactory singleton.
SegmentFeatureExtractorFactory< SegmentFeatureType > SegmentFeatureTypeFactory(SegmentFeatureType_ID)
SegmentFeatureExtractorFactory< SegmentFeatureLength > SegmentFeatureLengthFactory(SegmentFeatureLength_ID)
SegmentFeatureExtractorFactory< SegmentFeaturePosition > SegmentFeaturePositionFactory(SegmentFeaturePosition_ID)
NAUTITIA.
STL namespace.