melisa 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +53 -4
  3. data/ext/extconf.rb +33 -0
  4. data/ext/marisa-0.2.4/AUTHORS +1 -0
  5. data/ext/marisa-0.2.4/COPYING +32 -0
  6. data/ext/marisa-0.2.4/ChangeLog +0 -0
  7. data/ext/marisa-0.2.4/INSTALL +237 -0
  8. data/ext/marisa-0.2.4/Makefile.am +24 -0
  9. data/ext/marisa-0.2.4/Makefile.in +803 -0
  10. data/ext/marisa-0.2.4/NEWS +0 -0
  11. data/ext/marisa-0.2.4/README +63 -0
  12. data/ext/marisa-0.2.4/aclocal.m4 +976 -0
  13. data/ext/marisa-0.2.4/bindings/Makefile +16 -0
  14. data/ext/{marisa → marisa-0.2.4}/bindings/marisa-swig.cxx +0 -0
  15. data/ext/{marisa → marisa-0.2.4}/bindings/marisa-swig.h +0 -0
  16. data/ext/marisa-0.2.4/bindings/marisa-swig.i +28 -0
  17. data/ext/marisa-0.2.4/bindings/perl/Makefile.PL +7 -0
  18. data/ext/{marisa → marisa-0.2.4}/bindings/perl/marisa-swig.cxx +0 -0
  19. data/ext/{marisa → marisa-0.2.4}/bindings/perl/marisa-swig.h +0 -0
  20. data/ext/{marisa → marisa-0.2.4}/bindings/perl/marisa-swig_wrap.cxx +0 -0
  21. data/ext/marisa-0.2.4/bindings/perl/marisa.pm +297 -0
  22. data/ext/marisa-0.2.4/bindings/perl/sample.dic +0 -0
  23. data/ext/marisa-0.2.4/bindings/perl/sample.pl +62 -0
  24. data/ext/{marisa → marisa-0.2.4}/bindings/python/marisa-swig.cxx +0 -0
  25. data/ext/{marisa → marisa-0.2.4}/bindings/python/marisa-swig.h +0 -0
  26. data/ext/{marisa → marisa-0.2.4}/bindings/python/marisa-swig_wrap.cxx +0 -0
  27. data/ext/marisa-0.2.4/bindings/python/marisa.py +206 -0
  28. data/ext/marisa-0.2.4/bindings/python/sample.dic +0 -0
  29. data/ext/marisa-0.2.4/bindings/python/sample.py +57 -0
  30. data/ext/marisa-0.2.4/bindings/python/setup.py +9 -0
  31. data/ext/marisa-0.2.4/config.guess +1530 -0
  32. data/ext/marisa-0.2.4/config.sub +1773 -0
  33. data/ext/marisa-0.2.4/configure +17636 -0
  34. data/ext/marisa-0.2.4/configure.ac +172 -0
  35. data/ext/marisa-0.2.4/depcomp +688 -0
  36. data/ext/marisa-0.2.4/docs/readme.en.html +740 -0
  37. data/ext/marisa-0.2.4/docs/readme.ja.html +750 -0
  38. data/ext/marisa-0.2.4/docs/style.css +245 -0
  39. data/ext/marisa-0.2.4/install-sh +520 -0
  40. data/ext/marisa-0.2.4/lib/Makefile.am +57 -0
  41. data/ext/marisa-0.2.4/lib/Makefile.in +701 -0
  42. data/ext/{marisa → marisa-0.2.4}/lib/marisa.h +0 -0
  43. data/ext/{marisa → marisa-0.2.4}/lib/marisa/agent.cc +2 -2
  44. data/ext/{marisa → marisa-0.2.4}/lib/marisa/agent.h +2 -2
  45. data/ext/{marisa → marisa-0.2.4}/lib/marisa/base.h +3 -3
  46. data/ext/{marisa → marisa-0.2.4}/lib/marisa/exception.h +1 -1
  47. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/algorithm.h +1 -1
  48. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/algorithm/sort.h +1 -1
  49. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/intrin.h +1 -1
  50. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io.h +3 -3
  51. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io/mapper.cc +1 -1
  52. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io/mapper.h +1 -1
  53. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io/reader.cc +1 -1
  54. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io/reader.h +1 -1
  55. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io/writer.cc +1 -1
  56. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/io/writer.h +1 -1
  57. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie.h +2 -2
  58. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/cache.h +1 -1
  59. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/config.h +1 -1
  60. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/entry.h +1 -1
  61. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/header.h +1 -1
  62. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/history.h +1 -1
  63. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/key.h +1 -1
  64. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/louds-trie.cc +5 -5
  65. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/louds-trie.h +7 -7
  66. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/range.h +1 -1
  67. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/state.h +2 -2
  68. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/tail.cc +3 -3
  69. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/trie/tail.h +3 -3
  70. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector.h +3 -3
  71. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector/bit-vector.cc +2 -2
  72. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector/bit-vector.h +2 -2
  73. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector/flat-vector.h +1 -1
  74. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector/pop-count.h +1 -1
  75. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector/rank-index.h +1 -1
  76. data/ext/{marisa → marisa-0.2.4}/lib/marisa/grimoire/vector/vector.h +1 -1
  77. data/ext/{marisa → marisa-0.2.4}/lib/marisa/iostream.h +0 -0
  78. data/ext/{marisa → marisa-0.2.4}/lib/marisa/key.h +1 -1
  79. data/ext/{marisa → marisa-0.2.4}/lib/marisa/keyset.cc +1 -1
  80. data/ext/{marisa → marisa-0.2.4}/lib/marisa/keyset.h +1 -1
  81. data/ext/{marisa → marisa-0.2.4}/lib/marisa/query.h +1 -1
  82. data/ext/{marisa → marisa-0.2.4}/lib/marisa/scoped-array.h +1 -1
  83. data/ext/{marisa → marisa-0.2.4}/lib/marisa/scoped-ptr.h +1 -1
  84. data/ext/{marisa → marisa-0.2.4}/lib/marisa/stdio.h +0 -0
  85. data/ext/{marisa → marisa-0.2.4}/lib/marisa/trie.cc +4 -4
  86. data/ext/{marisa → marisa-0.2.4}/lib/marisa/trie.h +2 -2
  87. data/ext/marisa-0.2.4/ltmain.sh +9661 -0
  88. data/ext/marisa-0.2.4/m4/libtool.m4 +8001 -0
  89. data/ext/marisa-0.2.4/m4/ltoptions.m4 +384 -0
  90. data/ext/marisa-0.2.4/m4/ltsugar.m4 +123 -0
  91. data/ext/marisa-0.2.4/m4/ltversion.m4 +23 -0
  92. data/ext/marisa-0.2.4/m4/lt~obsolete.m4 +98 -0
  93. data/ext/marisa-0.2.4/marisa.pc.in +11 -0
  94. data/ext/marisa-0.2.4/missing +331 -0
  95. data/ext/marisa-0.2.4/mkmf.log +288 -0
  96. data/ext/marisa-0.2.4/pkg/bin/marisa-benchmark +0 -0
  97. data/ext/marisa-0.2.4/pkg/bin/marisa-build +0 -0
  98. data/ext/marisa-0.2.4/pkg/bin/marisa-common-prefix-search +0 -0
  99. data/ext/marisa-0.2.4/pkg/bin/marisa-dump +0 -0
  100. data/ext/marisa-0.2.4/pkg/bin/marisa-lookup +0 -0
  101. data/ext/marisa-0.2.4/pkg/bin/marisa-predictive-search +0 -0
  102. data/ext/marisa-0.2.4/pkg/bin/marisa-reverse-lookup +0 -0
  103. data/ext/marisa-0.2.4/pkg/include/marisa.h +14 -0
  104. data/ext/marisa-0.2.4/pkg/include/marisa/agent.h +73 -0
  105. data/ext/marisa-0.2.4/pkg/include/marisa/base.h +193 -0
  106. data/ext/marisa-0.2.4/pkg/include/marisa/exception.h +82 -0
  107. data/ext/marisa-0.2.4/pkg/include/marisa/iostream.h +18 -0
  108. data/ext/marisa-0.2.4/pkg/include/marisa/key.h +85 -0
  109. data/ext/marisa-0.2.4/pkg/include/marisa/keyset.h +80 -0
  110. data/ext/marisa-0.2.4/pkg/include/marisa/query.h +71 -0
  111. data/ext/marisa-0.2.4/pkg/include/marisa/scoped-array.h +48 -0
  112. data/ext/marisa-0.2.4/pkg/include/marisa/scoped-ptr.h +52 -0
  113. data/ext/marisa-0.2.4/pkg/include/marisa/stdio.h +15 -0
  114. data/ext/marisa-0.2.4/pkg/include/marisa/trie.h +64 -0
  115. data/ext/marisa-0.2.4/pkg/lib/libmarisa.0.dylib +0 -0
  116. data/ext/marisa-0.2.4/pkg/lib/libmarisa.a +0 -0
  117. data/ext/marisa-0.2.4/pkg/lib/libmarisa.dylib +0 -0
  118. data/ext/marisa-0.2.4/pkg/lib/libmarisa.la +41 -0
  119. data/ext/marisa-0.2.4/pkg/lib/pkgconfig/marisa.pc +11 -0
  120. data/ext/marisa-0.2.4/tests/Makefile.am +27 -0
  121. data/ext/marisa-0.2.4/tests/Makefile.in +624 -0
  122. data/ext/{marisa → marisa-0.2.4}/tests/base-test.cc +0 -0
  123. data/ext/{marisa → marisa-0.2.4}/tests/io-test.cc +0 -0
  124. data/ext/{marisa → marisa-0.2.4}/tests/marisa-assert.h +0 -0
  125. data/ext/{marisa → marisa-0.2.4}/tests/marisa-test.cc +0 -0
  126. data/ext/{marisa → marisa-0.2.4}/tests/trie-test.cc +0 -0
  127. data/ext/{marisa → marisa-0.2.4}/tests/vector-test.cc +0 -0
  128. data/ext/marisa-0.2.4/tools/Makefile.am +39 -0
  129. data/ext/marisa-0.2.4/tools/Makefile.in +616 -0
  130. data/ext/{marisa → marisa-0.2.4}/tools/cmdopt.cc +0 -0
  131. data/ext/{marisa → marisa-0.2.4}/tools/cmdopt.h +0 -0
  132. data/ext/{marisa → marisa-0.2.4}/tools/marisa-benchmark.cc +0 -0
  133. data/ext/{marisa → marisa-0.2.4}/tools/marisa-build.cc +0 -0
  134. data/ext/{marisa → marisa-0.2.4}/tools/marisa-common-prefix-search.cc +0 -0
  135. data/ext/{marisa → marisa-0.2.4}/tools/marisa-dump.cc +0 -0
  136. data/ext/{marisa → marisa-0.2.4}/tools/marisa-lookup.cc +0 -0
  137. data/ext/{marisa → marisa-0.2.4}/tools/marisa-predictive-search.cc +0 -0
  138. data/ext/{marisa → marisa-0.2.4}/tools/marisa-reverse-lookup.cc +0 -0
  139. data/ext/marisa-0.2.4/vs2008/base-test/base-test.vcproj +200 -0
  140. data/ext/marisa-0.2.4/vs2008/io-test/io-test.vcproj +199 -0
  141. data/ext/marisa-0.2.4/vs2008/libmarisa/libmarisa.vcproj +347 -0
  142. data/ext/marisa-0.2.4/vs2008/marisa-benchmark/marisa-benchmark.vcproj +203 -0
  143. data/ext/marisa-0.2.4/vs2008/marisa-build/marisa-build.vcproj +203 -0
  144. data/ext/marisa-0.2.4/vs2008/marisa-common-prefix-search/marisa-common-prefix-search.vcproj +203 -0
  145. data/ext/marisa-0.2.4/vs2008/marisa-dump/marisa-dump.vcproj +203 -0
  146. data/ext/marisa-0.2.4/vs2008/marisa-lookup/marisa-lookup.vcproj +203 -0
  147. data/ext/marisa-0.2.4/vs2008/marisa-predictive-search/marisa-predictive-search.vcproj +203 -0
  148. data/ext/marisa-0.2.4/vs2008/marisa-reverse-lookup/marisa-reverse-lookup.vcproj +203 -0
  149. data/ext/marisa-0.2.4/vs2008/marisa-test/marisa-test.vcproj +199 -0
  150. data/ext/marisa-0.2.4/vs2008/trie-test/trie-test.vcproj +199 -0
  151. data/ext/marisa-0.2.4/vs2008/vector-test/vector-test.vcproj +199 -0
  152. data/ext/marisa-0.2.4/vs2008/vs2008.sln +123 -0
  153. data/ext/marisa-0.2.4/vs2008/vs2008.suo +0 -0
  154. data/ext/{marisa/bindings/ruby/marisa-swig.cxx → marisa-swig.cxx} +0 -0
  155. data/ext/{marisa/bindings/ruby/marisa-swig.h → marisa-swig.h} +0 -0
  156. data/ext/{marisa/bindings/ruby/marisa-swig_wrap.cxx → marisa-swig_wrap.cxx} +0 -0
  157. data/lib/melisa/bytes_trie.rb +5 -0
  158. data/lib/melisa/trie.rb +2 -0
  159. data/lib/melisa/version.rb +1 -1
  160. data/melisa.gemspec +7 -9
  161. data/spec/bytes_trie_spec.rb +6 -1
  162. data/spec/int_trie_spec.rb +5 -0
  163. data/spec/search_spec.rb +6 -7
  164. data/spec/trie_spec.rb +4 -4
  165. metadata +178 -121
  166. data/ext/marisa/bindings/ruby/extconf.rb +0 -5
