LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
FsaAccessReader16.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 compactDict.h - description
8 -------------------
9 begin : mer mai 28 2003
10 copyright : (C) 2003 by Olivier Mesnard
11 email : olivier.mesnard@cea.fr
12 ***************************************************************************/
13
14/***************************************************************************
15 * *
16 * Compact dictionnary based on finite state automata implemented with *
17 * Boost Graph library. *
18 * Algorithm is described in article from Daciuk, Mihov, Watson & Watson: *
19 * "Incremental Construction of Minimal Acyclic Finite State Automata" *
20 * How to use it to compute hash code is explained in 'perfect hashing' *
21 * of document http://odur.let.rug.nl/alfa/fsa_stuff/#PerfHash *
22 * *
23 ***************************************************************************/
24
25#ifndef FSA_ACCESS_READER16_HPP
26#define FSA_ACCESS_READER16_HPP
27
28#include <iostream>
29#include <vector>
30#include <string>
31#include <deque>
32#include <boost/config.hpp>
33#include <boost/graph/adjacency_list.hpp>
34#include <boost/config.hpp>
35//#include <boost/graph/depth_first_search.hpp>
36//#include <boost/range/irange.hpp>
37#include <boost/pending/indirect_cmp.hpp>
38
42#include "FsaExceptions.h"
43#include "PrefixIterator.h"
44#include "FsaAccess16.h"
45
46namespace Lima {
47namespace Common {
48namespace FsaAccess {
49
50// forward declaration of FsaAccessReader16 for iterator
51template <typename graphType>
52class FsaAccessReader16;
53
54template <typename graphType>
56// friend std::ostream& operator<<(std::ostream& os, const iterator_context<graphType>& t);
57public:
58 void print(std::ostream& os) const;
59 typename boost::graph_traits<graphType>::out_edge_iterator out_edge;
60 typename boost::graph_traits<graphType>::out_edge_iterator out_edge_end;
62 int32_t wordPos;
63 int32_t word_length;
64 int32_t wordOffset;
65};
66
67template <typename graphType>
69// friend std::ostream& operator<<(std::ostream& os, const iterator_context<graphType>& t);
70public:
71 void print(std::ostream& os) const;
72 typename boost::graph_traits<graphType>::out_edge_iterator out_edge;
73 typename boost::graph_traits<graphType>::out_edge_iterator out_edge_end;
75 int32_t wordPos;
76 int32_t word_length;
77 int32_t wordOffset;
78 unsigned int nbError;
79 unsigned int nbSuccess;
81};
82
83// class iterator for FsaAccessReader::superWords() output
84template <typename graphType>
86// typedef selected_graph_types16::spareGraphType graphType;
87 public:
89 typename boost::graph_traits<graphType>::vertex_descriptor node,
90 const LimaString &prefix );
92 const LimaString &prefix);
95 const LimaString operator*() const override;
97 bool operator==(const AbstractSuperWordIterator& it) const override;
98 bool operator!=(const AbstractSuperWordIterator& it) const override;
99 virtual ClonableSuperWordIterator* clone() const override;
100 private:
101 typename boost::graph_traits<graphType>::vertex_descriptor m_curr;
102 std::deque<iterator_context<graphType> > m_context_stack;
103 const FsaAccessReader16<graphType> & m_dico;
104 const graphType & m_graph;
105 const LimaString m_prefix;
106 LimaString m_suffix;
107};
108
109// class iterator for FsaAccessReader::subWords() output
110template <typename graphType>
112// typedef selected_graph_types16::spareGraphType graphType;
113 public:
116 const LimaString &word);
118 const LimaString &word,
119 typename boost::graph_traits<graphType>::vertex_descriptor node,
120 const uint64_t offset );
122 const std::pair<uint64_t, uint64_t> operator*() const override;
124 bool operator==(const AbstractSubWordIterator& it) const override;
125 bool operator!=(const AbstractSubWordIterator& it) const override;
126 virtual ClonableSubWordIterator* clone() const override;
127 private:
129 // TODO: supress m_dico (when getVprop() )will be supressed
130 const FsaAccessReader16<graphType> & m_dico;
131 const graphType & m_graph;
132 PrefixIterator* m_prefixIt;
133 typename boost::graph_traits<graphType>::vertex_descriptor m_curr;
134 uint64_t m_index;
135};
136
137// class iterator for FsaAccessReader::superWords() output
138template <typename graphType>
140// typedef selected_graph_types16::spareGraphType graphType;
141 public:
143 typename boost::graph_traits<graphType>::vertex_descriptor nbMaxError,
144 const LimaString &word );
146 const ApproxSuggestion operator*() const override;
148 bool operator==(const AbstractApproxWordIterator& it) const override;
149 bool operator!=(const AbstractApproxWordIterator& it) const override;
150 virtual ClonableApproxWordIterator* clone() const override;
151 private:
153 typename boost::graph_traits<graphType>::vertex_descriptor m_curr;
154 std::deque<iterator_context<graphType> > m_context_stack;
155 const FsaAccessReader16<graphType> & m_dico;
156 const graphType & m_graph;
157 const LimaString m_prefix;
158 LimaString m_suffix;
159 std::multimap<unsigned int,ApproxSuggestion> suggestions;
160 std::multimap<std::pair<unsigned int,unsigned int>,approx_iterator_context<graphType> > contextes;
161};
162
163
164
165//template <typename graphType, typename LimaChar>
166template <typename graphType>
168 public FsaAccess16<graphType> {
169 friend class fsaReader_superword_iterator16<graphType>;
170 friend class fsaReader_subword_iterator16<graphType>;
171
172 public:
173 FsaAccessReader16(bool trie_direction_fwd);
175 // implementation of public operation defined in interface AbstractAccessByString
176 virtual uint64_t getSize() const override;
177 virtual uint64_t getIndex(const LimaString & word ) const override;
178 virtual std::pair< AccessSuperWordIterator, AccessSuperWordIterator >
179 getSuperWords(const LimaString & word ) const override;
180 virtual std::pair<AccessSubWordIterator,AccessSubWordIterator >
181 getSubWords(const uint64_t offset,
182 const LimaString & word ) const override;
183
184 // public optional operation in interface AbstractEnhancedAccess
185 LimaString getSpelling(const uint64_t index ) const override;
186
187 LimaString getExtent(const LimaString & prefix ) const;
188
189 // for IO
190 void read ( const std::string & filename );
191 void read ( std::istream& is );
193 protected:
195 uint64_t buildHash();
196 int computeHash( typename boost::graph_traits<graphType>::vertex_descriptor from );
197 uint64_t m_size;
198 private:
199 typename boost::graph_traits<graphType>::vertex_descriptor
200 getStartNode(const LimaString& word ) const;
201};
202
203} // namespace FsaAccess
204} // namespace Common
205} // namespace Lima
206
207/*
208template <typename graphType>
209std::ostream& operator<<(std::ostream& os, const Common::FsaAccess::iterator_context<graphType>& t);
210*/
211
212#include "common/FsaAccess/FsaAccessReader16.tcc"
213
214#endif //FSA_ACCESS_READER16_HPP
define abstract interface for access method
defines abstract interface for iterators on superwords
defines abstract interface for iterators on subwords
defines abstract interface for iterators on superwords
clonable approxworditerator specificapproxworditerator for a specific access method should inherits f...
clonable subworditerator specific subworditerator for a specific access method should inherits from t...
clonable superworditerator specific superworditerator for a specific access method should inherits fr...
LimaString getExtent(const LimaString &prefix) const
virtual uint64_t getSize() const override
gives the number of entries
void read(const std::string &filename)
virtual std::pair< AccessSuperWordIterator, AccessSuperWordIterator > getSuperWords(const LimaString &word) const override
void read(AbstractFsaAccessIStreamWrapper &iw)
FsaAccessReader16(bool trie_direction_fwd)
virtual std::pair< AccessSubWordIterator, AccessSubWordIterator > getSubWords(const uint64_t offset, const LimaString &word) const override
LimaString getSpelling(const uint64_t index) const override
get string from index
void read(FsaAccessDataInputHandler &is)
virtual uint64_t getIndex(const LimaString &word) const override
int computeHash(typename boost::graph_traits< graphType >::vertex_descriptor from)
boost::graph_traits< graphType >::out_edge_iterator out_edge
boost::graph_traits< graphType >::out_edge_iterator out_edge_end
bool operator!=(const AbstractApproxWordIterator &it) const override
fsaReader_approx_iterator16(const FsaAccessReader16< graphType > &dico, typename boost::graph_traits< graphType >::vertex_descriptor nbMaxError, const LimaString &word)
fsaReader_approx_iterator16(const FsaAccessReader16< graphType > &dico)
bool operator==(const AbstractApproxWordIterator &it) const override
virtual ClonableApproxWordIterator * clone() const override
const ApproxSuggestion operator*() const override
fsaReader_approx_iterator16 & operator++(int) override
const std::pair< uint64_t, uint64_t > operator*() const override
gives subword data.
fsaReader_subword_iterator16(const FsaAccessReader16< graphType > &dico, const LimaString &word, typename boost::graph_traits< graphType >::vertex_descriptor node, const uint64_t offset)
bool operator==(const AbstractSubWordIterator &it) const override
fsaReader_subword_iterator16 & operator++(int) override
fsaReader_subword_iterator16(const fsaReader_subword_iterator16 &iter)
bool operator!=(const AbstractSubWordIterator &it) const override
fsaReader_subword_iterator16(const FsaAccessReader16< graphType > &dico, const LimaString &word)
virtual ClonableSubWordIterator * clone() const override
fsaReader_superword_iterator16(const FsaAccessReader16< graphType > &dico, typename boost::graph_traits< graphType >::vertex_descriptor node, const LimaString &prefix)
fsaReader_superword_iterator16 & operator=(const fsaReader_superword_iterator16 &)=delete
bool operator!=(const AbstractSuperWordIterator &it) const override
fsaReader_superword_iterator16 & operator++(int) override
fsaReader_superword_iterator16(const FsaAccessReader16< graphType > &dico, const LimaString &prefix)
virtual ClonableSuperWordIterator * clone() const override
fsaReader_superword_iterator16(const fsaReader_superword_iterator16 &)=default
bool operator==(const AbstractSuperWordIterator &it) const override
boost::graph_traits< graphType >::out_edge_iterator out_edge
void print(std::ostream &os) const
boost::graph_traits< graphType >::out_edge_iterator out_edge_end
NAUTITIA.
QChar LimaChar
Definition LimaString.h:30
QString LimaString
Definition LimaString.h:33