LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
recognizerMatch.h
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file recognizerMatch.h
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Wed Oct 13 2004
11 * copyright Copyright (C) 2004 by CEA LIST
12 * Project Automaton
13 *
14 * @brief this class contains the result of the application of a rule on a text
15 *
16 *
17 ***********************************************************************/
18
19#ifndef RECOGNIZERMATCH_H
20#define RECOGNIZERMATCH_H
21
22#include "AutomatonExport.h"
24#include "entityProperties.h"
26#include <vector>
27
28namespace Lima {
29namespace LinguisticProcessing {
30namespace Automaton {
31
33 public:
35 MatchElement(const LinguisticGraphVertex& v, const bool isKept, const LimaString& ruleElemtId):
36 m_elem(std::make_pair(v,isKept)), m_ruleElemtId(ruleElemtId) {}
38 bool operator==(const MatchElement& m) {
39 return (m_elem.first==m.m_elem.first && m_elem.second==m.m_elem.second && m_ruleElemtId==m.m_ruleElemtId);
40 }
41 const LinguisticGraphVertex& getVertex() const { return m_elem.first; }
42 LinguisticGraphVertex& getVertex() { return m_elem.first; }
43 bool isKept() const { return m_elem.second; }
44 const LimaString& getRuleElemtId() const { return m_ruleElemtId; }
45
46 std::pair<LinguisticGraphVertex,bool> m_elem;
48};
49
50class RecognizerMatch;
51LIMA_AUTOMATON_EXPORT std::ostream& operator << (std::ostream&, const RecognizerMatch&);
52
54 public std::vector<MatchElement>,
55 public EntityProperties
56{
57 public:
60 const LinguisticGraphVertex& vertex,
61 const bool isKept);
63
64 // comparison operator
65 bool operator == (const RecognizerMatch&);
66
67 bool isContiguous() const;
68 bool hasDuplicateElements() const;
69 uint64_t positionBegin() const;
70 uint64_t positionEnd() const;
71 uint64_t length() const;
72
73 uint64_t numberOfElements() const; // number of *kept* elements
74
75 const LinguisticAnalysisStructure::AnalysisGraph* getGraph() const { return m_graph; }
76
77 LinguisticGraphVertex getEnd() const { return back().getVertex(); }
78 LinguisticGraphVertex getBegin() const { return front().getVertex(); }
79
80 bool BeginIs(const LinguisticGraphVertex& pi) const;
81 bool EndIs(const LinguisticGraphVertex& pi) const;
82
84 getToken(RecognizerMatch::iterator) const;
86 getToken(RecognizerMatch::const_iterator) const;
87
89 getData(RecognizerMatch::iterator) const;
91 getData(RecognizerMatch::const_iterator) const;
92
94 getHeadToken() const;
96 getHeadData() const;
97
98 void reinit();
99 void addBackVertex(const LinguisticGraphVertex&,bool isKept=true,const LimaString& ruleElementId="");
100 void addFrontVertex(const LinguisticGraphVertex&,bool isKept=true,const LimaString& ruleElementId="");
101 void popBackVertex();
102 void popFrontVertex();
103 void addBack(const RecognizerMatch& l);
104 void addFront(const RecognizerMatch& l);
105 void removeUnkeptAtExtremity();
106
107 LimaString getString() const;
108 LimaString concatString() const { return getString(); } // just an alias
109
110 LimaString getNormalizedString(const FsaStringsPool& sp) const;
111
112 // overlap based on positions
113 bool isOverlapping(const RecognizerMatch& otherMatch) const;
114
115 friend LIMA_AUTOMATON_EXPORT std::ostream& operator << (std::ostream&, const RecognizerMatch&);
116 friend LIMA_AUTOMATON_EXPORT QDebug& operator << (QDebug&, const RecognizerMatch&);
117
118 private:
120};
121
122//**********************************************************************
123// inline functions
124//**********************************************************************
125
127 return (front().getVertex()==pi);
128}
129inline bool RecognizerMatch::EndIs(const LinguisticGraphVertex& pi) const {
130 return (back().getVertex()==pi);
131}
132
134getToken(RecognizerMatch::iterator i) const {
135 return get(vertex_token,*(m_graph->getGraph()),(*i).getVertex());
136}
137
139getToken(RecognizerMatch::const_iterator i) const {
140 return get(vertex_token,*(m_graph->getGraph()),(*i).getVertex());
141}
142
144getData(RecognizerMatch::iterator i) const {
145 return get(vertex_data,*(m_graph->getGraph()),(*i).getVertex());
146}
147
149getData(RecognizerMatch::const_iterator i) const {
150 return get(vertex_data,*(m_graph->getGraph()),(*i).getVertex());
151}
152
154getHeadToken() const {
155 if (m_head==0) { return 0; }
156 return get(vertex_token,*(m_graph->getGraph()),m_head);
157}
159getHeadData() const {
160 if (m_head==0) { return 0; }
161 return get(vertex_data,*(m_graph->getGraph()),m_head);
162}
163
164} // end namespace
165} // end namespace
166} // end namespace
167
168#endif
#define LIMA_AUTOMATON_EXPORT
QDebug & operator<<(QDebug &qd, const std::string &str)
Definition QsLog.cpp:39
@ vertex_token
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
@ vertex_data
LinguisticGraphVertex m_head
indicates which token (in the original text) is the head of the recognized entity
std::pair< LinguisticGraphVertex, bool > m_elem
MatchElement(const LinguisticGraphVertex &v, const bool isKept, const LimaString &ruleElemtId)
const LinguisticGraphVertex & getVertex() const
bool EndIs(const LinguisticGraphVertex &pi) const
LinguisticAnalysisStructure::Token * getToken(RecognizerMatch::iterator) const
bool BeginIs(const LinguisticGraphVertex &pi) const
LinguisticAnalysisStructure::MorphoSyntacticData * getHeadData() const
const LinguisticAnalysisStructure::AnalysisGraph * getGraph() const
LinguisticAnalysisStructure::MorphoSyntacticData * getData(RecognizerMatch::iterator) const
LinguisticAnalysisStructure::Token * getHeadToken() const
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
std::ostream & operator<<(std::ostream &os, const DFFSPos &x)
NAUTITIA.
QString LimaString
Definition LimaString.h:33
STL namespace.