wordnet 0.0.5 → 1.0.0.pre.126
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/.gemtest +0 -0
- data/History.rdoc +5 -0
- data/LICENSE +9 -9
- data/Manifest.txt +39 -0
- data/README.rdoc +60 -0
- data/Rakefile +47 -267
- data/TODO +9 -0
- data/WordNet30-license.txt +31 -0
- data/examples/add-laced-boots.rb +35 -0
- data/examples/clothes-with-collars.rb +42 -0
- data/examples/clothesWithTongues.rb +0 -0
- data/examples/domainTree.rb +0 -0
- data/examples/memberTree.rb +0 -0
- data/lib/wordnet/constants.rb +259 -296
- data/lib/wordnet/lexicallink.rb +34 -0
- data/lib/wordnet/lexicon.rb +158 -386
- data/lib/wordnet/mixins.rb +62 -0
- data/lib/wordnet/model.rb +78 -0
- data/lib/wordnet/morph.rb +25 -0
- data/lib/wordnet/semanticlink.rb +52 -0
- data/lib/wordnet/sense.rb +55 -0
- data/lib/wordnet/sumoterm.rb +21 -0
- data/lib/wordnet/synset.rb +404 -859
- data/lib/wordnet/utils.rb +126 -0
- data/lib/wordnet/word.rb +119 -0
- data/lib/wordnet.rb +113 -76
- data/spec/lib/helpers.rb +102 -133
- data/spec/linguawordnet.tests.rb +38 -0
- data/spec/wordnet/lexicon_spec.rb +96 -186
- data/spec/wordnet/model_spec.rb +59 -0
- data/spec/wordnet/semanticlink_spec.rb +42 -0
- data/spec/wordnet/synset_spec.rb +27 -256
- data/spec/wordnet/word_spec.rb +58 -0
- data/spec/wordnet_spec.rb +52 -0
- data.tar.gz.sig +0 -0
- metadata +227 -188
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -720
- data/README +0 -93
- data/Rakefile.local +0 -46
- data/convertdb.rb +0 -417
- data/examples/addLacedBoots.rb +0 -27
- data/examples/clothesWithCollars.rb +0 -36
- data/rake/dependencies.rb +0 -76
- data/rake/helpers.rb +0 -384
- data/rake/manual.rb +0 -755
- data/rake/packaging.rb +0 -112
- data/rake/publishing.rb +0 -303
- data/rake/rdoc.rb +0 -35
- data/rake/style.rb +0 -62
- data/rake/svn.rb +0 -469
- data/rake/testing.rb +0 -192
- data/rake/verifytask.rb +0 -64
- data/utils.rb +0 -838
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'sequel'
|
4
|
+
|
5
|
+
# Use a mock database until the real one is provided by the user
|
6
|
+
Sequel::Model.db = Sequel.mock if Sequel::DATABASES.empty?
|
7
|
+
|
8
|
+
require 'wordnet' unless defined?( WordNet )
|
9
|
+
require 'wordnet/mixins'
|
10
|
+
|
11
|
+
module WordNet
|
12
|
+
|
13
|
+
# The base WordNet database-backed domain class. It's a subclass of Sequel::Model, so
|
14
|
+
# you'll first need to be familiar with Sequel (http://sequel.rubyforge.org/) and
|
15
|
+
# especially its Sequel::Model ORM.
|
16
|
+
#
|
17
|
+
# See the Sequel::Plugins::InlineMigrations module and the documentation for the
|
18
|
+
# 'validation_helpers', 'schema', and 'subclasses' Sequel plugins.
|
19
|
+
#
|
20
|
+
class Model < Sequel::Model
|
21
|
+
include WordNet::Loggable
|
22
|
+
|
23
|
+
plugin :validation_helpers
|
24
|
+
plugin :schema
|
25
|
+
plugin :subclasses
|
26
|
+
|
27
|
+
|
28
|
+
### Execute a block after removing all loggers from the current database handle, then
|
29
|
+
### restore them before returning.
|
30
|
+
def self::without_sql_logging( logged_db=nil )
|
31
|
+
logged_db ||= self.db
|
32
|
+
|
33
|
+
loggers_to_restore = logged_db.loggers.dup
|
34
|
+
logged_db.loggers.clear
|
35
|
+
yield
|
36
|
+
ensure
|
37
|
+
logged_db.loggers.replace( loggers_to_restore )
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
### Reset the database connection that all model objects will use.
|
42
|
+
### @param [Sequel::Database] newdb the new database object.
|
43
|
+
def self::db=( newdb )
|
44
|
+
self.without_sql_logging( newdb ) do
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
self.descendents.each do |subclass|
|
49
|
+
WordNet.log.info "Resetting database connection for: %p to: %p" % [ subclass, newdb ]
|
50
|
+
subclass.db = newdb
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end # class Model
|
55
|
+
|
56
|
+
|
57
|
+
### Overridden version of Sequel.Model() that creates subclasses of WordNet::Model instead
|
58
|
+
### of Sequel::Model.
|
59
|
+
### @see Sequel.Model()
|
60
|
+
def self::Model( source )
|
61
|
+
unless Sequel::Model::ANONYMOUS_MODEL_CLASSES.key?( source )
|
62
|
+
anonclass = nil
|
63
|
+
WordNet::Model.without_sql_logging do
|
64
|
+
if source.is_a?( Sequel::Database )
|
65
|
+
anonclass = Class.new( WordNet::Model )
|
66
|
+
anonclass.db = source
|
67
|
+
else
|
68
|
+
anonclass = Class.new( WordNet::Model ).set_dataset( source )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Sequel::Model::ANONYMOUS_MODEL_CLASSES[ source ] = anonclass
|
73
|
+
end
|
74
|
+
|
75
|
+
return Sequel::Model::ANONYMOUS_MODEL_CLASSES[ source ]
|
76
|
+
end
|
77
|
+
|
78
|
+
end # module WordNet
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'wordnet' unless defined?( WordNet )
|
4
|
+
require 'wordnet/mixins'
|
5
|
+
require 'wordnet/model'
|
6
|
+
|
7
|
+
# WordNet morph model class
|
8
|
+
class WordNet::Morph < WordNet::Model( :morphs )
|
9
|
+
include WordNet::Constants
|
10
|
+
|
11
|
+
set_primary_key :morphid
|
12
|
+
|
13
|
+
many_to_one :word,
|
14
|
+
:join_table => :morphmaps,
|
15
|
+
:left_key => :wordid,
|
16
|
+
:right_key => :morphid
|
17
|
+
|
18
|
+
|
19
|
+
### Return the stringified word; alias for #lemma.
|
20
|
+
def to_s
|
21
|
+
return "%s (%s)" % [ self.morph, self.pos ]
|
22
|
+
end
|
23
|
+
|
24
|
+
end # class WordNet::Morph
|
25
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'wordnet' unless defined?( WordNet )
|
4
|
+
require 'wordnet/constants'
|
5
|
+
require 'wordnet/model'
|
6
|
+
|
7
|
+
# WordNet semantic link (pointer) model class
|
8
|
+
class WordNet::SemanticLink < WordNet::Model( :semlinks )
|
9
|
+
include WordNet::Constants
|
10
|
+
|
11
|
+
|
12
|
+
set_primary_key [:synset1id, :synset2id, :linkid]
|
13
|
+
|
14
|
+
many_to_one :origin,
|
15
|
+
:class => :"WordNet::Synset",
|
16
|
+
:key => :synset1id,
|
17
|
+
:primary_key => :synsetid
|
18
|
+
|
19
|
+
one_to_one :target,
|
20
|
+
:class => :"WordNet::Synset",
|
21
|
+
:key => :synsetid,
|
22
|
+
:primary_key => :synset2id,
|
23
|
+
:eager => :words
|
24
|
+
|
25
|
+
|
26
|
+
######
|
27
|
+
public
|
28
|
+
######
|
29
|
+
|
30
|
+
### Return a stringified version of the SemanticLink.
|
31
|
+
def to_s
|
32
|
+
return "%s: %s (%s)" % [
|
33
|
+
self.type,
|
34
|
+
self.target.words.map( &:to_s ).join( ', ' ),
|
35
|
+
self.target.pos,
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
### Return the type of link as a Symbol.
|
41
|
+
def type
|
42
|
+
return WordNet::Synset.linktype_table[ self.linkid ][ :type ]
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
### Return the name of the link type as a String.
|
47
|
+
def typename
|
48
|
+
return WordNet::Synset.linktype_table[ self.linkid ][ :typename ]
|
49
|
+
end
|
50
|
+
|
51
|
+
end # class WordNet::SemanticLink
|
52
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'wordnet' unless defined?( WordNet )
|
4
|
+
require 'wordnet/model'
|
5
|
+
|
6
|
+
# WordNet sense model class
|
7
|
+
class WordNet::Sense < WordNet::Model( :senses )
|
8
|
+
include WordNet::Constants
|
9
|
+
|
10
|
+
set_primary_key :senseid
|
11
|
+
|
12
|
+
many_to_one :synset, :key => :synsetid
|
13
|
+
many_to_one :word, :key => :wordid
|
14
|
+
|
15
|
+
# Sense -> [ LexicalLinks ] -> [ Synsets ]
|
16
|
+
one_to_many :lexlinks,
|
17
|
+
:class => :"WordNet::LexicalLink",
|
18
|
+
:key => [ :synset1id, :word1id ],
|
19
|
+
:primary_key => [ :synsetid, :wordid ]
|
20
|
+
|
21
|
+
|
22
|
+
### Generate a method that will return Synsets related by the given lexical pointer
|
23
|
+
### +type+.
|
24
|
+
def self::lexical_link( type, typekey=nil )
|
25
|
+
typekey ||= type.to_s.chomp( 's' ).to_sym
|
26
|
+
|
27
|
+
WordNet.log.debug "Generating a %p method for %p links" % [ type, typekey ]
|
28
|
+
|
29
|
+
method_body = Proc.new do
|
30
|
+
linkinfo = WordNet::Synset.linktype_names[ typekey ] or
|
31
|
+
raise ScriptError, "no such link type %p" % [ typekey ]
|
32
|
+
ssids = self.lexlinks_dataset.filter( :linkid => linkinfo[:id] ).select( :synset2id )
|
33
|
+
self.class.filter( :synsetid => ssids )
|
34
|
+
end
|
35
|
+
WordNet.log.debug " method body is: %p" % [ method_body ]
|
36
|
+
|
37
|
+
define_method( type, &method_body )
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
lexical_link :also_see, :also
|
42
|
+
lexical_link :antonym
|
43
|
+
lexical_link :derivation
|
44
|
+
lexical_link :domain_categories, :domain_category
|
45
|
+
lexical_link :domain_member_categories, :domain_member_category
|
46
|
+
lexical_link :domain_member_region
|
47
|
+
lexical_link :domain_member_usage
|
48
|
+
lexical_link :domain_region
|
49
|
+
lexical_link :domain_usage
|
50
|
+
lexical_link :participle
|
51
|
+
lexical_link :pertainym
|
52
|
+
lexical_link :verb_group
|
53
|
+
|
54
|
+
end # class WordNet::Sense
|
55
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'wordnet' unless defined?( WordNet )
|
4
|
+
require 'wordnet/model'
|
5
|
+
require 'wordnet/constants'
|
6
|
+
|
7
|
+
|
8
|
+
# SUMO terms
|
9
|
+
class WordNet::SumoTerm < WordNet::Model( :sumoterms )
|
10
|
+
include WordNet::Constants
|
11
|
+
|
12
|
+
set_primary_key :sumoid
|
13
|
+
|
14
|
+
# SUMO Term -> [ SUMO Map ] -> [ Synset ]
|
15
|
+
many_to_many :synsets,
|
16
|
+
:join_table => :sumomaps,
|
17
|
+
:left_key => :sumoid,
|
18
|
+
:right_key => :synsetid
|
19
|
+
|
20
|
+
end # class WordNet::SumoTerm
|
21
|
+
|