@@ -0,0 +1,16 @@
1
+ ALL: swig-perl swig-python swig-ruby
2
+
3
+ swig-perl:
4
+ swig -Wall -c++ -perl -outdir perl marisa-swig.i
5
+ mv marisa-swig_wrap.cxx perl
6
+ cp marisa-swig.cxx marisa-swig.h perl
7
+
8
+ swig-python:
9
+ swig -Wall -c++ -python -outdir python marisa-swig.i
10
+ mv marisa-swig_wrap.cxx python
11
+ cp marisa-swig.cxx marisa-swig.h python
12
+
13
+ swig-ruby:
14
+ swig -Wall -c++ -ruby -outdir ruby marisa-swig.i
15
+ mv marisa-swig_wrap.cxx ruby
16
+ cp marisa-swig.cxx marisa-swig.h ruby
File without changes
@@ -0,0 +1,28 @@
1
+ %module marisa
2
+
3
+ %include "cstring.i"
4
+ %include "exception.i"
5
+
6
+ %{
7
+ #include "marisa-swig.h"
8
+ %}
9
+
10
+ %apply (char *STRING, int LENGTH) { (const char *ptr, std::size_t length) };
11
+
12
+ %cstring_output_allocate_size(const char **ptr_out, std::size_t *length_out, );
13
+ %cstring_output_allocate_size(const char **ptr_out_to_be_deleted,
14
+ std::size_t *length_out, delete [] (*$1));
15
+
16
+ %exception {
17
+ try {
18
+ $action
19
+ } catch (const marisa::Exception &ex) {
20
+ SWIG_exception(SWIG_RuntimeError, ex.what());
21
+ } catch (...) {
22
+ SWIG_exception(SWIG_UnknownError,"Unknown exception");
23
+ }
24
+ }
25
+
26
+ %include "marisa-swig.h"
27
+
28
+ %constant size_t INVALID_KEY_ID = MARISA_INVALID_KEY_ID;
@@ -0,0 +1,7 @@
1
+ use ExtUtils::MakeMaker;
2
+
3
+ WriteMakefile(
4
+ 'NAME' => 'marisa',
5
+ 'LIBS' => ['-lmarisa'],
6
+ 'OBJECT' => 'marisa-swig.o marisa-swig_wrap.o'
7
+ );
@@ -0,0 +1,297 @@
1
+ # This file was automatically generated by SWIG (http://www.swig.org).
2
+ # Version 1.3.40
3
+ #
4
+ # Do not make changes to this file unless you know what you are doing--modify
5
+ # the SWIG interface file instead.
6
+
7
+ package marisa;
8
+ use base qw(Exporter);
9
+ use base qw(DynaLoader);
10
+ package marisac;
11
+ bootstrap marisa;
12
+ package marisa;
13
+ @EXPORT = qw();
14
+
15
+ # ---------- BASE METHODS -------------
16
+
17
+ package marisa;
18
+
19
+ sub TIEHASH {
20
+ my ($classname,$obj) = @_;
21
+ return bless $obj, $classname;
22
+ }
23
+
24
+ sub CLEAR { }
25
+
26
+ sub FIRSTKEY { }
27
+
28
+ sub NEXTKEY { }
29
+
30
+ sub FETCH {
31
+ my ($self,$field) = @_;
32
+ my $member_func = "swig_${field}_get";
33
+ $self->$member_func();
34
+ }
35
+
36
+ sub STORE {
37
+ my ($self,$field,$newval) = @_;
38
+ my $member_func = "swig_${field}_set";
39
+ $self->$member_func($newval);
40
+ }
41
+
42
+ sub this {
43
+ my $ptr = shift;
44
+ return tied(%$ptr);
45
+ }
46
+
47
+
48
+ # ------- FUNCTION WRAPPERS --------
49
+
50
+ package marisa;
51
+
52
+
53
+ ############# Class : marisa::Key ##############
54
+
55
+ package marisa::Key;
56
+ use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
57
+ @ISA = qw( marisa );
58
+ %OWNER = ();
59
+ %ITERATORS = ();
60
+ *str = *marisac::Key_str;
61
+ *id = *marisac::Key_id;
62
+ *weight = *marisac::Key_weight;
63
+ sub DESTROY {
64
+ return unless $_[0]->isa('HASH');
65
+ my $self = tied(%{$_[0]});
66
+ return unless defined $self;
67
+ delete $ITERATORS{$self};
68
+ if (exists $OWNER{$self}) {
69
+ marisac::delete_Key($self);
70
+ delete $OWNER{$self};
71
+ }
72
+ }
73
+
74
+ sub DISOWN {
75
+ my $self = shift;
76
+ my $ptr = tied(%$self);
77
+ delete $OWNER{$ptr};
78
+ }
79
+
80
+ sub ACQUIRE {
81
+ my $self = shift;
82
+ my $ptr = tied(%$self);
83
+ $OWNER{$ptr} = 1;
84
+ }
85
+
86
+
87
+ ############# Class : marisa::Query ##############
88
+
89
+ package marisa::Query;
90
+ use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
91
+ @ISA = qw( marisa );
92
+ %OWNER = ();
93
+ %ITERATORS = ();
94
+ *str = *marisac::Query_str;
95
+ *id = *marisac::Query_id;
96
+ sub DESTROY {
97
+ return unless $_[0]->isa('HASH');
98
+ my $self = tied(%{$_[0]});
99
+ return unless defined $self;
100
+ delete $ITERATORS{$self};
101
+ if (exists $OWNER{$self}) {
102
+ marisac::delete_Query($self);
103
+ delete $OWNER{$self};
104
+ }
105
+ }
106
+
107
+ sub DISOWN {
108
+ my $self = shift;
109
+ my $ptr = tied(%$self);
110
+ delete $OWNER{$ptr};
111
+ }
112
+
113
+ sub ACQUIRE {
114
+ my $self = shift;
115
+ my $ptr = tied(%$self);
116
+ $OWNER{$ptr} = 1;
117
+ }
118
+
119
+
120
+ ############# Class : marisa::Keyset ##############
121
+
122
+ package marisa::Keyset;
123
+ use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
124
+ @ISA = qw( marisa );
125
+ %OWNER = ();
126
+ %ITERATORS = ();
127
+ sub new {
128
+ my $pkg = shift;
129
+ my $self = marisac::new_Keyset(@_);
130
+ bless $self, $pkg if defined($self);
131
+ }
132
+
133
+ sub DESTROY {
134
+ return unless $_[0]->isa('HASH');
135
+ my $self = tied(%{$_[0]});
136
+ return unless defined $self;
137
+ delete $ITERATORS{$self};
138
+ if (exists $OWNER{$self}) {
139
+ marisac::delete_Keyset($self);
140
+ delete $OWNER{$self};
141
+ }
142
+ }
143
+
144
+ *push_back = *marisac::Keyset_push_back;
145
+ *key = *marisac::Keyset_key;
146
+ *key_str = *marisac::Keyset_key_str;
147
+ *key_id = *marisac::Keyset_key_id;
148
+ *num_keys = *marisac::Keyset_num_keys;
149
+ *empty = *marisac::Keyset_empty;
150
+ *size = *marisac::Keyset_size;
151
+ *total_length = *marisac::Keyset_total_length;
152
+ *reset = *marisac::Keyset_reset;
153
+ *clear = *marisac::Keyset_clear;
154
+ sub DISOWN {
155
+ my $self = shift;
156
+ my $ptr = tied(%$self);
157
+ delete $OWNER{$ptr};
158
+ }
159
+
160
+ sub ACQUIRE {
161
+ my $self = shift;
162
+ my $ptr = tied(%$self);
163
+ $OWNER{$ptr} = 1;
164
+ }
165
+
166
+
167
+ ############# Class : marisa::Agent ##############
168
+
169
+ package marisa::Agent;
170
+ use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
171
+ @ISA = qw( marisa );
172
+ %OWNER = ();
173
+ %ITERATORS = ();
174
+ sub new {
175
+ my $pkg = shift;
176
+ my $self = marisac::new_Agent(@_);
177
+ bless $self, $pkg if defined($self);
178
+ }
179
+
180
+ sub DESTROY {
181
+ return unless $_[0]->isa('HASH');
182
+ my $self = tied(%{$_[0]});
183
+ return unless defined $self;
184
+ delete $ITERATORS{$self};
185
+ if (exists $OWNER{$self}) {
186
+ marisac::delete_Agent($self);
187
+ delete $OWNER{$self};
188
+ }
189
+ }
190
+
191
+ *set_query = *marisac::Agent_set_query;
192
+ *key = *marisac::Agent_key;
193
+ *query = *marisac::Agent_query;
194
+ *key_str = *marisac::Agent_key_str;
195
+ *key_id = *marisac::Agent_key_id;
196
+ *query_str = *marisac::Agent_query_str;
197
+ *query_id = *marisac::Agent_query_id;
198
+ sub DISOWN {
199
+ my $self = shift;
200
+ my $ptr = tied(%$self);
201
+ delete $OWNER{$ptr};
202
+ }
203
+
204
+ sub ACQUIRE {
205
+ my $self = shift;
206
+ my $ptr = tied(%$self);
207
+ $OWNER{$ptr} = 1;
208
+ }
209
+
210
+
211
+ ############# Class : marisa::Trie ##############
212
+
213
+ package marisa::Trie;
214
+ use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
215
+ @ISA = qw( marisa );
216
+ %OWNER = ();
217
+ %ITERATORS = ();
218
+ sub new {
219
+ my $pkg = shift;
220
+ my $self = marisac::new_Trie(@_);
221
+ bless $self, $pkg if defined($self);
222
+ }
223
+
224
+ sub DESTROY {
225
+ return unless $_[0]->isa('HASH');
226
+ my $self = tied(%{$_[0]});
227
+ return unless defined $self;
228
+ delete $ITERATORS{$self};
229
+ if (exists $OWNER{$self}) {
230
+ marisac::delete_Trie($self);
231
+ delete $OWNER{$self};
232
+ }
233
+ }
234
+
235
+ *build = *marisac::Trie_build;
236
+ *mmap = *marisac::Trie_mmap;
237
+ *load = *marisac::Trie_load;
238
+ *save = *marisac::Trie_save;
239
+ *common_prefix_search = *marisac::Trie_common_prefix_search;
240
+ *predictive_search = *marisac::Trie_predictive_search;
241
+ *lookup = *marisac::Trie_lookup;
242
+ *reverse_lookup = *marisac::Trie_reverse_lookup;
243
+ *num_tries = *marisac::Trie_num_tries;
244
+ *num_keys = *marisac::Trie_num_keys;
245
+ *num_nodes = *marisac::Trie_num_nodes;
246
+ *tail_mode = *marisac::Trie_tail_mode;
247
+ *node_order = *marisac::Trie_node_order;
248
+ *empty = *marisac::Trie_empty;
249
+ *size = *marisac::Trie_size;
250
+ *total_size = *marisac::Trie_total_size;
251
+ *io_size = *marisac::Trie_io_size;
252
+ *clear = *marisac::Trie_clear;
253
+ sub DISOWN {
254
+ my $self = shift;
255
+ my $ptr = tied(%$self);
256
+ delete $OWNER{$ptr};
257
+ }
258
+
259
+ sub ACQUIRE {
260
+ my $self = shift;
261
+ my $ptr = tied(%$self);
262
+ $OWNER{$ptr} = 1;
263
+ }
264
+
265
+
266
+ # ------- VARIABLE STUBS --------
267
+
268
+ package marisa;
269
+
270
+ *OK = *marisac::OK;
271
+ *STATE_ERROR = *marisac::STATE_ERROR;
272
+ *NULL_ERROR = *marisac::NULL_ERROR;
273
+ *BOUND_ERROR = *marisac::BOUND_ERROR;
274
+ *RANGE_ERROR = *marisac::RANGE_ERROR;
275
+ *CODE_ERROR = *marisac::CODE_ERROR;
276
+ *RESET_ERROR = *marisac::RESET_ERROR;
277
+ *SIZE_ERROR = *marisac::SIZE_ERROR;
278
+ *MEMORY_ERROR = *marisac::MEMORY_ERROR;
279
+ *IO_ERROR = *marisac::IO_ERROR;
280
+ *FORMAT_ERROR = *marisac::FORMAT_ERROR;
281
+ *MIN_NUM_TRIES = *marisac::MIN_NUM_TRIES;
282
+ *MAX_NUM_TRIES = *marisac::MAX_NUM_TRIES;
283
+ *DEFAULT_NUM_TRIES = *marisac::DEFAULT_NUM_TRIES;
284
+ *HUGE_CACHE = *marisac::HUGE_CACHE;
285
+ *LARGE_CACHE = *marisac::LARGE_CACHE;
286
+ *NORMAL_CACHE = *marisac::NORMAL_CACHE;
287
+ *SMALL_CACHE = *marisac::SMALL_CACHE;
288
+ *TINY_CACHE = *marisac::TINY_CACHE;
289
+ *DEFAULT_CACHE = *marisac::DEFAULT_CACHE;
290
+ *TEXT_TAIL = *marisac::TEXT_TAIL;
291
+ *BINARY_TAIL = *marisac::BINARY_TAIL;
292
+ *DEFAULT_TAIL = *marisac::DEFAULT_TAIL;
293
+ *LABEL_ORDER = *marisac::LABEL_ORDER;
294
+ *WEIGHT_ORDER = *marisac::WEIGHT_ORDER;
295
+ *DEFAULT_ORDER = *marisac::DEFAULT_ORDER;
296
+ *INVALID_KEY_ID = *marisac::INVALID_KEY_ID;
297
+ 1;
@@ -0,0 +1,62 @@
1
+ use marisa;
2
+
3
+ $keyset = new marisa::Keyset;
4
+ $keyset->push_back("cake");
5
+ $keyset->push_back("cookie");
6
+ $keyset->push_back("ice");
7
+ $keyset->push_back("ice-cream");
8
+
9
+ $trie = new marisa::Trie;
10
+ $trie->build($keyset);
11
+ print("no. keys: ", $trie->num_keys(), "\n");
12
+ print("no. tries: ", $trie->num_tries(), "\n");
13
+ print("no. nodes: ", $trie->num_nodes(), "\n");
14
+ print("size: ", $trie->io_size(), "\n");
15
+
16
+ $agent = new marisa::Agent;
17
+
18
+ $agent->set_query("cake");
19
+ $trie->lookup($agent);
20
+ print($agent->query_str(), ": ", $agent->key_id(), "\n");
21
+
22
+ $agent->set_query("cookie");
23
+ $trie->lookup($agent);
24
+ print($agent->query_str(), ": ", $agent->key_id(), "\n");
25
+
26
+ $agent->set_query("cockoo");
27
+ if ($trie->lookup(agent)) {
28
+ print($agent->query_str(), ": not found\n");
29
+ }
30
+
31
+ print("ice: ", $trie->lookup("ice"), "\n");
32
+ print("ice-cream: ", $trie->lookup("ice-cream"), "\n");
33
+ if ($trie->lookup("ice-age") == $marisa::INVALID_KEY_ID) {
34
+ print("ice-age: not found\n");
35
+ }
36
+
37
+ $trie->save("sample.dic");
38
+ $trie->load("sample.dic");
39
+
40
+ $agent->set_query(0);
41
+ $trie->reverse_lookup($agent);
42
+ print($agent->query_id(), ": ", $agent->key_str(), "\n");
43
+ $agent->set_query(1);
44
+ $trie->reverse_lookup($agent);
45
+ print($agent->query_id(), ": ", $agent->key_str(), "\n");
46
+
47
+ print("2: ", $trie->reverse_lookup(2), "\n");
48
+ print("3: ", $trie->reverse_lookup(3), "\n");
49
+
50
+ $trie->mmap("sample.dic");
51
+
52
+ $agent->set_query("ice-cream soda");
53
+ while ($trie->common_prefix_search($agent)) {
54
+ print($agent->query_str(), ": ", $agent->key_str(), " (",
55
+ $agent->key_id(), ")\n");
56
+ }
57
+
58
+ $agent->set_query("ic");
59
+ while ($trie->predictive_search($agent)) {
60
+ print($agent->query_str(), ": ", $agent->key_str(), " (",
61
+ $agent->key_id(), ")\n");
62
+ }
@@ -0,0 +1,206 @@
1
+ # This file was automatically generated by SWIG (http://www.swig.org).
2
+ # Version 1.3.40
3
+ #
4
+ # Do not make changes to this file unless you know what you are doing--modify
5
+ # the SWIG interface file instead.
6
+ # This file is compatible with both classic and new-style classes.
7
+
8
+ from sys import version_info
9
+ if version_info >= (2,6,0):
10
+ def swig_import_helper():
11
+ from os.path import dirname
12
+ import imp
13
+ fp = None
14
+ try:
15
+ fp, pathname, description = imp.find_module('_marisa', [dirname(__file__)])
16
+ except ImportError:
17
+ import _marisa
18
+ return _marisa
19
+ if fp is not None:
20
+ try:
21
+ _mod = imp.load_module('_marisa', fp, pathname, description)
22
+ finally:
23
+ fp.close()
24
+ return _mod
25
+ _marisa = swig_import_helper()
26
+ del swig_import_helper
27
+ else:
28
+ import _marisa
29
+ del version_info
30
+ try:
31
+ _swig_property = property
32
+ except NameError:
33
+ pass # Python < 2.2 doesn't have 'property'.
34
+ def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
35
+ if (name == "thisown"): return self.this.own(value)
36
+ if (name == "this"):
37
+ if type(value).__name__ == 'SwigPyObject':
38
+ self.__dict__[name] = value
39
+ return
40
+ method = class_type.__swig_setmethods__.get(name,None)
41
+ if method: return method(self,value)
42
+ if (not static) or hasattr(self,name):
43
+ self.__dict__[name] = value
44
+ else:
45
+ raise AttributeError("You cannot add attributes to %s" % self)
46
+
47
+ def _swig_setattr(self,class_type,name,value):
48
+ return _swig_setattr_nondynamic(self,class_type,name,value,0)
49
+
50
+ def _swig_getattr(self,class_type,name):
51
+ if (name == "thisown"): return self.this.own()
52
+ method = class_type.__swig_getmethods__.get(name,None)
53
+ if method: return method(self)
54
+ raise AttributeError(name)
55
+
56
+ def _swig_repr(self):
57
+ try: strthis = "proxy of " + self.this.__repr__()
58
+ except: strthis = ""
59
+ return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
60
+
61
+ try:
62
+ _object = object
63
+ _newclass = 1
64
+ except AttributeError:
65
+ class _object : pass
66
+ _newclass = 0
67
+
68
+
69
+ OK = _marisa.OK
70
+ STATE_ERROR = _marisa.STATE_ERROR
71
+ NULL_ERROR = _marisa.NULL_ERROR
72
+ BOUND_ERROR = _marisa.BOUND_ERROR
73
+ RANGE_ERROR = _marisa.RANGE_ERROR
74
+ CODE_ERROR = _marisa.CODE_ERROR
75
+ RESET_ERROR = _marisa.RESET_ERROR
76
+ SIZE_ERROR = _marisa.SIZE_ERROR
77
+ MEMORY_ERROR = _marisa.MEMORY_ERROR
78
+ IO_ERROR = _marisa.IO_ERROR
79
+ FORMAT_ERROR = _marisa.FORMAT_ERROR
80
+ MIN_NUM_TRIES = _marisa.MIN_NUM_TRIES
81
+ MAX_NUM_TRIES = _marisa.MAX_NUM_TRIES
82
+ DEFAULT_NUM_TRIES = _marisa.DEFAULT_NUM_TRIES
83
+ HUGE_CACHE = _marisa.HUGE_CACHE
84
+ LARGE_CACHE = _marisa.LARGE_CACHE
85
+ NORMAL_CACHE = _marisa.NORMAL_CACHE
86
+ SMALL_CACHE = _marisa.SMALL_CACHE
87
+ TINY_CACHE = _marisa.TINY_CACHE
88
+ DEFAULT_CACHE = _marisa.DEFAULT_CACHE
89
+ TEXT_TAIL = _marisa.TEXT_TAIL
90
+ BINARY_TAIL = _marisa.BINARY_TAIL
91
+ DEFAULT_TAIL = _marisa.DEFAULT_TAIL
92
+ LABEL_ORDER = _marisa.LABEL_ORDER
93
+ WEIGHT_ORDER = _marisa.WEIGHT_ORDER
94
+ DEFAULT_ORDER = _marisa.DEFAULT_ORDER
95
+ class Key(_object):
96
+ __swig_setmethods__ = {}
97
+ __setattr__ = lambda self, name, value: _swig_setattr(self, Key, name, value)
98
+ __swig_getmethods__ = {}
99
+ __getattr__ = lambda self, name: _swig_getattr(self, Key, name)
100
+ def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
101
+ __repr__ = _swig_repr
102
+ def str(self): return _marisa.Key_str(self)
103
+ def id(self): return _marisa.Key_id(self)
104
+ def weight(self): return _marisa.Key_weight(self)
105
+ __swig_destroy__ = _marisa.delete_Key
106
+ __del__ = lambda self : None;
107
+ Key_swigregister = _marisa.Key_swigregister
108
+ Key_swigregister(Key)
109
+
110
+ class Query(_object):
111
+ __swig_setmethods__ = {}
112
+ __setattr__ = lambda self, name, value: _swig_setattr(self, Query, name, value)
113
+ __swig_getmethods__ = {}
114
+ __getattr__ = lambda self, name: _swig_getattr(self, Query, name)
115
+ def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
116
+ __repr__ = _swig_repr
117
+ def str(self): return _marisa.Query_str(self)
118
+ def id(self): return _marisa.Query_id(self)
119
+ __swig_destroy__ = _marisa.delete_Query
120
+ __del__ = lambda self : None;
121
+ Query_swigregister = _marisa.Query_swigregister
122
+ Query_swigregister(Query)
123
+
124
+ class Keyset(_object):
125
+ __swig_setmethods__ = {}
126
+ __setattr__ = lambda self, name, value: _swig_setattr(self, Keyset, name, value)
127
+ __swig_getmethods__ = {}
128
+ __getattr__ = lambda self, name: _swig_getattr(self, Keyset, name)
129
+ __repr__ = _swig_repr
130
+ def __init__(self):
131
+ this = _marisa.new_Keyset()
132
+ try: self.this.append(this)
133
+ except: self.this = this
134
+ __swig_destroy__ = _marisa.delete_Keyset
135
+ __del__ = lambda self : None;
136
+ def push_back(self, *args): return _marisa.Keyset_push_back(self, *args)
137
+ def key(self, *args): return _marisa.Keyset_key(self, *args)
138
+ def key_str(self, *args): return _marisa.Keyset_key_str(self, *args)
139
+ def key_id(self, *args): return _marisa.Keyset_key_id(self, *args)
140
+ def num_keys(self): return _marisa.Keyset_num_keys(self)
141
+ def empty(self): return _marisa.Keyset_empty(self)
142
+ def size(self): return _marisa.Keyset_size(self)
143
+ def total_length(self): return _marisa.Keyset_total_length(self)
144
+ def reset(self): return _marisa.Keyset_reset(self)
145
+ def clear(self): return _marisa.Keyset_clear(self)
146
+ Keyset_swigregister = _marisa.Keyset_swigregister
147
+ Keyset_swigregister(Keyset)
148
+
149
+ class Agent(_object):
150
+ __swig_setmethods__ = {}
151
+ __setattr__ = lambda self, name, value: _swig_setattr(self, Agent, name, value)
152
+ __swig_getmethods__ = {}
153
+ __getattr__ = lambda self, name: _swig_getattr(self, Agent, name)
154
+ __repr__ = _swig_repr
155
+ def __init__(self):
156
+ this = _marisa.new_Agent()
157
+ try: self.this.append(this)
158
+ except: self.this = this
159
+ __swig_destroy__ = _marisa.delete_Agent
160
+ __del__ = lambda self : None;
161
+ def set_query(self, *args): return _marisa.Agent_set_query(self, *args)
162
+ def key(self): return _marisa.Agent_key(self)
163
+ def query(self): return _marisa.Agent_query(self)
164
+ def key_str(self): return _marisa.Agent_key_str(self)
165
+ def key_id(self): return _marisa.Agent_key_id(self)
166
+ def query_str(self): return _marisa.Agent_query_str(self)
167
+ def query_id(self): return _marisa.Agent_query_id(self)
168
+ Agent_swigregister = _marisa.Agent_swigregister
169
+ Agent_swigregister(Agent)
170
+
171
+ class Trie(_object):
172
+ __swig_setmethods__ = {}
173
+ __setattr__ = lambda self, name, value: _swig_setattr(self, Trie, name, value)
174
+ __swig_getmethods__ = {}
175
+ __getattr__ = lambda self, name: _swig_getattr(self, Trie, name)
176
+ __repr__ = _swig_repr
177
+ def __init__(self):
178
+ this = _marisa.new_Trie()
179
+ try: self.this.append(this)
180
+ except: self.this = this
181
+ __swig_destroy__ = _marisa.delete_Trie
182
+ __del__ = lambda self : None;
183
+ def build(self, *args): return _marisa.Trie_build(self, *args)
184
+ def mmap(self, *args): return _marisa.Trie_mmap(self, *args)
185
+ def load(self, *args): return _marisa.Trie_load(self, *args)
186
+ def save(self, *args): return _marisa.Trie_save(self, *args)
187
+ def common_prefix_search(self, *args): return _marisa.Trie_common_prefix_search(self, *args)
188
+ def predictive_search(self, *args): return _marisa.Trie_predictive_search(self, *args)
189
+ def lookup(self, *args): return _marisa.Trie_lookup(self, *args)
190
+ def reverse_lookup(self, *args): return _marisa.Trie_reverse_lookup(self, *args)
191
+ def num_tries(self): return _marisa.Trie_num_tries(self)
192
+ def num_keys(self): return _marisa.Trie_num_keys(self)
193
+ def num_nodes(self): return _marisa.Trie_num_nodes(self)
194
+ def tail_mode(self): return _marisa.Trie_tail_mode(self)
195
+ def node_order(self): return _marisa.Trie_node_order(self)
196
+ def empty(self): return _marisa.Trie_empty(self)
197
+ def size(self): return _marisa.Trie_size(self)
198
+ def total_size(self): return _marisa.Trie_total_size(self)
199
+ def io_size(self): return _marisa.Trie_io_size(self)
200
+ def clear(self): return _marisa.Trie_clear(self)
201
+ Trie_swigregister = _marisa.Trie_swigregister
202
+ Trie_swigregister(Trie)
203
+
204
+ INVALID_KEY_ID = _marisa.INVALID_KEY_ID
205
+
206
+