LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
BoWFeatureExtractor.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 Tue Feb 12 2013
9 * @brief accessors for various features of a word, stored in a BoW format
10 * (same features as the WordFeatureExtractors)
11 ***********************************************************************/
12
13#ifndef BOWFEATUREEXTRACTOR_H
14#define BOWFEATUREEXTRACTOR_H
15
20
21namespace Lima {
22namespace LinguisticProcessing {
23
24//----------------------------------------------------------------------
25// Abstract feature extractor class
26//
27// BoW feature extractors are needed for generic dumper because compounds are stored in
28// BoWTerm and we need compatible feature extractors on LinguisticVertex and on BoWTerm
29// to have a similar output for both
31{
32public:
33 AbstractBoWFeatureExtractor(MediaId language, const std::string& complement="");
35
36 virtual std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const=0;
37 const std::string& getName() { return m_name; }
38 void setName(const std::string& name) { m_name=name; }
39
40protected:
41 MediaId m_language;
42 std::string m_name;
43};
44
45//----------------------------------------------------------------------
46// Asbtract factory for abstract feature extractor
48 public RegistrableFactory<AbstractBoWFeatureExtractorFactory>
49{
50public:
51 AbstractBoWFeatureExtractorFactory(const std::string& factoryId);
52 virtual AbstractBoWFeatureExtractor* create(MediaId language, const std::string& complement="")=0;
53private:
54};
55
56//----------------------------------------------------------------------
57// template for factories for actual instances of feature extractors
58template<typename BoWFeatureExtractor>
61{
62public:
63 BoWFeatureExtractorFactory(const std::string& factoryId):
65 AbstractBoWFeatureExtractor* create(MediaId language, const std::string& complement="") override {
66 AbstractBoWFeatureExtractor* newFeature=new BoWFeatureExtractor(language,complement);
67 return newFeature;
68 }
69private:
70};
71
72//----------------------------------------------------------------------
73// a class for list of features
74//----------------------------------------------------------------------
75class LIMA_ANALYSISDUMPERS_EXPORT BoWFeatures : public std::vector<AbstractBoWFeatureExtractor*> {
76public:
78 BoWFeatures(MediaId language);
80
81 void setLanguage(MediaId language) { m_language=language; }
82 void initialize(const std::deque<std::string>& featureNames);
83private:
84 MediaId m_language;
85};
86
87//----------------------------------------------------------------------
88// instances of feature extractors
89//----------------------------------------------------------------------
90#define BoWFeaturePosition_ID "position"
92public:
93 BoWFeaturePosition(MediaId language,const std::string& complement="");
95
96 std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const override;
97};
98
99//----------------------------------------------------------------------
100#define BoWFeatureToken_ID "word"
102public:
103 BoWFeatureToken(MediaId language,const std::string& complement="");
105
106 std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const override;
107};
108
109//----------------------------------------------------------------------
110#define BoWFeatureInflectedForm_ID "inflectedForm"
112public:
113 BoWFeatureInflectedForm(MediaId language,const std::string& complement="");
115
116 std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const override;
117};
118
119//----------------------------------------------------------------------
120#define BoWFeatureLemma_ID "lemma"
122public:
123 BoWFeatureLemma(MediaId language,const std::string& complement="");
125
126 std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const override;
127private:
128};
129
130//----------------------------------------------------------------------
131#define BoWFeatureProperty_ID "property"
133public:
134 BoWFeatureProperty(MediaId language, const std::string& complement="");
136
137 std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const override;
138
139private:
140 std::string m_propertyName;
141 const Common::PropertyCode::PropertyAccessor* m_propertyAccessor;
142 const Common::PropertyCode::PropertyManager* m_propertyManager;
143};
144
145//----------------------------------------------------------------------
146#define BoWFeatureTstatus_ID "tstatus"
148public:
149 BoWFeatureTstatus(MediaId language,const std::string& complement="");
151
152 std::string getValue(const Common::BagOfWords::AbstractBoWElement* token) const override;
153};
154
155} // end namespace
156} // end namespace
157
158#endif
#define LIMA_ANALYSISDUMPERS_EXPORT
This class is the abstract base class of all elements that can be stored in a BoWText.
Provide function to read write and check a property.
Provide tools to manage a specific property.
virtual AbstractBoWFeatureExtractor * create(MediaId language, const std::string &complement="")=0
virtual std::string getValue(const Common::BagOfWords::AbstractBoWElement *token) const =0
AbstractBoWFeatureExtractor * create(MediaId language, const std::string &complement="") override
Defines a Factory that automatically register to a MainFactory singleton.
NAUTITIA.