linkparser 1.1.4 → 2.0.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/.simplecov +9 -0
- data/ChangeLog +40 -3
- data/History.md +55 -0
- data/Manifest.txt +6 -4
- data/{README.rdoc → README.md} +56 -53
- data/Rakefile +53 -21
- data/ext/dictionary.c +60 -65
- data/ext/extconf.rb +6 -3
- data/ext/linkage.c +117 -368
- data/ext/linkparser.c +56 -27
- data/ext/linkparser.h +14 -16
- data/ext/parseoptions.c +209 -680
- data/ext/sentence.c +62 -149
- data/lib/linkparser.rb +14 -7
- data/lib/linkparser/dictionary.rb +13 -0
- data/lib/linkparser/linkage.rb +277 -166
- data/lib/linkparser/mixins.rb +2 -2
- data/lib/linkparser/parseoptions.rb +58 -0
- data/lib/linkparser/sentence.rb +21 -34
- data/spec/bugfixes_spec.rb +23 -36
- data/spec/helpers.rb +35 -0
- data/spec/linkparser/dictionary_spec.rb +29 -48
- data/spec/linkparser/linkage_spec.rb +199 -268
- data/spec/linkparser/mixins_spec.rb +9 -24
- data/spec/linkparser/parseoptions_spec.rb +45 -59
- data/spec/linkparser/sentence_spec.rb +36 -56
- data/spec/linkparser_spec.rb +6 -25
- metadata +97 -85
- metadata.gz.sig +0 -0
- data/History.rdoc +0 -41
- data/examples/basic-api.rb +0 -65
- data/examples/readme-example.rb +0 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: efc4f3a1276fa02671075995ab71b7941fd85dcc
|
4
|
+
data.tar.gz: 51c133d19189f4f2a20ec69528a0553e5d7cd540
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2530f1ee151c4edb144c6973ea440fdd7a3efb8ed9968ccbdaec47d168051ac4667e71ef2c785bc183fb994d370c0ba85088fbcb3974e03ce7988b7a6c48493d
|
7
|
+
data.tar.gz: 24ea588e3cae4243a933c548e2bfae672715f244caa376b8db38956a291581d7ca778416e68f45b6c987f545e52af8291ebeb6603038924dad03485c87d5c3c0
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.simplecov
ADDED
data/ChangeLog
CHANGED
@@ -1,8 +1,45 @@
|
|
1
|
+
2013-02-25 Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
* .rvmrc:
|
4
|
+
Test under Ruby 2 by default.
|
5
|
+
[9f95dae5c1a0] [github/master, tip]
|
6
|
+
|
7
|
+
* Rakefile:
|
8
|
+
Use RbConfig instead of deprecated Config module
|
9
|
+
[7a3166b6bfb7]
|
10
|
+
|
11
|
+
2013-01-11 Michael Granger <ged@FaerieMUD.org>
|
12
|
+
|
13
|
+
* Merge pull request #5 from egtann/improved-readme
|
14
|
+
|
15
|
+
Fixed formatting in the examples section of the README
|
16
|
+
[5b7f098d2d8a]
|
17
|
+
|
18
|
+
2012-07-21 Evan Tann <egtann@gmail.com>
|
19
|
+
|
20
|
+
* README.rdoc:
|
21
|
+
Fixing a spacing issue under Example Usage
|
22
|
+
[217df54f42d7]
|
23
|
+
|
24
|
+
* README.rdoc:
|
25
|
+
Improved formatting for Github markdown
|
26
|
+
[a42ca1b29189]
|
27
|
+
|
28
|
+
2012-10-10 Michael Granger <ged@FaerieMUD.org>
|
29
|
+
|
30
|
+
* .hgtags:
|
31
|
+
Added tag v1.1.4 for changeset ddf1b289fe82
|
32
|
+
[0aba6078aca1]
|
33
|
+
|
34
|
+
* .hgsigs:
|
35
|
+
Added signature for changeset 370fd7d741fb
|
36
|
+
[ddf1b289fe82] [v1.1.4]
|
37
|
+
|
1
38
|
2012-08-07 Michael Granger <ged@FaerieMUD.org>
|
2
39
|
|
3
40
|
* .rvm.gems:
|
4
41
|
Update dev gems
|
5
|
-
[370fd7d741fb]
|
42
|
+
[370fd7d741fb]
|
6
43
|
|
7
44
|
* .rvmrc:
|
8
45
|
Omit the patch version from the rvmrc
|
@@ -565,8 +602,8 @@
|
|
565
602
|
lib/linkparser/linkage.rb, misc/monkeypatches.rb, misc/readme-
|
566
603
|
example.rb, spec/linkage_spec.rb:
|
567
604
|
* Fixed the Mkrf-generated Rakefile so it'll actually install the
|
568
|
-
extension; this requires a monkeypatch currently, but I'll
|
569
|
-
|
605
|
+
extension; this requires a monkeypatch currently, but I'll upstream
|
606
|
+
the fix to the Mkrf guys.
|
570
607
|
* Fixed some warnings in linkage.c
|
571
608
|
* Fixed the INSTALL instructions
|
572
609
|
* Fixed up the example in the README and extracted the code to ease
|
data/History.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
## v2.0.0 [2015-03-02] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
Updated for the latest Ruby and link-grammar.
|
4
|
+
|
5
|
+
NOTE: This release breaks the API of previous releases. In the 5.x
|
6
|
+
release of the upstream library (link-grammar) a bunch of
|
7
|
+
long-deprecated functions were removed, so it was no longer possible
|
8
|
+
to maintain backward-compatibility.
|
9
|
+
|
10
|
+
The 1.x version of LinkParser should continue to work fine for
|
11
|
+
pre-5.x versions of link-grammar, and it will continue to be
|
12
|
+
maintained for the forseeable future.
|
13
|
+
|
14
|
+
|
15
|
+
## v1.1.4 [2012-01-31] Michael Granger <ged@FaerieMUD.org>
|
16
|
+
|
17
|
+
- Packaging fixes, dependency update
|
18
|
+
|
19
|
+
|
20
|
+
## v1.1.3 [2011-05-16] Michael Granger <ged@FaerieMUD.org>
|
21
|
+
|
22
|
+
- Use a relative path for path constants (Alessandro Berardi), update
|
23
|
+
deps
|
24
|
+
|
25
|
+
|
26
|
+
## v1.1.2 [2011-05-12] Michael Granger <ged@FaerieMUD.org>
|
27
|
+
|
28
|
+
- Fixes package configuration options concatenation bug (see
|
29
|
+
http://goo.gl/G49Y8) (Alessandro Berardi <berardialessandro@gmail.com>)
|
30
|
+
- De-Yard, build cleanup, added gem-testers support
|
31
|
+
- Removed unnecessary (and non-existant on Ruby < 1.9) include.
|
32
|
+
- Fixing some shadowed variables for 1.9.2.
|
33
|
+
- Avoid circular requires.
|
34
|
+
|
35
|
+
|
36
|
+
## v1.1.1 [2010-12-30] Michael Granger <ged@FaerieMUD.org>
|
37
|
+
|
38
|
+
* Updated for link-grammar 4.7.1.
|
39
|
+
* Fixed some specs that were doing nothing, using old RSpec syntax, etc.
|
40
|
+
* Converted to Hoe.
|
41
|
+
|
42
|
+
|
43
|
+
## v1.1.0 [2010-11-30] Michael Granger <ged@FaerieMUD.org>
|
44
|
+
|
45
|
+
* Updated to support link-grammar 4.7.0. Note that this breaks compatibility with
|
46
|
+
earlier versions, as the model for sentences with conjunctions has changed
|
47
|
+
significantly.
|
48
|
+
* Use pkgconfig if available.
|
49
|
+
* Various memory-management and 1.9.2 fixes.
|
50
|
+
|
51
|
+
|
52
|
+
## v1.0.6 [2009-10-16] Michael Granger <ged@FaerieMUD.org>
|
53
|
+
|
54
|
+
[TODO]
|
55
|
+
|
data/Manifest.txt
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
.gemtest
|
2
|
+
.simplecov
|
2
3
|
ChangeLog
|
3
|
-
History.
|
4
|
+
History.md
|
4
5
|
LICENSE
|
5
6
|
Manifest.txt
|
6
|
-
README.
|
7
|
+
README.md
|
7
8
|
Rakefile
|
8
|
-
examples/basic-api.rb
|
9
|
-
examples/readme-example.rb
|
10
9
|
ext/dictionary.c
|
11
10
|
ext/extconf.rb
|
12
11
|
ext/linkage.c
|
@@ -15,10 +14,13 @@ ext/linkparser.h
|
|
15
14
|
ext/parseoptions.c
|
16
15
|
ext/sentence.c
|
17
16
|
lib/linkparser.rb
|
17
|
+
lib/linkparser/dictionary.rb
|
18
18
|
lib/linkparser/linkage.rb
|
19
19
|
lib/linkparser/mixins.rb
|
20
|
+
lib/linkparser/parseoptions.rb
|
20
21
|
lib/linkparser/sentence.rb
|
21
22
|
spec/bugfixes_spec.rb
|
23
|
+
spec/helpers.rb
|
22
24
|
spec/linkparser/dictionary_spec.rb
|
23
25
|
spec/linkparser/linkage_spec.rb
|
24
26
|
spec/linkparser/mixins_spec.rb
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,69 +1,66 @@
|
|
1
|
-
|
1
|
+
# linkparser
|
2
2
|
|
3
3
|
* http://deveiate.org/projects/Ruby-LinkParser
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
This module is a Ruby binding for
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
First, download and install the latest version of the link-grammar
|
48
|
-
library from
|
49
|
-
{Abiword's site}[http://www.abisource.com/projects/link-grammar/#download].
|
5
|
+
## Description
|
6
|
+
|
7
|
+
This module is a Ruby binding for
|
8
|
+
[the Abiword version](http://www.abisource.com/projects/link-grammar/) of CMU's
|
9
|
+
[Link Grammar](http://www.link.cs.cmu.edu/link/), a syntactic parser of English.
|
10
|
+
|
11
|
+
|
12
|
+
### Example Usage
|
13
|
+
|
14
|
+
dict = LinkParser::Dictionary.new
|
15
|
+
=> #<LinkParser::Dictionary:0x007f9a5b117220>
|
16
|
+
|
17
|
+
sent = dict.parse( "People use Ruby for all kinds of nifty things." )
|
18
|
+
=> #<LinkParser::Sentence:0x1fe69761a146 "LEFT-WALL people.p use.v Ruby.f
|
19
|
+
for.p all.a kinds.n of nifty.a things.n . RIGHT-WALL"/15
|
20
|
+
linkages/0 nulls>
|
21
|
+
|
22
|
+
sent.subject
|
23
|
+
=> "people"
|
24
|
+
|
25
|
+
sent.verb
|
26
|
+
=> "use"
|
27
|
+
|
28
|
+
sent.object
|
29
|
+
=> "Ruby.f"
|
30
|
+
|
31
|
+
puts sent.diagram( max_width: 200 )
|
32
|
+
>
|
33
|
+
> +---------------------------------Xp--------------------------------+
|
34
|
+
> | +---------------Jp---------------+ |
|
35
|
+
> | | +--------Dmc--------+ |
|
36
|
+
> +------>WV------>+-----MVp----+ | +------Jd-----+ |
|
37
|
+
> +----Wd---+--Sp--+--Os--+ | +-Dmcn-+-OFd-+ +----A---+ +--RW--+
|
38
|
+
> | | | | | | | | | | | |
|
39
|
+
> LEFT-WALL people.p use.v Ruby.f for.p all.a kinds.n of nifty.a things.n . RIGHT-WALL
|
40
|
+
|
41
|
+
|
42
|
+
## Installation
|
43
|
+
|
44
|
+
First, download and install the latest version of the link-grammar
|
45
|
+
library from
|
46
|
+
[Abiword's site](http://www.abisource.com/projects/link-grammar/#download).
|
50
47
|
|
51
48
|
Then install the gem:
|
52
49
|
|
53
50
|
gem install linkparser
|
54
51
|
|
55
|
-
You may need to specify the path to the link-grammar library if you
|
52
|
+
You may need to specify the path to the link-grammar library if you
|
56
53
|
installed it somewhere that your linker doesn't look by default:
|
57
54
|
|
58
55
|
gem install linkparser -- --with-link-grammar=/usr/local
|
59
56
|
|
60
57
|
|
61
|
-
|
58
|
+
## Contributing
|
62
59
|
|
63
60
|
You can check out the current development source
|
64
|
-
|
61
|
+
[with Mercurial](http://repo.deveiate.org/LinkParser),
|
65
62
|
or if you prefer Git, via
|
66
|
-
|
63
|
+
[its Github mirror](http://github.com/ged/linkparser).
|
67
64
|
|
68
65
|
After checking out the source, run:
|
69
66
|
|
@@ -73,9 +70,16 @@ This task will install any missing dependencies, run the tests/specs,
|
|
73
70
|
and generate the API documentation.
|
74
71
|
|
75
72
|
|
76
|
-
|
73
|
+
## License
|
77
74
|
|
78
|
-
|
75
|
+
This gem uses the link-grammar library, which is licensed under the
|
76
|
+
LGPL v2.1 license:
|
77
|
+
|
78
|
+
https://www.gnu.org/licenses/lgpl-2.1.html
|
79
|
+
|
80
|
+
The gem itself is licensed under the BSD license:
|
81
|
+
|
82
|
+
Copyright (c) 2006-2015, The FaerieMUD Consortium
|
79
83
|
All rights reserved.
|
80
84
|
|
81
85
|
Redistribution and use in source and binary forms, with or without
|
@@ -103,4 +107,3 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
103
107
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
104
108
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
105
109
|
|
106
|
-
|
data/Rakefile
CHANGED
@@ -21,35 +21,40 @@ SPECDIR = BASEDIR + 'spec'
|
|
21
21
|
EXTDIR = BASEDIR + 'ext'
|
22
22
|
LIBDIR = BASEDIR + 'lib'
|
23
23
|
|
24
|
-
DLEXT =
|
24
|
+
DLEXT = RbConfig::CONFIG['DLEXT']
|
25
25
|
|
26
26
|
EXTCONF = EXTDIR + 'extconf.rb'
|
27
27
|
EXT = LIBDIR + "linkparser_ext.#{DLEXT}"
|
28
28
|
|
29
|
+
GEMSPEC = 'linkparser.gemspec'
|
30
|
+
|
29
31
|
# Hoe plugins
|
30
32
|
Hoe.plugin :mercurial
|
33
|
+
Hoe.plugin :publish
|
31
34
|
Hoe.plugin :signing
|
32
35
|
|
33
36
|
Hoe.plugins.delete :rubyforge
|
34
37
|
|
35
38
|
# Main gem configuration
|
36
39
|
hoespec = Hoe.spec 'linkparser' do
|
37
|
-
self.
|
38
|
-
self.
|
39
|
-
self.
|
40
|
+
self.license 'BSD'
|
41
|
+
self.readme_file = 'README.md'
|
42
|
+
self.history_file = 'History.md'
|
43
|
+
self.extra_rdoc_files = FileList[ '*.md', 'ext/*.[ch]' ]
|
40
44
|
|
41
45
|
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
42
46
|
self.developer 'Martin Chase', 'stillflame@FaerieMUD.org'
|
43
47
|
|
48
|
+
self.dependency 'loggability', '~> 0.11'
|
44
49
|
self.dependency 'rake-compiler', '~> 0', :development
|
45
|
-
self.dependency 'hoe-deveiate', '~> 0', :development
|
50
|
+
self.dependency 'hoe-deveiate', '~> 0.5', :development
|
51
|
+
self.dependency 'rdoc-generator-fivefish', '~> 0', :development
|
46
52
|
|
47
|
-
self.spec_extras[:licenses] = ["BSD"]
|
48
53
|
self.spec_extras[:extensions] = [ EXTCONF.to_s ]
|
49
54
|
|
50
|
-
self.require_ruby_version( '>=
|
51
|
-
|
55
|
+
self.require_ruby_version( '>=2.0.0' )
|
52
56
|
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
57
|
+
self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
|
53
58
|
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
54
59
|
end
|
55
60
|
|
@@ -59,24 +64,12 @@ ENV['VERSION'] ||= hoespec.spec.version.to_s
|
|
59
64
|
# Need to (re)compile before running specs
|
60
65
|
task :spec => :compile
|
61
66
|
|
62
|
-
# gem-testers support
|
63
|
-
task :test do
|
64
|
-
# rake-compiler always wants to copy the compiled extension into lib/, but
|
65
|
-
# we don't want testers to have to re-compile, especially since that
|
66
|
-
# often fails because they can't (and shouldn't have to) write to tmp/ in
|
67
|
-
# the installed gem dir. So we clear the task rake-compiler set up
|
68
|
-
# to break the dependency between :spec and :compile when running under
|
69
|
-
# rubygems-test, and then run :spec.
|
70
|
-
Rake::Task[ EXT.to_s ].clear
|
71
|
-
Rake::Task[ :spec ].execute
|
72
|
-
end
|
73
|
-
|
74
67
|
desc "Turn on warnings and debugging in the build."
|
75
68
|
task :maint do
|
76
69
|
ENV['MAINTAINER_MODE'] = 'yes'
|
77
70
|
end
|
78
71
|
|
79
|
-
ENV['RUBY_CC_VERSION'] = '
|
72
|
+
ENV['RUBY_CC_VERSION'] = '2.0.0:2.1:2.2'
|
80
73
|
|
81
74
|
# Rake-compiler task
|
82
75
|
Rake::ExtensionTask.new do |ext|
|
@@ -89,3 +82,42 @@ Rake::ExtensionTask.new do |ext|
|
|
89
82
|
ext.cross_platform = %w[i386-mswin32 i386-mingw32]
|
90
83
|
end
|
91
84
|
|
85
|
+
|
86
|
+
# Ensure the specs pass before checking in
|
87
|
+
task 'hg:precheckin' => [:check_history, :check_manifest, :gemspec, :spec]
|
88
|
+
|
89
|
+
desc "Build a coverage report"
|
90
|
+
task :coverage do
|
91
|
+
ENV["COVERAGE"] = 'yes'
|
92
|
+
Rake::Task[:spec].invoke
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
# Use the fivefish formatter for docs generated from development checkout
|
97
|
+
if File.directory?( '.hg' )
|
98
|
+
require 'rdoc/task'
|
99
|
+
|
100
|
+
Rake::Task[ 'docs' ].clear
|
101
|
+
RDoc::Task.new( 'docs' ) do |rdoc|
|
102
|
+
rdoc.main = "README.rdoc"
|
103
|
+
rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb", "ext/**/*.c" )
|
104
|
+
rdoc.generator = :fivefish
|
105
|
+
rdoc.title = "Ruby LinkParser"
|
106
|
+
rdoc.rdoc_dir = 'doc'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
task :gemspec => GEMSPEC
|
111
|
+
file GEMSPEC => __FILE__
|
112
|
+
task GEMSPEC do |task|
|
113
|
+
spec = $hoespec.spec
|
114
|
+
spec.files.delete( '.gemtest' )
|
115
|
+
spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
116
|
+
spec.signing_key = nil
|
117
|
+
File.open( task.name, 'w' ) do |fh|
|
118
|
+
fh.write( spec.to_ruby )
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
CLOBBER.include( GEMSPEC.to_s )
|
123
|
+
task :default => :gemspec
|
data/ext/dictionary.c
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
/*
|
2
2
|
* dict.c - Ruby LinkParser - Dictionary Class
|
3
|
-
* $Id: dictionary.c,v
|
4
|
-
*
|
3
|
+
* $Id: dictionary.c,v 85300de8d84c 2015/03/02 16:59:48 ged $
|
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;
|
@@ -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 */
|