1 #ifndef __WORDNODE_H__ // -*- tab-width: 2 mode: c++ -*-
8 #ifndef __DICTIONARY_H__
9 #include "dictionary.h"
19 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
20 #include <boost/shared_ptr.hpp>
23 #ifndef __MYSTRING_H__
30 typedef boost::shared_ptr
<NNode
> NNodeRef
;
35 virtual bool is_leaf() const = 0;
39 class BranchNNode
:public NNode
42 typedef std::map
<strid
,NNodeRef
> node_map
;
43 typedef std::pair
<node_map::const_iterator
,node_map::const_iterator
> const_np_range
;
44 typedef std::pair
<node_map::iterator
,node_map::iterator
> np_range
;
48 virtual ~BranchNNode() {}
49 bool is_leaf() const { return false; }
50 LeafNNode
* get_leaf(strid leaf
) const;
51 void get_leaves(std::vector
<LeafNNode
*> &nodes
) const;
52 void get_branches(strid
,std::vector
<BranchNNode
*> &nodes
) const;
53 BranchNNode
* get_branch(strid
) const;
54 const node_map
& get_nodes() const { return nodes
; }
56 BranchNNode
* add_path(std::vector
<strid
> toks
);
57 void add(strid
,NNodeRef
);
60 class LeafNNode
:public NNode
64 std::vector
<strid
> syllables
;
67 LeafNNode():bitmask(0) {}
68 virtual ~LeafNNode() {}
69 bool is_leaf() const { return true; }
70 strid
get_id() const { return id
; }
71 void set_id(const std::vector
<strid
> &sy
);
73 uint
get_mask() const { return bitmask
; }
74 void set_mask(uint maskval
,bool mask
= true);
75 bool filter(uint mask
) const { return (bitmask
& mask
) == mask
; }
77 uint
get_syllable_count() const { return syllables
.size(); }
78 void get_syllables(std::vector
<strid
> &_syllables
) const { _syllables
= syllables
; }
86 DNNode(T
* _node
= NULL
):node(_node
),distance(0) {}
87 int operator == (const DNNode
&dn1
) const {
88 return dn1
.node
== node
;
90 int operator < (const DNNode
&dn1
) const {
91 return (int)node
+distance
< (int)dn1
.node
+dn1
.distance
;
93 T
& operator* () const { return *node
; }
94 T
* operator-> () const { return node
; }
101 void add_entry(std::vector
<std::string
> toks
);
102 void add_case_entry(std::vector
<std::string
> toks
);
103 std::vector
<strid
> leaf_id
;
107 BranchNNode
* get_root() { return (BranchNNode
*)root
.get(); }
108 bool load(const char *filename
);
109 LeafNNode
* add_special_entry(strid
);
110 void register_leaf(strid leaf
);
111 const std::vector
<strid
>& get_leaf_id() const { return leaf_id
; }
113 LeafNNode
* get_special_node(int);
115 extern WordArchive warch
;
118 std::ostream
& operator << (std::ostream
&os
,const DNNode
<T
> &node
)
124 std::ostream
& operator << (std::ostream
&os
,const LeafNNode
&node
);