1 #ifndef __WORDNODE_H__ // -*- tab-width: 2 mode: c++ -*-
4 #ifndef __DICTIONARY_H__
5 #include "dictionary.h"
15 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
16 #include <boost/shared_ptr.hpp>
19 #ifndef __MYSTRING_H__
26 typedef boost::shared_ptr
<Node
> NodeRef
;
31 virtual bool is_leaf() const = 0;
35 class BranchNode
:public Node
38 typedef std::map
<strid
,NodeRef
> node_map
;
39 typedef std::pair
<node_map::const_iterator
,node_map::const_iterator
> const_np_range
;
40 typedef std::pair
<node_map::iterator
,node_map::iterator
> np_range
;
44 virtual ~BranchNode() {}
45 bool is_leaf() const { return false; }
46 LeafNode
* get_leaf(strid leaf
) const;
47 void get_leaves(std::vector
<LeafNode
*> &nodes
) const;
48 void get_branches(strid
,std::vector
<BranchNode
*> &nodes
) const;
49 BranchNode
* get_branch(strid
) const;
50 const node_map
& get_nodes() const { return nodes
; }
52 BranchNode
* add_path(std::vector
<strid
> toks
);
53 void add(strid
,NodeRef
);
56 class LeafNode
:public Node
60 std::vector
<strid
> syllables
;
63 LeafNode():bitmask(0) {}
64 virtual ~LeafNode() {}
65 bool is_leaf() const { return true; }
66 strid
get_id() const { return id
; }
67 void set_id(const std::vector
<strid
> &sy
);
69 uint
get_mask() const { return bitmask
; }
70 void set_mask(uint maskval
,bool mask
= true);
71 bool filter(uint mask
) const { return (bitmask
& mask
) == mask
; }
73 uint
get_syllable_count() const { return syllables
.size(); }
74 void get_syllables(std::vector
<strid
> &_syllables
) const { _syllables
= syllables
; }
82 DNode(T
* _node
= NULL
):node(_node
),distance(0) {}
83 int operator == (const DNode
&dn1
) const {
84 return dn1
.node
== node
;
86 int operator < (const DNode
&dn1
) const {
87 return (int)node
+distance
< (int)dn1
.node
+dn1
.distance
;
89 T
& operator* () const { return *node
; }
90 T
* operator-> () const { return node
; }
97 void add_entry(std::vector
<std::string
> toks
);
98 void add_case_entry(std::vector
<std::string
> toks
);
99 std::vector
<strid
> leaf_id
;
103 BranchNode
* get_root() { return (BranchNode
*)root
.get(); }
104 bool load(const char *filename
);
105 LeafNode
* add_special_entry(strid
);
106 void register_leaf(strid leaf
);
107 const std::vector
<strid
>& get_leaf_id() const { return leaf_id
; }
109 LeafNode
* get_special_node(int);
111 extern WordArchive warch
;
114 std::ostream
& operator << (std::ostream
&os
,const DNode
<T
> &node
)
120 std::ostream
& operator << (std::ostream
&os
,const LeafNode
&node
);