20#include <boost/config.hpp>
21#include <boost/graph/adjacency_list.hpp>
57 LDEBUG <<
"FsaAccessBuilder16::write(" << filename.c_str() <<
")";
59 std::ofstream os(filename.c_str(), std::ios::out | std::ios::binary );
61 std::string mess =
"FsaAccessBuilder16::write: Can't open file " + filename;
71 LDEBUG <<
"FsaAccessBuilder16::write(" << filename.c_str() <<
"): end";
80 LDEBUG <<
"FsaAccessBuilder16::write(std::ostream)";
92 LDEBUG <<
"FsaAccessBuilder16::write(std::ostream)";
104 LDEBUG <<
"FsaAccessBuilder16::write()";
109 boost::graph_traits<graphType>::vertices_size_type nbVerts =
111 boost::graph_traits<graphType>::edges_size_type nbEdges =
120 LDEBUG <<
"FsaAccessBuilder16::write: call to writeBody";
124 LDEBUG <<
"FsaAccessBuilder16::write: end";
131 LDEBUG <<
"FsaAccessBuilder::pack()";
135 m_packingStatus =
BUILT;
142 LDEBUG <<
"FsaAccessBuilder::addWord(" << newWord <<
")";
154 LWARN <<
"FsaAccessBuilder::addWord: already in dictionary!!! ";
167 LDEBUG <<
"FsaAccessBuilder::replaceOrRegister: (" << candidateState <<
")";
173 dico_degree_size nbChild = boost::out_degree(candidateState,
m_graph);
175 LDEBUG <<
"FsaAccessBuilder::replaceOrRegister: out_degree = " << nbChild;
182 boost::graph_traits<graphType>::out_edge_iterator ei, edge_end;
183 boost::tie(ei,edge_end) = boost::out_edges(candidateState,
m_graph);
188 for( dico_degree_size i = 0 ; i < nbChild - 1 ; i++ ) {
192 dicoVertex lastChild = boost::target(*ei,
m_graph);
196 LDEBUG <<
"FsaAccessBuilder::replaceOrRegister: recursive call on" << lastChild;
204 LDEBUG <<
"FsaAccessBuilder::replaceOrRegister: merging " <<
equivalent.first <<
" and " << lastChild <<
" with " << candidateState <<
" parent";
210 LDEBUG <<
"FsaAccessBuilder::replaceOrRegister: set HEAD_OF_CLASS_16 to " << lastChild;
219 dicoVertex tempState, dicoVertex parentState ) {
222 LDEBUG <<
"FsaAccessBuilder16::merge( " << inRegister <<
", "
224 << parentState <<
")";
227 std::pair<dicoEdgeType, bool> trans = edge(parentState, tempState,
m_graph);
229 Q_ASSERT( trans.second );
234 LDEBUG <<
"FsaAccessBuilder16::merge: add_edge(" << parentState <<
", " << inRegister <<
", " <<
")";
237 std::pair<dicoEdgeType, bool> res = add_edge(parentState, inRegister,
m_graph);
241 LERROR <<
"FsaAccessBuilder16::merge failed to add edge to the graph";
244 Q_ASSERT( res.second );
250 LDEBUG <<
"FsaAccessBuilder16::merge: remove vertex" << tempState;
252 clear_vertex(tempState,
m_graph);
253 remove_vertex(tempState,
m_graph);
virtual void addSuffix(dicoVertexType from, PrefixIterator *prefixIt)
void getPrefix(dicoVertexType &from, PrefixIterator *prefixIt) const
Recursively goes through the graph from from, following edges labelled by the prefix iterator chars.
dicoVertexType m_rootVertex
bool equivalent(dicoVertexType referenceState, dicoVertexType candidateState) const
are both state equivalent? We assume that edges are ordered
void writeBody(AbstractFsaAccessOStreamWrapper &ow)
std::pair< const dicoVertexType, bool > findEquivalentInRegister(dicoVertexType tempState)
Search for equivalent state in register.
selected_graph_types16::builderGraphType m_graph
PrefixIterator * getPrefixIterator(const LimaString &word, const uint64_t offset=0) const
For all navigation Factory of prefixIterator (prefixIt depends on direction: forward/reverse)
virtual void replaceOrRegister(dicoVertex candidateState)
FsaAccessBuilder16(bool trie_direction_fwd=true)
void merge(dicoVertex inRegister, dicoVertex tempState, dicoVertex parentState)
FsaAccessIOHandler< graphType > * getFsaAccessIOHandler() const override
For IO Factory of IO Handler: Handler depends on graphType: with mapping or not.
virtual void addWord(const Lima::LimaString &newWord)
void write(const std::string &filename)
virtual ~FsaAccessBuilder16()
virtual bool hasNextLetter() const =0
virtual const LimaString getCurrentPrefix() const =0
boost::property_map< graphType, boost::vertex_name_t >::type nconst_vname_map_type