LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SegmentFeatureExtractor.h
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.h
9 * @author Romaric Besancon (romaric.besancon@cea.fr)
10 * @date Mon Feb 7 2011
11 * copyright Copyright (C) 2011 by CEA LIST
12 * Project LIMA
13 *
14 * @brief accessors for various features of a word
15 *
16 *
17 ***********************************************************************/
18
19#ifndef SEGMENTFEATUREEXTRACTOR_H
20#define SEGMENTFEATUREEXTRACTOR_H
21
23#include "SegmentationData.h"
26
27namespace Lima {
28namespace LinguisticProcessing {
29
30//----------------------------------------------------------------------
31// Abstract segment feature extractor class
33{
34public:
35 AbstractSegmentFeatureExtractor(MediaId language, const std::string& complement="");
37
38 virtual void update(const AnalysisContent& /*analysis*/) {}
39
40 virtual std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
41 const Segment& seg) const=0;
42 protected:
43 MediaId m_language;
44};
45
46//----------------------------------------------------------------------
47// Asbtract factory for abstract feature extractor
49 public RegistrableFactory<AbstractSegmentFeatureExtractorFactory>
50{
51public:
52 AbstractSegmentFeatureExtractorFactory(const std::string& factoryId);
53 virtual AbstractSegmentFeatureExtractor* create(MediaId language,const std::string& complement)=0;
54private:
55};
56
57//----------------------------------------------------------------------
58// template for factories for actual instances of feature extractors
59template<typename SegmentFeatureExtractor>
62{
63public:
64 SegmentFeatureExtractorFactory(const std::string& factoryId):
66 AbstractSegmentFeatureExtractor* create(MediaId language, const std::string& complement) override {
67 AbstractSegmentFeatureExtractor* newFeature=new SegmentFeatureExtractor(language, complement);
68 return newFeature;
69 }
70private:
71};
72
73//----------------------------------------------------------------------
74// a class for list of features
75//----------------------------------------------------------------------
76class SegmentFeatures : public std::vector<AbstractSegmentFeatureExtractor*> {
77public:
79 SegmentFeatures(MediaId language);
81
82 void setLanguage(MediaId language) { m_language=language; }
83 void initialize(const std::deque<std::string>& featureNames);
84 void update(const AnalysisContent& analysis);
85
86private:
87 MediaId m_language;
88};
89
90//----------------------------------------------------------------------
91// instances of feature extractors
92//----------------------------------------------------------------------
93// check if an entity of a given type exists in the segment
94#define SegmentFeaturePosition_ID "position"
96public:
97 SegmentFeaturePosition(MediaId language, const std::string& complement="");
99
100 void update(const AnalysisContent& analysis) override;
101
102 std::string
103 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
104 const Segment& seg) const override;
105private:
106 uint64_t m_offset;
107};
108
109#define SegmentFeatureLength_ID "length"
111public:
112 SegmentFeatureLength(MediaId language, const std::string& complement="");
114
115 void update(const AnalysisContent& analysis) override;
116
117 std::string
118 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
119 const Segment& seg) const override;
120private:
121};
122
123#define SegmentFeatureType_ID "type"
125public:
126 SegmentFeatureType(MediaId language, const std::string& complement="");
128
129 void update(const AnalysisContent& analysis) override;
130
131 std::string
132 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
133 const Segment& seg) const override;
134private:
135};
136
137
138} // end namespace
139} // end namespace
140
141#endif
#define LIMA_TEXTSEGMENTATION_EXPORT
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
virtual AbstractSegmentFeatureExtractor * create(MediaId language, const std::string &complement)=0
virtual std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph *graph, const Segment &seg) const =0
An AnalysisData containing a LinguisticGraph with a language and an id.
AbstractSegmentFeatureExtractor * create(MediaId language, const std::string &complement) override
void initialize(const std::deque< std::string > &featureNames)
void update(const AnalysisContent &analysis)
Defines a Factory that automatically register to a MainFactory singleton.
NAUTITIA.