linkparser 1.0.4 → 1.1.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.
- data.tar.gz.sig +0 -0
- data/ChangeLog +134 -506
- data/LICENSE +1 -1
- data/README.md +95 -0
- data/Rakefile +145 -95
- data/Rakefile.local +31 -39
- data/ext/dictionary.c +103 -37
- data/ext/extconf.rb +79 -32
- data/ext/linkage.c +245 -210
- data/ext/linkparser.c +3 -2
- data/ext/linkparser.h +21 -17
- data/ext/parseoptions.c +65 -65
- data/ext/sentence.c +75 -64
- data/lib/linkparser.rb +16 -26
- data/lib/linkparser/linkage.rb +68 -50
- data/lib/linkparser/mixins.rb +38 -0
- data/lib/linkparser/sentence.rb +15 -40
- data/rake/dependencies.rb +1 -1
- data/rake/documentation.rb +123 -0
- data/rake/helpers.rb +400 -310
- data/rake/hg.rb +318 -0
- data/rake/manual.rb +84 -79
- data/rake/packaging.rb +33 -37
- data/rake/publishing.rb +166 -146
- data/rake/style.rb +1 -1
- data/rake/svn.rb +577 -549
- data/rake/testing.rb +55 -106
- data/spec/bugfixes_spec.rb +12 -6
- data/spec/linkparser/dictionary_spec.rb +45 -29
- data/spec/linkparser/linkage_spec.rb +90 -94
- data/spec/linkparser/mixins_spec.rb +67 -0
- data/spec/linkparser/parseoptions_spec.rb +19 -22
- data/spec/linkparser/sentence_spec.rb +19 -17
- data/spec/linkparser_spec.rb +11 -5
- metadata +64 -147
- metadata.gz.sig +0 -0
- data/README +0 -61
- data/rake/rdoc.rb +0 -40
- data/rake/win32.rb +0 -186
data/ext/linkparser.c
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* linkparser.c - Ruby LinkParser
|
3
|
-
* $Id: linkparser.c
|
3
|
+
* $Id: linkparser.c,v 53ec62029ee4 2010/10/12 15:45:26 ged $
|
4
4
|
*
|
5
5
|
* Authors:
|
6
6
|
* * Michael Granger <ged@FaerieMUD.org>
|
@@ -90,6 +90,7 @@ static VALUE
|
|
90
90
|
rlink_link_grammar_version( VALUE self ) {
|
91
91
|
#ifdef HAVE_LINKGRAMMAR_GET_VERSION
|
92
92
|
const char *version = linkgrammar_get_version();
|
93
|
+
if ( !version ) rb_bug( "linkgrammar_get_version returned NULL pointer" );
|
93
94
|
return rb_str_new2( version );
|
94
95
|
#else
|
95
96
|
return rb_str_new2( "link-grammar-4.3.9-or-earlier" );
|
@@ -109,7 +110,7 @@ Init_linkparser_ext() {
|
|
109
110
|
|
110
111
|
rb_define_singleton_method( rlink_mLinkParser, "link_grammar_version",
|
111
112
|
rlink_link_grammar_version, 0 );
|
112
|
-
|
113
|
+
|
113
114
|
setlocale( LC_ALL, "" );
|
114
115
|
|
115
116
|
rlink_init_dict();
|
data/ext/linkparser.h
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* linkparser.h - Ruby-LinkParser Header
|
3
|
-
* $Id: linkparser.h
|
3
|
+
* $Id: linkparser.h,v 53ec62029ee4 2010/10/12 15:45:26 ged $
|
4
4
|
*
|
5
5
|
* Authors:
|
6
6
|
* * Michael Granger <ged@FaerieMUD.org>
|
@@ -16,12 +16,12 @@
|
|
16
16
|
#include <locale.h>
|
17
17
|
#include <stdlib.h>
|
18
18
|
#include <stdio.h>
|
19
|
+
#include <assert.h>
|
19
20
|
|
20
|
-
#include
|
21
|
-
#include
|
22
|
-
|
23
|
-
#include <link-grammar/link-includes.h>
|
21
|
+
#include "ruby.h"
|
22
|
+
#include "ruby/intern.h"
|
24
23
|
|
24
|
+
#include "link-grammar/link-includes.h"
|
25
25
|
|
26
26
|
|
27
27
|
/* Debugging functions/macros */
|
@@ -62,18 +62,22 @@ extern VALUE rlink_eLpError;
|
|
62
62
|
|
63
63
|
/*
|
64
64
|
* Structures
|
65
|
-
*/
|
66
|
-
|
65
|
+
*/
|
66
|
+
struct rlink_dictionary {
|
67
|
+
Dictionary dict;
|
68
|
+
};
|
69
|
+
|
70
|
+
struct rlink_sentence {
|
67
71
|
Sentence sentence;
|
68
72
|
VALUE dictionary;
|
69
73
|
VALUE parsed_p;
|
70
74
|
VALUE options;
|
71
|
-
}
|
75
|
+
};
|
72
76
|
|
73
|
-
|
77
|
+
struct rlink_linkage {
|
74
78
|
Linkage linkage;
|
75
79
|
VALUE sentence;
|
76
|
-
}
|
80
|
+
};
|
77
81
|
|
78
82
|
|
79
83
|
|
@@ -98,15 +102,15 @@ typedef struct {
|
|
98
102
|
/* -------------------------------------------------------
|
99
103
|
* Initializer functions
|
100
104
|
* ------------------------------------------------------- */
|
101
|
-
extern void rlink_init_dict
|
102
|
-
extern void rlink_init_sentence
|
103
|
-
extern void rlink_init_linkage
|
104
|
-
extern void rlink_init_parseoptions
|
105
|
+
extern void rlink_init_dict _(( void ));
|
106
|
+
extern void rlink_init_sentence _(( void ));
|
107
|
+
extern void rlink_init_linkage _(( void ));
|
108
|
+
extern void rlink_init_parseoptions _(( void ));
|
105
109
|
|
106
110
|
/* Fetchers */
|
107
|
-
extern
|
108
|
-
extern
|
109
|
-
extern Parse_Options rlink_get_parseopts
|
111
|
+
extern struct rlink_dictionary * rlink_get_dict _(( VALUE ));
|
112
|
+
extern struct rlink_sentence *rlink_get_sentence _(( VALUE ));
|
113
|
+
extern Parse_Options rlink_get_parseopts _(( VALUE ));
|
110
114
|
|
111
115
|
#endif /* _R_LINKPARSER_H */
|
112
116
|
|
data/ext/parseoptions.c
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* parseoptions.c - Ruby LinkParser::ParseOptions class
|
3
|
-
* $Id: parseoptions.c
|
3
|
+
* $Id: parseoptions.c,v 53ec62029ee4 2010/10/12 15:45:26 ged $
|
4
4
|
*
|
5
5
|
* Authors:
|
6
6
|
* * Michael Granger <ged@FaerieMUD.org>
|
@@ -48,7 +48,7 @@ check_parseopts( VALUE self ) {
|
|
48
48
|
rb_raise( rb_eTypeError, "wrong argument type %s (expected LinkParser::ParseOptions)",
|
49
49
|
rb_class2name(CLASS_OF( self )) );
|
50
50
|
}
|
51
|
-
|
51
|
+
|
52
52
|
return DATA_PTR( self );
|
53
53
|
}
|
54
54
|
|
@@ -114,7 +114,7 @@ rlink_parseopts_init( int argc, VALUE *argv, VALUE self ) {
|
|
114
114
|
if ( ! check_parseopts(self) ) {
|
115
115
|
Parse_Options opts;
|
116
116
|
VALUE opthash = Qnil;
|
117
|
-
|
117
|
+
|
118
118
|
debugMsg(( "Initializing a ParseOptions: %p", self ));
|
119
119
|
DATA_PTR( self ) = opts = parse_options_create();
|
120
120
|
|
@@ -124,7 +124,7 @@ rlink_parseopts_init( int argc, VALUE *argv, VALUE self ) {
|
|
124
124
|
rb_iterate( rb_each, opthash, rlink_parseopts_each_opthash_i, self );
|
125
125
|
}
|
126
126
|
}
|
127
|
-
|
127
|
+
|
128
128
|
else {
|
129
129
|
rb_raise( rb_eRuntimeError, "Cannot re-initialize a Dictionary object." );
|
130
130
|
}
|
@@ -142,19 +142,19 @@ rlink_parseopts_each_opthash_i( VALUE pair, VALUE self ) {
|
|
142
142
|
VALUE key, val, keystring;
|
143
143
|
char *method_name;
|
144
144
|
ID method;
|
145
|
-
|
145
|
+
|
146
146
|
key = rb_ary_entry( pair, 0 );
|
147
147
|
val = rb_ary_entry( pair, 1 );
|
148
148
|
|
149
149
|
keystring = rb_obj_as_string( key );
|
150
|
-
|
151
|
-
method_name = ALLOCA_N( char,
|
152
|
-
strncpy( method_name,
|
150
|
+
|
151
|
+
method_name = ALLOCA_N( char, RSTRING_LEN(keystring) + 1 );
|
152
|
+
strncpy( method_name, RSTRING_PTR(keystring), RSTRING_LEN(keystring) + 1 );
|
153
153
|
strncat( method_name, "=", 1 );
|
154
|
-
|
154
|
+
|
155
155
|
debugMsg(( "Calling method %s", method_name ));
|
156
156
|
method = rb_intern( method_name );
|
157
|
-
|
157
|
+
|
158
158
|
return rb_funcall( self, method, 1, val );
|
159
159
|
}
|
160
160
|
|
@@ -168,7 +168,7 @@ rlink_parseopts_each_opthash_i( VALUE pair, VALUE self ) {
|
|
168
168
|
*/
|
169
169
|
/*static VALUE
|
170
170
|
rlink_parseopts_merge( VALUE self, other ) {
|
171
|
-
|
171
|
+
|
172
172
|
}
|
173
173
|
*/
|
174
174
|
|
@@ -1105,7 +1105,7 @@ rlink_parseopts_reset_resources( VALUE self ) {
|
|
1105
1105
|
*/
|
1106
1106
|
void
|
1107
1107
|
rlink_init_parseoptions() {
|
1108
|
-
rlink_cParseOptions = rb_define_class_under( rlink_mLinkParser,
|
1108
|
+
rlink_cParseOptions = rb_define_class_under( rlink_mLinkParser,
|
1109
1109
|
"ParseOptions", rb_cObject );
|
1110
1110
|
|
1111
1111
|
rb_define_alloc_func( rlink_cParseOptions, rlink_parseopts_s_alloc );
|
@@ -1114,113 +1114,113 @@ rlink_init_parseoptions() {
|
|
1114
1114
|
rb_define_method( rlink_cParseOptions, "merge", rlink_parseopts_merge, 1 );
|
1115
1115
|
rb_define_method( rlink_cParseOptions, "merge!", rlink_parseopts_merge_bang, 1 );
|
1116
1116
|
*/
|
1117
|
-
rb_define_method( rlink_cParseOptions, "verbosity=",
|
1117
|
+
rb_define_method( rlink_cParseOptions, "verbosity=",
|
1118
1118
|
rlink_parseopts_set_verbosity, 1 );
|
1119
|
-
rb_define_method( rlink_cParseOptions, "verbosity",
|
1119
|
+
rb_define_method( rlink_cParseOptions, "verbosity",
|
1120
1120
|
rlink_parseopts_get_verbosity, 0 );
|
1121
|
-
rb_define_method( rlink_cParseOptions, "linkage_limit=",
|
1121
|
+
rb_define_method( rlink_cParseOptions, "linkage_limit=",
|
1122
1122
|
rlink_parseopts_set_linkage_limit, 1 );
|
1123
|
-
rb_define_method( rlink_cParseOptions, "linkage_limit",
|
1123
|
+
rb_define_method( rlink_cParseOptions, "linkage_limit",
|
1124
1124
|
rlink_parseopts_get_linkage_limit, 0 );
|
1125
|
-
rb_define_method( rlink_cParseOptions, "disjunct_cost=",
|
1125
|
+
rb_define_method( rlink_cParseOptions, "disjunct_cost=",
|
1126
1126
|
rlink_parseopts_set_disjunct_cost, 1 );
|
1127
|
-
rb_define_method( rlink_cParseOptions, "disjunct_cost",
|
1127
|
+
rb_define_method( rlink_cParseOptions, "disjunct_cost",
|
1128
1128
|
rlink_parseopts_get_disjunct_cost, 0 );
|
1129
|
-
rb_define_method( rlink_cParseOptions, "min_null_count=",
|
1129
|
+
rb_define_method( rlink_cParseOptions, "min_null_count=",
|
1130
1130
|
rlink_parseopts_set_min_null_count, 1 );
|
1131
|
-
rb_define_method( rlink_cParseOptions, "min_null_count",
|
1131
|
+
rb_define_method( rlink_cParseOptions, "min_null_count",
|
1132
1132
|
rlink_parseopts_get_min_null_count, 0 );
|
1133
|
-
rb_define_method( rlink_cParseOptions, "max_null_count=",
|
1133
|
+
rb_define_method( rlink_cParseOptions, "max_null_count=",
|
1134
1134
|
rlink_parseopts_set_max_null_count, 1 );
|
1135
|
-
rb_define_method( rlink_cParseOptions, "max_null_count",
|
1135
|
+
rb_define_method( rlink_cParseOptions, "max_null_count",
|
1136
1136
|
rlink_parseopts_get_max_null_count, 0 );
|
1137
|
-
rb_define_method( rlink_cParseOptions, "null_block=",
|
1137
|
+
rb_define_method( rlink_cParseOptions, "null_block=",
|
1138
1138
|
rlink_parseopts_set_null_block, 1 );
|
1139
|
-
rb_define_method( rlink_cParseOptions, "null_block",
|
1139
|
+
rb_define_method( rlink_cParseOptions, "null_block",
|
1140
1140
|
rlink_parseopts_get_null_block, 0 );
|
1141
|
-
rb_define_method( rlink_cParseOptions, "islands_ok=",
|
1141
|
+
rb_define_method( rlink_cParseOptions, "islands_ok=",
|
1142
1142
|
rlink_parseopts_set_islands_ok, 1 );
|
1143
|
-
rb_define_method( rlink_cParseOptions, "islands_ok?",
|
1143
|
+
rb_define_method( rlink_cParseOptions, "islands_ok?",
|
1144
1144
|
rlink_parseopts_get_islands_ok_p, 0 );
|
1145
|
-
rb_define_method( rlink_cParseOptions, "short_length=",
|
1145
|
+
rb_define_method( rlink_cParseOptions, "short_length=",
|
1146
1146
|
rlink_parseopts_set_short_length, 1 );
|
1147
|
-
rb_define_method( rlink_cParseOptions, "short_length",
|
1147
|
+
rb_define_method( rlink_cParseOptions, "short_length",
|
1148
1148
|
rlink_parseopts_get_short_length, 0 );
|
1149
|
-
rb_define_method( rlink_cParseOptions, "max_memory=",
|
1149
|
+
rb_define_method( rlink_cParseOptions, "max_memory=",
|
1150
1150
|
rlink_parseopts_set_max_memory, 1 );
|
1151
|
-
rb_define_method( rlink_cParseOptions, "max_memory",
|
1151
|
+
rb_define_method( rlink_cParseOptions, "max_memory",
|
1152
1152
|
rlink_parseopts_get_max_memory, 0 );
|
1153
|
-
rb_define_method( rlink_cParseOptions, "max_sentence_length=",
|
1153
|
+
rb_define_method( rlink_cParseOptions, "max_sentence_length=",
|
1154
1154
|
rlink_parseopts_set_max_sentence_length, 1 );
|
1155
|
-
rb_define_method( rlink_cParseOptions, "max_sentence_length",
|
1155
|
+
rb_define_method( rlink_cParseOptions, "max_sentence_length",
|
1156
1156
|
rlink_parseopts_get_max_sentence_length, 0 );
|
1157
|
-
rb_define_method( rlink_cParseOptions, "max_parse_time=",
|
1157
|
+
rb_define_method( rlink_cParseOptions, "max_parse_time=",
|
1158
1158
|
rlink_parseopts_set_max_parse_time, 1 );
|
1159
|
-
rb_define_method( rlink_cParseOptions, "max_parse_time",
|
1159
|
+
rb_define_method( rlink_cParseOptions, "max_parse_time",
|
1160
1160
|
rlink_parseopts_get_max_parse_time, 0 );
|
1161
|
-
rb_define_method( rlink_cParseOptions, "screen_width=",
|
1161
|
+
rb_define_method( rlink_cParseOptions, "screen_width=",
|
1162
1162
|
rlink_parseopts_set_screen_width, 1 );
|
1163
|
-
rb_define_method( rlink_cParseOptions, "screen_width",
|
1163
|
+
rb_define_method( rlink_cParseOptions, "screen_width",
|
1164
1164
|
rlink_parseopts_get_screen_width, 0 );
|
1165
|
-
rb_define_method( rlink_cParseOptions, "allow_null=",
|
1165
|
+
rb_define_method( rlink_cParseOptions, "allow_null=",
|
1166
1166
|
rlink_parseopts_set_allow_null, 1 );
|
1167
|
-
rb_define_method( rlink_cParseOptions, "allow_null?",
|
1167
|
+
rb_define_method( rlink_cParseOptions, "allow_null?",
|
1168
1168
|
rlink_parseopts_get_allow_null_p, 0 );
|
1169
|
-
rb_define_method( rlink_cParseOptions, "display_walls=",
|
1169
|
+
rb_define_method( rlink_cParseOptions, "display_walls=",
|
1170
1170
|
rlink_parseopts_set_display_walls, 1 );
|
1171
|
-
rb_define_method( rlink_cParseOptions, "display_walls?",
|
1171
|
+
rb_define_method( rlink_cParseOptions, "display_walls?",
|
1172
1172
|
rlink_parseopts_get_display_walls_p, 0 );
|
1173
|
-
rb_define_method( rlink_cParseOptions, "all_short_connectors=",
|
1173
|
+
rb_define_method( rlink_cParseOptions, "all_short_connectors=",
|
1174
1174
|
rlink_parseopts_set_all_short_connectors, 1 );
|
1175
|
-
rb_define_method( rlink_cParseOptions, "all_short_connectors?",
|
1175
|
+
rb_define_method( rlink_cParseOptions, "all_short_connectors?",
|
1176
1176
|
rlink_parseopts_get_all_short_connectors_p, 0 );
|
1177
|
-
rb_define_method( rlink_cParseOptions, "cost_model_type=",
|
1177
|
+
rb_define_method( rlink_cParseOptions, "cost_model_type=",
|
1178
1178
|
rlink_parseopts_set_cost_model_type, 1 );
|
1179
1179
|
|
1180
1180
|
/* (No way to get the cost_model_type from the API)
|
1181
1181
|
|
1182
|
-
rb_define_method( rlink_cParseOptions, "cost_model_type",
|
1182
|
+
rb_define_method( rlink_cParseOptions, "cost_model_type",
|
1183
1183
|
rlink_parseopts_get_cost_model_type, 0 );
|
1184
1184
|
*/
|
1185
|
-
rb_define_method( rlink_cParseOptions, "batch_mode=",
|
1185
|
+
rb_define_method( rlink_cParseOptions, "batch_mode=",
|
1186
1186
|
rlink_parseopts_set_batch_mode, 1 );
|
1187
|
-
rb_define_method( rlink_cParseOptions, "batch_mode?",
|
1187
|
+
rb_define_method( rlink_cParseOptions, "batch_mode?",
|
1188
1188
|
rlink_parseopts_get_batch_mode_p, 0 );
|
1189
|
-
rb_define_method( rlink_cParseOptions, "panic_mode=",
|
1189
|
+
rb_define_method( rlink_cParseOptions, "panic_mode=",
|
1190
1190
|
rlink_parseopts_set_panic_mode, 1 );
|
1191
|
-
rb_define_method( rlink_cParseOptions, "panic_mode?",
|
1191
|
+
rb_define_method( rlink_cParseOptions, "panic_mode?",
|
1192
1192
|
rlink_parseopts_get_panic_mode_p, 0 );
|
1193
|
-
rb_define_method( rlink_cParseOptions, "display_on=",
|
1193
|
+
rb_define_method( rlink_cParseOptions, "display_on=",
|
1194
1194
|
rlink_parseopts_set_display_on, 1 );
|
1195
|
-
rb_define_method( rlink_cParseOptions, "display_on?",
|
1195
|
+
rb_define_method( rlink_cParseOptions, "display_on?",
|
1196
1196
|
rlink_parseopts_get_display_on_p, 0 );
|
1197
|
-
rb_define_method( rlink_cParseOptions, "display_postscript=",
|
1197
|
+
rb_define_method( rlink_cParseOptions, "display_postscript=",
|
1198
1198
|
rlink_parseopts_set_display_postscript, 1 );
|
1199
|
-
rb_define_method( rlink_cParseOptions, "display_postscript?",
|
1199
|
+
rb_define_method( rlink_cParseOptions, "display_postscript?",
|
1200
1200
|
rlink_parseopts_get_display_postscript_p, 0 );
|
1201
|
-
rb_define_method( rlink_cParseOptions, "display_constituents=",
|
1201
|
+
rb_define_method( rlink_cParseOptions, "display_constituents=",
|
1202
1202
|
rlink_parseopts_set_display_constituents, 1 );
|
1203
|
-
rb_define_method( rlink_cParseOptions, "display_constituents?",
|
1203
|
+
rb_define_method( rlink_cParseOptions, "display_constituents?",
|
1204
1204
|
rlink_parseopts_get_display_constituents_p, 0 );
|
1205
|
-
rb_define_method( rlink_cParseOptions, "display_bad=",
|
1205
|
+
rb_define_method( rlink_cParseOptions, "display_bad=",
|
1206
1206
|
rlink_parseopts_set_display_bad, 1 );
|
1207
|
-
rb_define_method( rlink_cParseOptions, "display_bad?",
|
1207
|
+
rb_define_method( rlink_cParseOptions, "display_bad?",
|
1208
1208
|
rlink_parseopts_get_display_bad_p, 0 );
|
1209
|
-
rb_define_method( rlink_cParseOptions, "display_links=",
|
1209
|
+
rb_define_method( rlink_cParseOptions, "display_links=",
|
1210
1210
|
rlink_parseopts_set_display_links, 1 );
|
1211
|
-
rb_define_method( rlink_cParseOptions, "display_links?",
|
1211
|
+
rb_define_method( rlink_cParseOptions, "display_links?",
|
1212
1212
|
rlink_parseopts_get_display_links_p, 0 );
|
1213
|
-
rb_define_method( rlink_cParseOptions, "display_union=",
|
1213
|
+
rb_define_method( rlink_cParseOptions, "display_union=",
|
1214
1214
|
rlink_parseopts_set_display_union, 1 );
|
1215
|
-
rb_define_method( rlink_cParseOptions, "display_union?",
|
1215
|
+
rb_define_method( rlink_cParseOptions, "display_union?",
|
1216
1216
|
rlink_parseopts_get_display_union_p, 0 );
|
1217
|
-
rb_define_method( rlink_cParseOptions, "echo_on=",
|
1217
|
+
rb_define_method( rlink_cParseOptions, "echo_on=",
|
1218
1218
|
rlink_parseopts_set_echo_on, 1 );
|
1219
|
-
rb_define_method( rlink_cParseOptions, "echo_on?",
|
1219
|
+
rb_define_method( rlink_cParseOptions, "echo_on?",
|
1220
1220
|
rlink_parseopts_get_echo_on_p, 0 );
|
1221
|
-
rb_define_method( rlink_cParseOptions, "spell_guessing_enabled=",
|
1221
|
+
rb_define_method( rlink_cParseOptions, "spell_guessing_enabled=",
|
1222
1222
|
rlink_parseopts_set_spell_guess, 1 );
|
1223
|
-
rb_define_method( rlink_cParseOptions, "spell_guessing_enabled?",
|
1223
|
+
rb_define_method( rlink_cParseOptions, "spell_guessing_enabled?",
|
1224
1224
|
rlink_parseopts_get_spell_guess_p, 0 );
|
1225
1225
|
|
1226
1226
|
rb_define_method( rlink_cParseOptions, "timer_expired?",
|
@@ -1231,6 +1231,6 @@ rlink_init_parseoptions() {
|
|
1231
1231
|
rlink_parseopts_resources_exhausted_p, 0 );
|
1232
1232
|
rb_define_method( rlink_cParseOptions, "reset_resources",
|
1233
1233
|
rlink_parseopts_reset_resources, 0 );
|
1234
|
-
|
1234
|
+
|
1235
1235
|
}
|
1236
1236
|
|
data/ext/sentence.c
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* sentence.c - Ruby LinkParser
|
3
|
-
* $Id: sentence.c
|
3
|
+
* $Id: sentence.c,v 53ec62029ee4 2010/10/12 15:45:26 ged $
|
4
4
|
*
|
5
5
|
* Authors:
|
6
6
|
* * Michael Granger <ged@FaerieMUD.org>
|
@@ -29,16 +29,16 @@
|
|
29
29
|
/*
|
30
30
|
* Allocation function
|
31
31
|
*/
|
32
|
-
static
|
32
|
+
static struct rlink_sentence *
|
33
33
|
rlink_sentence_alloc() {
|
34
|
-
|
35
|
-
|
34
|
+
struct rlink_sentence *ptr = ALLOC( struct rlink_sentence );
|
35
|
+
|
36
36
|
ptr->sentence = NULL;
|
37
37
|
ptr->dictionary = Qnil;
|
38
38
|
ptr->parsed_p = Qfalse;
|
39
39
|
ptr->options = Qnil;
|
40
|
-
|
41
|
-
debugMsg(( "Initialized an
|
40
|
+
|
41
|
+
debugMsg(( "Initialized an rlink_sentence <%p>", ptr ));
|
42
42
|
return ptr;
|
43
43
|
}
|
44
44
|
|
@@ -47,16 +47,16 @@ rlink_sentence_alloc() {
|
|
47
47
|
* GC Mark function
|
48
48
|
*/
|
49
49
|
static void
|
50
|
-
rlink_sentence_gc_mark(
|
50
|
+
rlink_sentence_gc_mark( struct rlink_sentence *ptr ) {
|
51
51
|
debugMsg(( "Marking LinkParser::Sentence %p", ptr ));
|
52
|
-
|
52
|
+
|
53
53
|
if ( ptr ) {
|
54
54
|
rb_gc_mark( ptr->dictionary );
|
55
55
|
rb_gc_mark( ptr->options );
|
56
56
|
}
|
57
|
-
|
57
|
+
|
58
58
|
else {
|
59
|
-
debugMsg(( "Not marking uninitialized
|
59
|
+
debugMsg(( "Not marking uninitialized rlink_sentence struct" ));
|
60
60
|
}
|
61
61
|
}
|
62
62
|
|
@@ -65,24 +65,35 @@ rlink_sentence_gc_mark( rlink_SENTENCE *ptr ) {
|
|
65
65
|
* GC Free function
|
66
66
|
*/
|
67
67
|
static void
|
68
|
-
rlink_sentence_gc_free(
|
68
|
+
rlink_sentence_gc_free( struct rlink_sentence *ptr ) {
|
69
69
|
if ( ptr ) {
|
70
70
|
debugMsg(( "In free function of Sentence <%p>", ptr ));
|
71
|
-
|
72
|
-
if (
|
73
|
-
|
74
|
-
|
71
|
+
|
72
|
+
if ( ptr->dictionary && TYPE(ptr->dictionary) == T_DATA ) {
|
73
|
+
struct rlink_dictionary *dictionary = rlink_get_dict( ptr->dictionary );
|
74
|
+
debugMsg(( " sentence's dictionary is: <%p>", dictionary ));
|
75
|
+
|
76
|
+
/* Freeing the dictionary automatically frees the sentences it belongs to, so
|
77
|
+
don't double-free if the dictionary struct or its pointer is done. */
|
78
|
+
if ( dictionary->dict ) {
|
79
|
+
debugMsg(( " deleting Sentence <%p>", ptr->sentence ));
|
80
|
+
sentence_delete( (Sentence)ptr->sentence );
|
81
|
+
}
|
75
82
|
} else {
|
76
|
-
debugMsg(( "
|
83
|
+
debugMsg(( " not deleting a Sentence belonging to an already-freed dictionary." ));
|
77
84
|
}
|
78
85
|
|
79
86
|
ptr->sentence = NULL;
|
80
87
|
ptr->options = Qnil;
|
81
88
|
ptr->dictionary = Qnil;
|
89
|
+
|
90
|
+
debugMsg(( " freeing rlink_sentence <%p>", ptr ));
|
91
|
+
xfree( ptr );
|
92
|
+
ptr = NULL;
|
82
93
|
}
|
83
|
-
|
94
|
+
|
84
95
|
else {
|
85
|
-
debugMsg(( "Not freeing an uninitialized
|
96
|
+
debugMsg(( "Not freeing an uninitialized rlink_sentence struct" ));
|
86
97
|
}
|
87
98
|
}
|
88
99
|
|
@@ -90,7 +101,7 @@ rlink_sentence_gc_free( rlink_SENTENCE *ptr ) {
|
|
90
101
|
/*
|
91
102
|
* Object validity checker. Returns the data pointer.
|
92
103
|
*/
|
93
|
-
static
|
104
|
+
static struct rlink_sentence *
|
94
105
|
check_sentence( VALUE self ) {
|
95
106
|
Check_Type( self, T_DATA );
|
96
107
|
|
@@ -98,7 +109,7 @@ check_sentence( VALUE self ) {
|
|
98
109
|
rb_raise( rb_eTypeError, "wrong argument type %s (expected LinkParser::Sentence)",
|
99
110
|
rb_class2name(CLASS_OF( self )) );
|
100
111
|
}
|
101
|
-
|
112
|
+
|
102
113
|
return DATA_PTR( self );
|
103
114
|
}
|
104
115
|
|
@@ -106,9 +117,9 @@ check_sentence( VALUE self ) {
|
|
106
117
|
/*
|
107
118
|
* Fetch the data pointer and check it for sanity.
|
108
119
|
*/
|
109
|
-
static
|
120
|
+
static struct rlink_sentence *
|
110
121
|
get_sentence( VALUE self ) {
|
111
|
-
|
122
|
+
struct rlink_sentence *ptr = check_sentence( self );
|
112
123
|
|
113
124
|
if ( !ptr )
|
114
125
|
rb_raise( rb_eRuntimeError, "uninitialized Sentence" );
|
@@ -120,7 +131,7 @@ get_sentence( VALUE self ) {
|
|
120
131
|
/*
|
121
132
|
* Publicly-usable sentence-fetcher
|
122
133
|
*/
|
123
|
-
|
134
|
+
struct rlink_sentence *
|
124
135
|
rlink_get_sentence( VALUE self ) {
|
125
136
|
return get_sentence( self );
|
126
137
|
}
|
@@ -162,19 +173,19 @@ rlink_sentence_s_alloc( VALUE klass ) {
|
|
162
173
|
static VALUE
|
163
174
|
rlink_sentence_init( VALUE self, VALUE input_string, VALUE dictionary ) {
|
164
175
|
if ( !check_sentence(self) ) {
|
165
|
-
|
176
|
+
struct rlink_sentence *ptr;
|
166
177
|
Sentence sent;
|
167
|
-
|
168
|
-
|
169
|
-
if ( !(sent = sentence_create( StringValueCStr(input_string), dict )) )
|
178
|
+
struct rlink_dictionary *dictptr = rlink_get_dict( dictionary );
|
179
|
+
|
180
|
+
if ( !(sent = sentence_create( StringValueCStr(input_string), dictptr->dict )) )
|
170
181
|
rlink_raise_lp_error();
|
171
182
|
|
172
183
|
DATA_PTR( self ) = ptr = rlink_sentence_alloc();
|
173
|
-
|
184
|
+
|
174
185
|
ptr->sentence = sent;
|
175
186
|
ptr->dictionary = dictionary;
|
176
187
|
ptr->options = Qnil;
|
177
|
-
|
188
|
+
|
178
189
|
} else {
|
179
190
|
rb_raise( rb_eRuntimeError,
|
180
191
|
"Cannot re-initialize a sentence once it's been created." );
|
@@ -195,7 +206,7 @@ rlink_sentence_init( VALUE self, VALUE input_string, VALUE dictionary ) {
|
|
195
206
|
*/
|
196
207
|
static VALUE
|
197
208
|
rlink_sentence_parse( int argc, VALUE *argv, VALUE self ) {
|
198
|
-
|
209
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
199
210
|
Parse_Options opts;
|
200
211
|
VALUE defopts = Qnil;
|
201
212
|
VALUE options = Qnil;
|
@@ -223,7 +234,7 @@ rlink_sentence_parse( int argc, VALUE *argv, VALUE self ) {
|
|
223
234
|
|
224
235
|
ptr->options = options;
|
225
236
|
ptr->parsed_p = Qtrue;
|
226
|
-
|
237
|
+
|
227
238
|
return INT2FIX( link_count );
|
228
239
|
}
|
229
240
|
|
@@ -240,7 +251,7 @@ rlink_sentence_parse( int argc, VALUE *argv, VALUE self ) {
|
|
240
251
|
*/
|
241
252
|
static VALUE
|
242
253
|
rlink_sentence_parsed_p( VALUE self ) {
|
243
|
-
|
254
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
244
255
|
return ptr->parsed_p;
|
245
256
|
}
|
246
257
|
|
@@ -256,7 +267,7 @@ rlink_sentence_parsed_p( VALUE self ) {
|
|
256
267
|
*/
|
257
268
|
static VALUE
|
258
269
|
rlink_sentence_options( VALUE self ) {
|
259
|
-
|
270
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
260
271
|
return ptr->options;
|
261
272
|
}
|
262
273
|
|
@@ -273,7 +284,7 @@ rlink_sentence_options( VALUE self ) {
|
|
273
284
|
*/
|
274
285
|
static VALUE
|
275
286
|
rlink_sentence_linkages( VALUE self ) {
|
276
|
-
|
287
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
277
288
|
int i, count = 0;
|
278
289
|
VALUE rary;
|
279
290
|
|
@@ -282,18 +293,18 @@ rlink_sentence_linkages( VALUE self ) {
|
|
282
293
|
|
283
294
|
count = sentence_num_valid_linkages( (Sentence)ptr->sentence );
|
284
295
|
rary = rb_ary_new2( count );
|
285
|
-
|
296
|
+
|
286
297
|
for ( i = 0; i < count; i++ ) {
|
287
298
|
VALUE linkage;
|
288
299
|
VALUE args[2];
|
289
|
-
|
300
|
+
|
290
301
|
args[0] = INT2FIX( i );
|
291
302
|
args[1] = self;
|
292
|
-
|
303
|
+
|
293
304
|
linkage = rb_class_new_instance( 2, args, rlink_cLinkage );
|
294
305
|
rb_ary_store( rary, i, linkage );
|
295
306
|
}
|
296
|
-
|
307
|
+
|
297
308
|
return rary;
|
298
309
|
}
|
299
310
|
|
@@ -309,14 +320,14 @@ rlink_sentence_linkages( VALUE self ) {
|
|
309
320
|
|
310
321
|
static VALUE
|
311
322
|
rlink_sentence_length( VALUE self ) {
|
312
|
-
|
323
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
313
324
|
|
314
325
|
if ( !RTEST(ptr->parsed_p) )
|
315
326
|
rlink_sentence_parse( 0, 0, self );
|
316
327
|
|
317
328
|
return INT2FIX( sentence_length((Sentence)ptr->sentence) );
|
318
329
|
}
|
319
|
-
|
330
|
+
|
320
331
|
|
321
332
|
/*
|
322
333
|
* call-seq:
|
@@ -327,9 +338,9 @@ rlink_sentence_length( VALUE self ) {
|
|
327
338
|
*/
|
328
339
|
static VALUE
|
329
340
|
rlink_sentence_word( VALUE self, VALUE n ) {
|
330
|
-
|
341
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
331
342
|
const char *word;
|
332
|
-
|
343
|
+
|
333
344
|
if ( !RTEST(ptr->parsed_p) )
|
334
345
|
rlink_sentence_parse( 0, 0, self );
|
335
346
|
|
@@ -349,11 +360,11 @@ rlink_sentence_word( VALUE self, VALUE n ) {
|
|
349
360
|
*/
|
350
361
|
static VALUE
|
351
362
|
rlink_sentence_words( VALUE self ) {
|
352
|
-
|
363
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
353
364
|
const char *word;
|
354
365
|
int i, length;
|
355
366
|
VALUE words = rb_ary_new();
|
356
|
-
|
367
|
+
|
357
368
|
if ( !RTEST(ptr->parsed_p) )
|
358
369
|
rlink_sentence_parse( 0, 0, self );
|
359
370
|
|
@@ -363,7 +374,7 @@ rlink_sentence_words( VALUE self ) {
|
|
363
374
|
debugMsg(( "Word %d: <%s>", i, word ));
|
364
375
|
rb_ary_push( words, rb_str_new2(word) );
|
365
376
|
}
|
366
|
-
|
377
|
+
|
367
378
|
return words;
|
368
379
|
}
|
369
380
|
|
@@ -406,16 +417,16 @@ rlink_sentence_aref( argc, argv, self )
|
|
406
417
|
*/
|
407
418
|
static VALUE
|
408
419
|
rlink_sentence_null_count( VALUE self ) {
|
409
|
-
|
420
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
410
421
|
int count;
|
411
|
-
|
422
|
+
|
412
423
|
if ( !RTEST(ptr->parsed_p) )
|
413
424
|
rlink_sentence_parse( 0, 0, self );
|
414
425
|
|
415
426
|
count = sentence_null_count( (Sentence)ptr->sentence );
|
416
427
|
return INT2FIX( count );
|
417
428
|
}
|
418
|
-
|
429
|
+
|
419
430
|
|
420
431
|
/*
|
421
432
|
* call-seq:
|
@@ -426,14 +437,14 @@ rlink_sentence_null_count( VALUE self ) {
|
|
426
437
|
*/
|
427
438
|
static VALUE
|
428
439
|
rlink_sentence_num_linkages_found( VALUE self ) {
|
429
|
-
|
440
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
430
441
|
int i = 0;
|
431
|
-
|
442
|
+
|
432
443
|
if ( !RTEST(ptr->parsed_p) )
|
433
444
|
rlink_sentence_parse( 0, 0, self );
|
434
445
|
|
435
446
|
i = sentence_num_linkages_found( (Sentence)ptr->sentence );
|
436
|
-
|
447
|
+
|
437
448
|
return INT2FIX( i );
|
438
449
|
}
|
439
450
|
|
@@ -446,16 +457,16 @@ rlink_sentence_num_linkages_found( VALUE self ) {
|
|
446
457
|
*/
|
447
458
|
static VALUE
|
448
459
|
rlink_sentence_num_valid_linkages( VALUE self ) {
|
449
|
-
|
460
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
450
461
|
int count;
|
451
|
-
|
462
|
+
|
452
463
|
if ( !RTEST(ptr->parsed_p) )
|
453
464
|
rlink_sentence_parse( 0, 0, self );
|
454
465
|
|
455
466
|
count = sentence_num_valid_linkages( (Sentence)ptr->sentence );
|
456
467
|
return INT2FIX( count );
|
457
468
|
}
|
458
|
-
|
469
|
+
|
459
470
|
|
460
471
|
/*
|
461
472
|
* call-seq:
|
@@ -466,16 +477,16 @@ rlink_sentence_num_valid_linkages( VALUE self ) {
|
|
466
477
|
*/
|
467
478
|
static VALUE
|
468
479
|
rlink_sentence_num_linkages_post_processed( VALUE self ) {
|
469
|
-
|
480
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
470
481
|
int count;
|
471
|
-
|
482
|
+
|
472
483
|
if ( !RTEST(ptr->parsed_p) )
|
473
484
|
rlink_sentence_parse( 0, 0, self );
|
474
485
|
|
475
486
|
count = sentence_num_linkages_post_processed( (Sentence)ptr->sentence );
|
476
487
|
return INT2FIX( count );
|
477
488
|
}
|
478
|
-
|
489
|
+
|
479
490
|
|
480
491
|
/*
|
481
492
|
* call-seq:
|
@@ -486,16 +497,16 @@ rlink_sentence_num_linkages_post_processed( VALUE self ) {
|
|
486
497
|
*/
|
487
498
|
static VALUE
|
488
499
|
rlink_sentence_num_violations( VALUE self, VALUE i ) {
|
489
|
-
|
500
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
490
501
|
int count;
|
491
|
-
|
502
|
+
|
492
503
|
if ( !RTEST(ptr->parsed_p) )
|
493
504
|
rlink_sentence_parse( 0, 0, self );
|
494
505
|
|
495
506
|
count = sentence_num_violations( (Sentence)ptr->sentence, FIX2INT(i) );
|
496
507
|
return INT2FIX( count );
|
497
508
|
}
|
498
|
-
|
509
|
+
|
499
510
|
|
500
511
|
/*
|
501
512
|
* call-seq:
|
@@ -505,16 +516,16 @@ rlink_sentence_num_violations( VALUE self, VALUE i ) {
|
|
505
516
|
*/
|
506
517
|
static VALUE
|
507
518
|
rlink_sentence_disjunct_cost( VALUE self, VALUE i ) {
|
508
|
-
|
519
|
+
struct rlink_sentence *ptr = get_sentence( self );
|
509
520
|
int count;
|
510
|
-
|
521
|
+
|
511
522
|
if ( !RTEST(ptr->parsed_p) )
|
512
523
|
rlink_sentence_parse( 0, 0, self );
|
513
524
|
|
514
525
|
count = sentence_disjunct_cost( (Sentence)ptr->sentence, FIX2INT(i) );
|
515
526
|
return INT2FIX( count );
|
516
527
|
}
|
517
|
-
|
528
|
+
|
518
529
|
|
519
530
|
/*
|
520
531
|
* Document-class: LinkParser::Sentence
|
@@ -529,7 +540,7 @@ void
|
|
529
540
|
rlink_init_sentence() {
|
530
541
|
rlink_cSentence = rb_define_class_under( rlink_mLinkParser, "Sentence",
|
531
542
|
rb_cObject );
|
532
|
-
|
543
|
+
|
533
544
|
rb_define_alloc_func( rlink_cSentence, rlink_sentence_s_alloc );
|
534
545
|
|
535
546
|
rb_define_method( rlink_cSentence, "initialize", rlink_sentence_init, 2 );
|