WordNet::
Synset class
Superclass | WordNet::Model( :synsets ) |
Included Modules |
WordNet
synonym-set object class
Instances of this class encapsulate the data for a synonym set (‘synset’) in a WordNet
lexical database. A synonym set is a set of words that are interchangeable in some context.
We can either fetch the synset from a connected Lexicon:
lexicon = WordNet::Lexicon.new( 'postgres://localhost/wordnet31' ) ss = lexicon[ :first, 'time' ] # => #<WordNet::Synset:0x7ffbf2643bb0 {115265518} 'commencement, first, # get-go, offset, outset, start, starting time, beginning, kickoff, # showtime' (noun): [noun.time] the time at which something is # supposed to begin>
or if you’ve already created a Lexicon, use its connection indirectly to look up a Synset
by its ID:
ss = WordNet::Synset[ 115265518 ] # => #<WordNet::Synset:0x7ffbf257e928 {115265518} 'commencement, first, # get-go, offset, outset, start, starting time, beginning, kickoff, # showtime' (noun): [noun.time] the time at which something is # supposed to begin>
You can fetch a list of the lemmas (base forms) of the words included in the synset:
ss.words.map( &:lemma ) # => ["commencement", "first", "get-go", "offset", "outset", "start", # "starting time", "beginning", "kickoff", "showtime"]
But the primary reason for a synset is its lexical and semantic links to other words and synsets. For instance, its hypernym is the equivalent of its superclass: it’s the class of things of which the receiving synset is a member.
ss.hypernyms # => [#<WordNet::Synset:0x7ffbf25c76c8 {115180528} 'point, point in # time' (noun): [noun.time] an instant of time>]
The synset’s hyponyms, on the other hand, are kind of like its subclasses:
ss.hyponyms # => [#<WordNet::Synset:0x7ffbf25d83b0 {115142167} 'birth' (noun): # [noun.time] the time when something begins (especially life)>, # #<WordNet::Synset:0x7ffbf25d8298 {115268993} 'threshold' (noun): # [noun.time] the starting point for a new state or experience>, # #<WordNet::Synset:0x7ffbf25d8180 {115143012} 'incipiency, # incipience' (noun): [noun.time] beginning to exist or to be # apparent>, # #<WordNet::Synset:0x7ffbf25d8068 {115266164} 'starting point, # terminus a quo' (noun): [noun.time] earliest limiting point>]
Traversal
Synset
also provides a few ‘traversal’ methods which provide recursive searching of a Synset’s semantic links:
# Recursively search for more-general terms for the synset, and print out # each one with indentation according to how distantly it's related. lexicon[ :fencing, 'sword' ]. traverse(:hypernyms).with_depth. each {|ss, depth| puts "%s%s [%d]" % [' ' * (depth-1), ss.words.first, ss.synsetid] } # (outputs:) play [100041468] action [100037396] act [100030358] event [100029378] psychological feature [100023100] abstract entity [100002137] entity [100001740] combat [101170962] battle [100958896] group action [101080366] event [100029378] psychological feature [100023100] abstract entity [100002137] entity [100001740] act [100030358] event [100029378] psychological feature [100023100] abstract entity [100002137] entity [100001740]
See the Traversal Methods section for more details.
Low-Level API
This library is implemented using Sequel::Model, an ORM layer on top of the excellent Sequel database toolkit. This means that in addition to the high-level methods above, you can also make use of a database-oriented API if you need to do something not provided by a high-level method.
In order to make use of this API, you’ll need to be familiar with Sequel, especially Datasets and Model Associations. Most of Ruby-WordNet’s functionality is implemented in terms of one or both of these.
Datasets
The main dataset is available from WordNet::Synset.dataset:
WordNet::Synset.dataset # => #<Sequel::SQLite::Dataset: "SELECT * FROM `synsets`">
In addition to this, Synset
also defines a few other canned datasets. To facilitate searching by part of speech on the Synset
class:
or by the semantic links for a particular Synset:
-
WordNet::Synset#also_see_dataset
-
WordNet::Synset#attributes_dataset
-
WordNet::Synset#causes_dataset
-
WordNet::Synset#domain_categories_dataset
-
WordNet::Synset#domain_member_categories_dataset
-
WordNet::Synset#domain_member_regions_dataset
-
WordNet::Synset#domain_member_usages_dataset
-
WordNet::Synset#domain_regions_dataset
-
WordNet::Synset#domain_usages_dataset
-
WordNet::Synset#entailments_dataset
-
WordNet::Synset#hypernyms_dataset
-
WordNet::Synset#hyponyms_dataset
-
WordNet::Synset#instance_hypernyms_dataset
-
WordNet::Synset#instance_hyponyms_dataset
-
WordNet::Synset#member_holonyms_dataset
-
WordNet::Synset#member_meronyms_dataset
-
WordNet::Synset#part_holonyms_dataset
-
WordNet::Synset#part_meronyms_dataset
-
WordNet::Synset#semlinks_dataset
-
WordNet::Synset#semlinks_to_dataset
-
WordNet::Synset#senses_dataset
-
WordNet::Synset#similar_words_dataset
-
WordNet::Synset#substance_holonyms_dataset
-
WordNet::Synset#substance_meronyms_dataset
-
WordNet::Synset#sumo_terms_dataset
-
WordNet::Synset#verb_groups_dataset
-
WordNet::Synset#words_dataset
Constants
- SEMANTIC_TYPEKEYS
Semantic link type keys; maps what the API calls them to what they are in the DB.
Attributes
- semantic_link_methods R
Public Class Methods
Overridden to reset any lookup tables that may have been loaded from the previous database.
Return the table of lexical domains, keyed by id.
Lexical domains, keyed by name as a String (e.g., “verb.cognition”)
Return the table of link types, keyed by linkid
Return the table of link types, keyed by name.
Return the table of part-of-speech types, keyed by letter identifier.
Return the table of part-of-speech names to letter identifiers (both Symbols).
Unload all of the cached lookup tables that have been loaded.
Generate methods that will return Synsets related by the given semantic pointer type
.
Public Instance Methods
Return a human-readable representation of the objects, suitable for debugging.
Return the name of the lexical domain the synset belongs to; this also corresponds to the lexicographer’s file the synset was originally loaded from.
Return the name of the Synset’s part of speech (pos).
Return any sample sentences.
Return a Sequel::Dataset for synsets related to the receiver via the semantic link of the specified type
.
Return an Enumerator that will iterate over the Synsets related to the receiver via the semantic links of the specified linktype
.
The WordNet::SemanticLinks indicating a relationship with other WordNet::Synsets
The WordNet::SemanticLinks pointing to this Synset
The WordNet::Senses associated with the receiver
Terms from the Suggested Upper Merged Ontology
Stringify the synset.
Return the Synset’s Words as an Array of Strings.
The WordNet::Words associated with the receiver
Dataset Methods
↑ topPublic Instance Methods
:singleton-method: adjective_satellites
Limit results to adjective satellites.
:singleton-method: adjectives Limit results to adjectives.
:singleton-method: adverbs Limit results to adverbs.
:singleton-method: nouns Limit results to nouns.
:singleton-method: verbs Limit results to verbs.
Semantic Links
↑ topPublic Instance Methods
“See Also” synsets
Attribute synsets
Cause synsets
Domain category synsets
Domain member category synsets
Domain member region synsets
Domain member usage synsets
Domain region synsets
Domain usage synsets
Verb entailment synsets
Hypernym sunsets
Hyponym synsets
Instance hypernym synsets
Instance hyponym synsets
Member holonym synsets
Member meronym synsets
Part holonym synsets
Part meronym synsets
Similar word synsets
Substance holonym synsets
Substance meronym synsets
Verb group synsets
Traversal Methods
↑ topPublic Instance Methods
Search for the specified synset
in the semantic links of the given type
of the receiver, returning the depth it was found at if it’s found, or nil if it wasn’t found.
With a block, yield a WordNet::Synset
related to the receiver via a link of the specified type
, recursing depth first into each of its links if the link type is recursive. To exit from the traversal at any depth, throw :stop_traversal.
If no block is given, return an Enumerator that will do the same thing instead.
# Print all the parts of a boot puts lexicon[:boot].traverse( :member_meronyms ).to_a
You can also traverse with an addiitional argument that indicates the depth of recursion by calling with_depth on the Enumerator:
$lex[:fencing].traverse( :hypernyms ).with_depth.each {|ss,d| puts "%02d: %s" % [d,ss] } # (outputs:) 01: play, swordplay (noun): [noun.act] the act using a sword (or other weapon) vigorously and skillfully (hypernym: 1, hyponym: 1) 02: action (noun): [noun.act] something done (usually as opposed to something said) (hypernym: 1, hyponym: 33) 03: act, deed, human action, human activity (noun): [noun.tops] something that people do or cause to happen (hypernym: 1, hyponym: 40) ...
Union: Return the least general synset that the receiver and othersyn
have in common as a hypernym, or nil if it doesn’t share any.