linkparser 1.1.3 → 2.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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.md +68 -3
- data/README.md +66 -47
- data/ext/{dictionary.c → linkparser_ext/dictionary.c} +61 -66
- data/ext/{extconf.rb → linkparser_ext/extconf.rb} +10 -3
- data/ext/{linkage.c → linkparser_ext/linkage.c} +121 -358
- data/ext/{linkparser.c → linkparser_ext/linkparser.c} +79 -28
- data/ext/{linkparser.h → linkparser_ext/linkparser.h} +14 -16
- data/ext/linkparser_ext/parseoptions.c +776 -0
- data/ext/{sentence.c → linkparser_ext/sentence.c} +65 -151
- data/lib/linkparser.rb +14 -6
- data/lib/linkparser/dictionary.rb +13 -0
- data/lib/linkparser/linkage.rb +271 -166
- data/lib/linkparser/mixins.rb +2 -3
- data/lib/linkparser/parseoptions.rb +58 -0
- data/lib/linkparser/sentence.rb +21 -38
- data/spec/bugfixes_spec.rb +23 -36
- data/spec/helpers.rb +39 -0
- data/spec/linkparser/dictionary_spec.rb +29 -48
- data/spec/linkparser/linkage_spec.rb +212 -276
- data/spec/linkparser/mixins_spec.rb +9 -24
- data/spec/linkparser/parseoptions_spec.rb +47 -59
- data/spec/linkparser/sentence_spec.rb +36 -56
- data/spec/linkparser_spec.rb +11 -25
- metadata +134 -174
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
- data/ChangeLog +0 -670
- data/LICENSE +0 -27
- data/Rakefile +0 -91
- data/ext/parseoptions.c +0 -1236
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0fdb3ebc1f449d0bcbdf3b4a1c69b0b417abd68642ac64d9df62cc2ccf330ba5
|
4
|
+
data.tar.gz: 1ea9b2c22a7a3212ca9fdae2e2640344e73f06331c451289bcac1fbe7c283940
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8484674e2df9d3eee3844db974a28d06b4030b6609418b6b1d54641ec0e67099632955c6ebd9276bbf23353a66cbf082472791a4764834160f70a04cd8b8f20
|
7
|
+
data.tar.gz: ed5d589f141897ec1b703f3f0d30628f418e1eca728f6d5d60b9e034ae5ed85956ac1897e33ed77692a8756bdc66965fbb6a8e2525818b9c00eafcbeddc4f9e6
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.md
CHANGED
@@ -1,17 +1,82 @@
|
|
1
|
-
|
1
|
+
# Release History for linkparser
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
## v2.2.0 [2020-12-24] Michael Granger <ged@faeriemud.org>
|
6
|
+
|
7
|
+
Enhancements:
|
8
|
+
|
9
|
+
- Updated for Ruby 2.7
|
10
|
+
- Add support for fetching the link-grammar config.
|
11
|
+
- Updated for link-grammar 5.8.0.
|
12
|
+
|
13
|
+
|
14
|
+
## v2.1.0 [2018-01-10] Michael Granger <ged@FaerieMUD.org>
|
15
|
+
|
16
|
+
Enhancements:
|
17
|
+
|
18
|
+
- Update for the latest link-grammar (5.4.3)
|
19
|
+
|
20
|
+
Bugfixes:
|
21
|
+
|
22
|
+
- Fix LinkParser.link_grammar_version
|
23
|
+
- Eliminate weird calls to rb_funcall with explicit null pointers (Ruby 2.5)
|
24
|
+
- Eliminate use of deprecated Fixnum constant (Ruby 2.5)
|
25
|
+
- Add a workaround and minimal test case for diagrams with very small widths
|
26
|
+
|
27
|
+
|
28
|
+
## v2.0.0 [2015-03-02] Michael Granger <ged@FaerieMUD.org>
|
29
|
+
|
30
|
+
Updated for the latest Ruby and link-grammar.
|
31
|
+
|
32
|
+
NOTE: This release breaks the API of previous releases. In the 5.x
|
33
|
+
release of the upstream library (link-grammar) a bunch of
|
34
|
+
long-deprecated functions were removed, so it was no longer possible
|
35
|
+
to maintain backward-compatibility.
|
36
|
+
|
37
|
+
The 1.x version of LinkParser should continue to work fine for
|
38
|
+
pre-5.x versions of link-grammar, and it will continue to be
|
39
|
+
maintained for the forseeable future.
|
40
|
+
|
41
|
+
|
42
|
+
## v1.1.4 [2012-01-31] Michael Granger <ged@FaerieMUD.org>
|
43
|
+
|
44
|
+
- Packaging fixes, dependency update
|
45
|
+
|
46
|
+
|
47
|
+
## v1.1.3 [2011-05-16] Michael Granger <ged@FaerieMUD.org>
|
48
|
+
|
49
|
+
- Use a relative path for path constants (Alessandro Berardi), update
|
50
|
+
deps
|
51
|
+
|
52
|
+
|
53
|
+
## v1.1.2 [2011-05-12] Michael Granger <ged@FaerieMUD.org>
|
54
|
+
|
55
|
+
- Fixes package configuration options concatenation bug (see
|
56
|
+
http://goo.gl/G49Y8) (Alessandro Berardi <berardialessandro@gmail.com>)
|
57
|
+
- De-Yard, build cleanup, added gem-testers support
|
58
|
+
- Removed unnecessary (and non-existant on Ruby < 1.9) include.
|
59
|
+
- Fixing some shadowed variables for 1.9.2.
|
60
|
+
- Avoid circular requires.
|
61
|
+
|
62
|
+
|
63
|
+
## v1.1.1 [2010-12-30] Michael Granger <ged@FaerieMUD.org>
|
2
64
|
|
3
65
|
* Updated for link-grammar 4.7.1.
|
4
66
|
* Fixed some specs that were doing nothing, using old RSpec syntax, etc.
|
5
67
|
* Converted to Hoe.
|
6
68
|
|
7
69
|
|
8
|
-
##
|
70
|
+
## v1.1.0 [2010-11-30] Michael Granger <ged@FaerieMUD.org>
|
9
71
|
|
10
72
|
* Updated to support link-grammar 4.7.0. Note that this breaks compatibility with
|
11
|
-
earlier versions, as the model for sentences with conjunctions has changed
|
73
|
+
earlier versions, as the model for sentences with conjunctions has changed
|
12
74
|
significantly.
|
13
75
|
* Use pkgconfig if available.
|
14
76
|
* Various memory-management and 1.9.2 fixes.
|
15
77
|
|
16
78
|
|
79
|
+
## v1.0.6 [2009-10-16] Michael Granger <ged@FaerieMUD.org>
|
80
|
+
|
81
|
+
[TODO]
|
17
82
|
|
data/README.md
CHANGED
@@ -1,56 +1,67 @@
|
|
1
1
|
# linkparser
|
2
2
|
|
3
|
-
|
3
|
+
home
|
4
|
+
: https://hg.sr.ht/~ged/linkparser
|
5
|
+
|
6
|
+
code
|
7
|
+
: https://hg.sr.ht/~ged/linkparser/browse
|
8
|
+
|
9
|
+
docs
|
10
|
+
: http://deveiate.org/code/linkparser
|
11
|
+
|
12
|
+
github
|
13
|
+
: http://github.com/ged/linkparser
|
14
|
+
|
15
|
+
|
4
16
|
|
5
17
|
## Description
|
6
18
|
|
7
|
-
This module is a Ruby binding for
|
8
|
-
[
|
19
|
+
This module is a Ruby binding for
|
20
|
+
[the Abiword version](http://www.abisource.com/projects/link-grammar/) of CMU's
|
21
|
+
[Link Grammar](http://www.link.cs.cmu.edu/link/), a syntactic parser of English.
|
9
22
|
|
10
23
|
|
11
24
|
### Example Usage
|
12
25
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# +----Wd---+--Sp--+--Os-+ | +-Dmc-+--Mp-+ +----A---+ |
|
40
|
-
# | | | | | | | | | | |
|
41
|
-
# LEFT-WALL people.p use.v Ruby for.p all kinds.n of nifty.a things.n .
|
26
|
+
dict = LinkParser::Dictionary.new
|
27
|
+
=> #<LinkParser::Dictionary:0x007fc56b480d18 @options={}>
|
28
|
+
|
29
|
+
sent = dict.parse( "People use Ruby for all kinds of nifty things." )
|
30
|
+
=> #<LinkParser::Sentence:0x1ff15b42eeda
|
31
|
+
"LEFT-WALL people.p use.v Ruby.f for.p all.a kinds.n of nifty.a things.n . RIGHT-WALL"/
|
32
|
+
15 linkages/0 nulls>
|
33
|
+
|
34
|
+
sent.subject
|
35
|
+
=> "people"
|
36
|
+
|
37
|
+
sent.verb
|
38
|
+
=> "use"
|
39
|
+
|
40
|
+
sent.object
|
41
|
+
=> "Ruby"
|
42
|
+
|
43
|
+
puts sent.diagram( max_width: 200 )
|
44
|
+
|
45
|
+
+---------------------------------Xp--------------------------------+
|
46
|
+
| +---------------Jp---------------+ |
|
47
|
+
| | +--------Dmc--------+ |
|
48
|
+
+------>WV------>+-----MVp----+ | +------Jd-----+ |
|
49
|
+
+----Wd---+--Sp--+--Os--+ | +-Dmcn-+-OFd-+ +----A---+ +--RW--+
|
50
|
+
| | | | | | | | | | | |
|
51
|
+
LEFT-WALL people.p use.v Ruby.f for.p all.a kinds.n of nifty.a things.n . RIGHT-WALL
|
42
52
|
|
43
53
|
|
44
54
|
## Installation
|
45
55
|
|
46
|
-
First, download and install the latest version of the link-grammar
|
47
|
-
library from
|
56
|
+
First, download and install the latest version of the link-grammar
|
57
|
+
library from
|
58
|
+
[Abiword's site](http://www.abisource.com/projects/link-grammar/#download).
|
48
59
|
|
49
60
|
Then install the gem:
|
50
61
|
|
51
62
|
gem install linkparser
|
52
63
|
|
53
|
-
You may need to specify the path to the link-grammar library if you
|
64
|
+
You may need to specify the path to the link-grammar library if you
|
54
65
|
installed it somewhere that your linker doesn't look by default:
|
55
66
|
|
56
67
|
gem install linkparser -- --with-link-grammar=/usr/local
|
@@ -58,20 +69,34 @@ installed it somewhere that your linker doesn't look by default:
|
|
58
69
|
|
59
70
|
## Contributing
|
60
71
|
|
61
|
-
You can check out the current development source
|
62
|
-
|
72
|
+
You can check out the current development source
|
73
|
+
[with Mercurial](https://hg.sr.ht/~ged/linkparser),
|
74
|
+
or if you prefer Git, via
|
75
|
+
[its Github mirror](http://github.com/ged/linkparser).
|
63
76
|
|
64
77
|
After checking out the source, run:
|
65
78
|
|
66
|
-
|
79
|
+
$ gen install -Ng
|
80
|
+
$ rake setup
|
81
|
+
|
82
|
+
This will install any missing dependencies and do any neceesary developer setup.
|
83
|
+
|
84
|
+
|
85
|
+
## Author(s)
|
67
86
|
|
68
|
-
|
69
|
-
and generate the API documentation.
|
87
|
+
- Michael Granger <ged@faeriemud.org>
|
70
88
|
|
71
89
|
|
72
90
|
## License
|
73
91
|
|
74
|
-
|
92
|
+
This gem uses the link-grammar library, which is licensed under the
|
93
|
+
LGPL v2.1 license:
|
94
|
+
|
95
|
+
https://www.gnu.org/licenses/lgpl-2.1.html
|
96
|
+
|
97
|
+
The gem itself is licensed under the BSD license:
|
98
|
+
|
99
|
+
Copyright (c) 2006-2020, The FaerieMUD Consortium
|
75
100
|
All rights reserved.
|
76
101
|
|
77
102
|
Redistribution and use in source and binary forms, with or without
|
@@ -99,9 +124,3 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
99
124
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
100
125
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
101
126
|
|
102
|
-
|
103
|
-
[abiword]:http://www.abisource.com/projects/link-grammar/
|
104
|
-
[link-grammar]:http://www.link.cs.cmu.edu/link/ "Link Grammar"
|
105
|
-
[abiword-dl]:http://www.abisource.com/projects/link-grammar/#download
|
106
|
-
[hg-repo]:http://repo.deveiate.org/LinkParser
|
107
|
-
[github-mirror]:http://github.com/ged/linkparser
|
@@ -1,11 +1,11 @@
|
|
1
1
|
/*
|
2
2
|
* dict.c - Ruby LinkParser - Dictionary Class
|
3
|
-
* $Id
|
4
|
-
*
|
3
|
+
* $Id$
|
4
|
+
*
|
5
5
|
* Authors:
|
6
6
|
* * Michael Granger <ged@FaerieMUD.org>
|
7
|
-
*
|
8
|
-
* Please see the LICENSE file at the top of the distribution for licensing
|
7
|
+
*
|
8
|
+
* Please see the LICENSE file at the top of the distribution for licensing
|
9
9
|
* information.
|
10
10
|
*/
|
11
11
|
|
@@ -21,12 +21,13 @@
|
|
21
21
|
* Allocation function
|
22
22
|
*/
|
23
23
|
static struct rlink_dictionary *
|
24
|
-
rlink_dictionary_alloc()
|
24
|
+
rlink_dictionary_alloc()
|
25
|
+
{
|
25
26
|
struct rlink_dictionary *ptr = ALLOC( struct rlink_dictionary );
|
26
27
|
|
27
28
|
ptr->dict = NULL;
|
28
29
|
|
29
|
-
|
30
|
+
rlink_log( "debug", "Initialized an rlink_dictionary <%p>", ptr );
|
30
31
|
return ptr;
|
31
32
|
}
|
32
33
|
|
@@ -35,9 +36,9 @@ rlink_dictionary_alloc() {
|
|
35
36
|
* Free function
|
36
37
|
*/
|
37
38
|
static void
|
38
|
-
rlink_dict_gc_free( struct rlink_dictionary *ptr )
|
39
|
+
rlink_dict_gc_free( struct rlink_dictionary *ptr )
|
40
|
+
{
|
39
41
|
if ( ptr ) {
|
40
|
-
debugMsg(( "Freeing Dictionary <%p>", ptr ));
|
41
42
|
if ( ptr->dict )
|
42
43
|
dictionary_delete( ptr->dict );
|
43
44
|
|
@@ -45,8 +46,6 @@ rlink_dict_gc_free( struct rlink_dictionary *ptr ) {
|
|
45
46
|
|
46
47
|
xfree( ptr );
|
47
48
|
ptr = NULL;
|
48
|
-
} else {
|
49
|
-
debugMsg(( "Not freeing already freed Dictionary." ));
|
50
49
|
}
|
51
50
|
}
|
52
51
|
|
@@ -55,7 +54,8 @@ rlink_dict_gc_free( struct rlink_dictionary *ptr ) {
|
|
55
54
|
* Object validity checker. Returns the data pointer.
|
56
55
|
*/
|
57
56
|
static struct rlink_dictionary *
|
58
|
-
check_dict( VALUE self )
|
57
|
+
check_dict( VALUE self )
|
58
|
+
{
|
59
59
|
Check_Type( self, T_DATA );
|
60
60
|
|
61
61
|
if ( !IsDictionary(self) ) {
|
@@ -71,7 +71,8 @@ check_dict( VALUE self ) {
|
|
71
71
|
* Fetch the data pointer and check it for sanity.
|
72
72
|
*/
|
73
73
|
static struct rlink_dictionary *
|
74
|
-
get_dict( VALUE self )
|
74
|
+
get_dict( VALUE self )
|
75
|
+
{
|
75
76
|
struct rlink_dictionary *ptr = check_dict( self );
|
76
77
|
|
77
78
|
if ( !ptr )
|
@@ -81,11 +82,12 @@ get_dict( VALUE self ) {
|
|
81
82
|
}
|
82
83
|
|
83
84
|
|
84
|
-
/*
|
85
|
+
/*
|
85
86
|
* Get the Dictionary behind the LinkParser::Dictionary +object+ specified.
|
86
87
|
*/
|
87
88
|
struct rlink_dictionary *
|
88
|
-
rlink_get_dict( VALUE obj )
|
89
|
+
rlink_get_dict( VALUE obj )
|
90
|
+
{
|
89
91
|
return get_dict( obj );
|
90
92
|
}
|
91
93
|
|
@@ -103,8 +105,9 @@ rlink_get_dict( VALUE obj ) {
|
|
103
105
|
* Allocate a new LinkParser::Dictionary object.
|
104
106
|
*/
|
105
107
|
static VALUE
|
106
|
-
rlink_dict_s_alloc( VALUE klass )
|
107
|
-
|
108
|
+
rlink_dict_s_alloc( VALUE klass )
|
109
|
+
{
|
110
|
+
rlink_log( "debug", "Wrapping an uninitialized Dictionary pointer." );
|
108
111
|
return Data_Wrap_Struct( klass, 0, rlink_dict_gc_free, 0 );
|
109
112
|
}
|
110
113
|
|
@@ -114,7 +117,9 @@ rlink_dict_s_alloc( VALUE klass ) {
|
|
114
117
|
* can be useful for testing and stuff.
|
115
118
|
*/
|
116
119
|
static Dictionary
|
117
|
-
rlink_make_oldstyle_dict( VALUE dict_file, VALUE pp_file, VALUE cons_file, VALUE affix_file )
|
120
|
+
rlink_make_oldstyle_dict( VALUE dict_file, VALUE pp_file, VALUE cons_file, VALUE affix_file )
|
121
|
+
{
|
122
|
+
#ifdef HAVE_DICTIONARY_CREATE
|
118
123
|
SafeStringValue( dict_file );
|
119
124
|
SafeStringValue( pp_file );
|
120
125
|
SafeStringValue( cons_file );
|
@@ -126,6 +131,11 @@ rlink_make_oldstyle_dict( VALUE dict_file, VALUE pp_file, VALUE cons_file, VALUE
|
|
126
131
|
StringValuePtr(cons_file ),
|
127
132
|
StringValuePtr(affix_file)
|
128
133
|
);
|
134
|
+
#else
|
135
|
+
rb_raise( rb_eNotImpError,
|
136
|
+
"Old-style dictionary creation isn't supported by the installed version of link-grammar." );
|
137
|
+
UNREACHABLE;
|
138
|
+
#endif
|
129
139
|
}
|
130
140
|
|
131
141
|
|
@@ -134,44 +144,45 @@ rlink_make_oldstyle_dict( VALUE dict_file, VALUE pp_file, VALUE cons_file, VALUE
|
|
134
144
|
* LinkParser::Dictionary.new( *args ) -> dict
|
135
145
|
*
|
136
146
|
* Create a new LinkParser::Dictionary.
|
137
|
-
*
|
147
|
+
*
|
138
148
|
* The preferred way to set up the dictionary is to call it with no
|
139
149
|
* arguments, which will look for a dictionary with the same language
|
140
150
|
* as the current environment. Alternatively, a fixed language can be
|
141
151
|
* specified by specifying an ISO639 language code, for example,
|
142
152
|
* <tt>LinkParser::Dictionary.new( :en )</tt>.
|
143
|
-
*
|
153
|
+
*
|
144
154
|
* Explicit dictionary file names can be also specified, like so:
|
145
|
-
*
|
155
|
+
*
|
146
156
|
* Dictionary.new( dict_file,
|
147
157
|
* post_process_file,
|
148
158
|
* constituent_knowledge_file,
|
149
159
|
* affix_file )
|
150
|
-
*
|
151
|
-
* This mode of dictionary construction is not recommended for new
|
152
|
-
* development, and is intended for advanced users only. To create the
|
153
|
-
* dictionary, the Dictionary looks in the current directory and the data
|
160
|
+
*
|
161
|
+
* This mode of dictionary construction is not recommended for new
|
162
|
+
* development, and is intended for advanced users only. To create the
|
163
|
+
* dictionary, the Dictionary looks in the current directory and the data
|
154
164
|
* directory for the files +dict_file+, +post_process_file+,
|
155
165
|
* +constituent_knowledge_file+, and +affix_file+. The last three entries
|
156
166
|
* may be omitted. If +dict_file+ is a fully specified path name, then
|
157
167
|
* the other file names, which need not be fully specified, will be
|
158
168
|
* prefixed by the directory specified by +dict_file+.
|
159
|
-
*
|
169
|
+
*
|
160
170
|
* In any case, a Hash of options can be specified which will be used
|
161
171
|
* as default ParseOption attributes for any sentences created from
|
162
172
|
* it.
|
163
173
|
*
|
164
174
|
* Examples:
|
165
175
|
* dict = LinkParser::Dictionary.new
|
166
|
-
*
|
176
|
+
*
|
167
177
|
* dict = LinkParser::Dictionary.new( :de )
|
168
|
-
*
|
178
|
+
*
|
169
179
|
* dict = LinkParser::Dictionary.new( '/var/data/custom_dicts/4.2.dict' )
|
170
|
-
*
|
171
|
-
*
|
180
|
+
*
|
181
|
+
*
|
172
182
|
*/
|
173
183
|
static VALUE
|
174
|
-
rlink_dict_initialize( int argc, VALUE *argv, VALUE self )
|
184
|
+
rlink_dict_initialize( int argc, VALUE *argv, VALUE self )
|
185
|
+
{
|
175
186
|
if ( !check_dict(self) ) {
|
176
187
|
int i = 0;
|
177
188
|
struct rlink_dictionary *ptr = NULL;
|
@@ -183,24 +194,24 @@ rlink_dict_initialize( int argc, VALUE *argv, VALUE self ) {
|
|
183
194
|
switch( i = rb_scan_args(argc, argv, "05", &arg1, &arg2, &arg3, &arg4, &arg5) ) {
|
184
195
|
/* Dictionary.new */
|
185
196
|
case 0:
|
186
|
-
|
197
|
+
rlink_log_obj( self, "debug", "No arguments" );
|
187
198
|
break;
|
188
199
|
|
189
200
|
/* Dictionary.new( lang )*/
|
190
201
|
/* Dictionary.new( opthash )*/
|
191
202
|
case 1:
|
192
203
|
if( TYPE(arg1) == T_HASH ) {
|
193
|
-
|
204
|
+
rlink_log_obj( self, "debug", "One arg: options hash." );
|
194
205
|
opthash = arg1;
|
195
206
|
} else {
|
196
|
-
|
207
|
+
rlink_log_obj( self, "debug", "One arg: language" );
|
197
208
|
lang = arg1;
|
198
209
|
}
|
199
210
|
break;
|
200
211
|
|
201
212
|
/* Dictionary.new( lang, opthash ) */
|
202
213
|
case 2:
|
203
|
-
|
214
|
+
rlink_log_obj( self, "debug", "Two args: language and options hash." );
|
204
215
|
lang = arg1;
|
205
216
|
opthash = arg2;
|
206
217
|
break;
|
@@ -209,7 +220,7 @@ rlink_dict_initialize( int argc, VALUE *argv, VALUE self ) {
|
|
209
220
|
/* Dictionary.new( dict, pp, cons, affix, opthash ) */
|
210
221
|
case 4:
|
211
222
|
case 5:
|
212
|
-
|
223
|
+
rlink_log_obj( self, "debug", "Four or five args: old-style explicit dict files." );
|
213
224
|
dict = rlink_make_oldstyle_dict( arg1, arg2, arg3, arg4 );
|
214
225
|
opthash = arg5;
|
215
226
|
break;
|
@@ -234,14 +245,17 @@ rlink_dict_initialize( int argc, VALUE *argv, VALUE self ) {
|
|
234
245
|
creating it */
|
235
246
|
if ( !dict ) rlink_raise_lp_error();
|
236
247
|
|
237
|
-
|
248
|
+
rlink_log_obj( self, "debug", "Created dictionary %p", dict );
|
238
249
|
DATA_PTR( self ) = ptr = rlink_dictionary_alloc();
|
239
250
|
|
240
251
|
ptr->dict = dict;
|
241
252
|
|
242
253
|
/* If they passed in an options hash, save it for later. */
|
243
|
-
if ( RTEST(opthash) )
|
244
|
-
|
254
|
+
if ( RTEST(opthash) ) {
|
255
|
+
rb_iv_set( self, "@options", opthash );
|
256
|
+
} else {
|
257
|
+
rb_iv_set( self, "@options", rb_hash_new() );
|
258
|
+
}
|
245
259
|
}
|
246
260
|
|
247
261
|
else {
|
@@ -252,37 +266,18 @@ rlink_dict_initialize( int argc, VALUE *argv, VALUE self ) {
|
|
252
266
|
}
|
253
267
|
|
254
268
|
|
255
|
-
/*
|
256
|
-
* call-seq:
|
257
|
-
* dictionary.max_cost -> fixnum
|
258
|
-
*
|
259
|
-
* Returns the maximum cost (number of brackets []) that is placed on any
|
260
|
-
* connector in the dictionary. This is useful for designing a parsing
|
261
|
-
* algorithm that progresses in stages, first trying the cheap connectors.
|
262
|
-
*/
|
263
|
-
static VALUE
|
264
|
-
rlink_get_max_cost( VALUE self ) {
|
265
|
-
struct rlink_dictionary *ptr = get_dict( self );
|
266
|
-
|
267
|
-
int cost = dictionary_get_max_cost( ptr->dict );
|
268
|
-
|
269
|
-
debugMsg(( "Max cost is: %d", cost ));
|
270
|
-
|
271
|
-
return INT2NUM( cost );
|
272
|
-
}
|
273
|
-
|
274
|
-
|
275
269
|
/*
|
276
270
|
* call-seq:
|
277
271
|
* dictionary.parse( string ) -> sentence
|
278
272
|
* dictionary.parse( string, options ) -> sentence
|
279
273
|
*
|
280
|
-
* Parse the specified sentence +string+ with the dictionary and return a
|
274
|
+
* Parse the specified sentence +string+ with the dictionary and return a
|
281
275
|
* LinkParser::Sentence. If you specify an +options+ hash, its values will override
|
282
276
|
* those of the Dictionary's for the resulting Sentence.
|
283
277
|
*/
|
284
278
|
static VALUE
|
285
|
-
rlink_parse( int argc, VALUE *argv, VALUE self )
|
279
|
+
rlink_parse( int argc, VALUE *argv, VALUE self )
|
280
|
+
{
|
286
281
|
VALUE input_string, options, sentence;
|
287
282
|
VALUE args[2];
|
288
283
|
int i;
|
@@ -296,7 +291,7 @@ rlink_parse( int argc, VALUE *argv, VALUE self ) {
|
|
296
291
|
|
297
292
|
/* Now call #parse on it */
|
298
293
|
if ( i == 1 )
|
299
|
-
rb_funcall( sentence, rb_intern("parse"), 0
|
294
|
+
rb_funcall( sentence, rb_intern("parse"), 0 );
|
300
295
|
else
|
301
296
|
rb_funcall( sentence, rb_intern("parse"), 1, options );
|
302
297
|
|
@@ -307,26 +302,26 @@ rlink_parse( int argc, VALUE *argv, VALUE self ) {
|
|
307
302
|
|
308
303
|
|
309
304
|
|
310
|
-
/*
|
305
|
+
/*
|
311
306
|
* Document-class: LinkParser::Dictionary
|
312
|
-
*
|
307
|
+
*
|
313
308
|
* A Dictionary is the programmer's handle on the set of word definitions that defines the
|
314
309
|
* grammar. A user creates a Dictionary from a grammar file and post-process knowledge
|
315
310
|
* file, and then creates all other objects through it.
|
316
311
|
*/
|
317
312
|
void
|
318
|
-
rlink_init_dict()
|
313
|
+
rlink_init_dict()
|
314
|
+
{
|
319
315
|
#ifdef FOR_RDOC
|
320
316
|
rlink_mLinkParser = rb_define_module( "LinkParser" );
|
321
317
|
#endif
|
322
318
|
|
323
319
|
rlink_cDictionary = rb_define_class_under( rlink_mLinkParser, "Dictionary",
|
324
|
-
|
320
|
+
rb_cObject );
|
325
321
|
|
326
322
|
rb_define_alloc_func( rlink_cDictionary, rlink_dict_s_alloc );
|
327
323
|
rb_define_method( rlink_cDictionary, "initialize", rlink_dict_initialize, -1 );
|
328
324
|
|
329
|
-
rb_define_method( rlink_cDictionary, "max_cost", rlink_get_max_cost, 0 );
|
330
325
|
rb_define_method( rlink_cDictionary, "parse", rlink_parse, -1 );
|
331
326
|
|
332
327
|
/* The LinkParser::ParseOptions object for the Dictionary */
|