LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
WordFeatureExtractor.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 * @author Romaric Besancon (romaric.besancon@cea.fr)
8 * @date Mon Feb 7 2011
9 * copyright Copyright (C) 2011 by CEA LIST
10 * @brief accessors for various features of a word
11 ***********************************************************************/
12
13#ifndef WORDFEATUREEXTRACTOR_H
14#define WORDFEATUREEXTRACTOR_H
15
20
21namespace Lima {
22namespace LinguisticProcessing {
23
24//----------------------------------------------------------------------
25// Abstract feature extractor class
27{
28public:
29 AbstractFeatureExtractor(MediaId language, const std::string& complement="");
31
32 virtual std::string
34 LinguisticGraphVertex v, AnalysisContent &analysis) const=0;
35 const std::string& getName() { return m_name; }
36 void setName(const std::string& name) { m_name=name; }
37
38protected:
39 MediaId m_language;
40 std::string m_name;
41};
42
43//----------------------------------------------------------------------
44// Asbtract factory for abstract feature extractor
46 public RegistrableFactory<AbstractFeatureExtractorFactory>
47{
48public:
49 AbstractFeatureExtractorFactory(const std::string& factoryId);
50 virtual AbstractFeatureExtractor* create(MediaId language, const std::string& complement="")=0;
51private:
52};
53
54//----------------------------------------------------------------------
55// template for factories for actual instances of feature extractors
56template<typename FeatureExtractor>
59{
60public:
61 FeatureExtractorFactory(const std::string& factoryId):
63 AbstractFeatureExtractor* create(MediaId language, const std::string& complement="") override {
64 AbstractFeatureExtractor* newFeature=new FeatureExtractor(language,complement);
65 return newFeature;
66 }
67private:
68};
69
70//----------------------------------------------------------------------
71// a class for list of features
72//----------------------------------------------------------------------
73class LIMA_ANALYSISDUMPERS_EXPORT WordFeatures : public std::vector<AbstractFeatureExtractor*> {
74public:
76 WordFeatures(MediaId language);
78
79 void setLanguage(MediaId language) { m_language=language; }
80 void initialize(const std::deque<std::string>& featureNames);
81private:
82 MediaId m_language;
83};
84
85//----------------------------------------------------------------------
86// instances of feature extractors
87//----------------------------------------------------------------------
88#define FeaturePosition_ID "position"
90public:
91 FeaturePosition(MediaId language,const std::string& complement="");
93
94 std::string
97 AnalysisContent & ) const override;
98};
99
100//----------------------------------------------------------------------
101#define FeatureToken_ID "word"
103public:
104 FeatureToken(MediaId language,const std::string& complement="");
106
107 std::string
108 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
111 ) const override;
112};
113
114//----------------------------------------------------------------------
115// inflectedForm is different from word: word is the token in the text, inflectedForm is the inflected form in the dictionary
116// (e.g. possible corrections on accents)
117#define FeatureInflectedForm_ID "inflectedForm"
119public:
120 FeatureInflectedForm(MediaId language,const std::string& complement="");
122
123 std::string
124 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
127 ) const override;
128private:
129 const FsaStringsPool* m_sp;
130};
131
132//----------------------------------------------------------------------
133#define FeatureLemma_ID "lemma"
135public:
136 FeatureLemma(MediaId language,const std::string& complement="");
138
139 std::string
140 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
143 ) const override;
144private:
145 const FsaStringsPool* m_sp;
146};
147
148//----------------------------------------------------------------------
149#define FeatureProperty_ID "property"
151public:
152 FeatureProperty(MediaId language, const std::string& complement="");
154
155 std::string
156 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
159 ) const override;
160private:
161 std::string m_propertyName;
162 const Common::PropertyCode::PropertyAccessor* m_propertyAccessor;
163 const Common::PropertyCode::PropertyManager* m_propertyManager;
164};
165
166//----------------------------------------------------------------------
167#define FeatureTstatus_ID "tstatus"
169public:
170 FeatureTstatus(MediaId language,const std::string& complement="");
172
173 std::string
174 getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
177 ) const override;
178};
179
180//--------------------------------------------------------
181#define FeatureSpecificEntity_ID "specificEntity"
183{
184 public:
185 FeatureSpecificEntity(MediaId language, const std::string& complement="");
187
188 std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
190 AnalysisContent &) const override;
191};
192
193//--------------------------------------------------------
194#define FeatureLemmaSpecificEntity_ID "lemmaSpecificEntity"
196{
197public:
198 FeatureLemmaSpecificEntity(MediaId language, const std::string& complement="");
200
201 std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
203 AnalysisContent &) const override;
204};
205
206//--------------------------------------------------------
207#define FeatureStoredData_ID "storedData"
209{
210public:
211 FeatureStoredData(MediaId language, const std::string& complement="");
213
214 std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph* graph,
216 AnalysisContent &) const override;
217};
218
219} // end namespace
220} // end namespace
221
222#endif
#define LIMA_ANALYSISDUMPERS_EXPORT
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
Provide function to read write and check a property.
Provide tools to manage a specific property.
virtual AbstractFeatureExtractor * create(MediaId language, const std::string &complement="")=0
virtual std::string getValue(const LinguisticAnalysisStructure::AnalysisGraph *graph, LinguisticGraphVertex v, AnalysisContent &analysis) const =0
AbstractFeatureExtractor * create(MediaId language, const std::string &complement="") override
An AnalysisData containing a LinguisticGraph with a language and an id.
Defines a Factory that automatically register to a MainFactory singleton.
NAUTITIA.