Class: Words::TokyoWordnetConnection
- Inherits:
-
Object
- Object
- Words::TokyoWordnetConnection
- Defined in:
- lib/wordnet_connectors/tokyo_wordnet_connection.rb
Overview
Provides a pure tokyo cabinate connector to the Wordnet dataset.
Instance Attribute Summary (collapse)
-
- (true, false) connected
(also: #connected?)
readonly
Returns the current connection status of the wordnet object.
-
- (Symbol) connection_type
readonly
Returns the type of the current wordnet connection.
-
- (Pathname?) data_path
readonly
Returns the datapath currently in use (this may be irrelevent when using the pure connector and thus could be nil.).
-
- (Pathname?) wordnet_path
readonly
Returns the path to the wordnet collection currently in use (this may be irrelevent when using the tokyo connector and thus could be nil.).
Instance Method Summary (collapse)
-
- (Object) close!
Causes the current connection to wordnet to be closed.
-
- (Object) evocations(synset_id)
Locates from a synset id any relevent evocations and constructs an evocations hash.
-
- (true, false) evocations?
Returns wheter evocations are currently avalable to use with the current wordnet object.
-
- (Object) homographs(term)
Locates from a term any relevent homographs and constructs a homographs hash.
-
- (PureWordnetConnection) initialize(data_path, wordnet_path)
constructor
Constructs a new tokyo ruby connector for use with the words wordnet class.
-
- (Object) open!
Causes the connection specified within the wordnet object to be reopened if currently closed.
-
- (Object) synset(synset_id)
Locates from a synset_id a specific synset and constructs a synset hash.
-
- (String) to_s
Provides a textural description of the current connection state of the Wordnet object.
Constructor Details
- (PureWordnetConnection) initialize(data_path, wordnet_path)
Constructs a new tokyo ruby connector for use with the words wordnet class.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 43 def initialize(data_path, wordnet_path) @data_path, @wordnet_path, @connection_type, @connected = data_path + 'wordnet.tct', wordnet_path, :tokyo, false # ensure we have the rufus gem loaded, else there is little point in continuing... raise BadWordnetConnector, "Coulden't find the rufus-tokyo gem. Please ensure it's installed." unless Gem.available?('rufus-tokyo') open! end |
Instance Attribute Details
- (true, false) connected (readonly) Also known as: connected?
Returns the current connection status of the wordnet object.
15 16 17 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 15 def connected @connected end |
- (Symbol) connection_type (readonly)
Returns the type of the current wordnet connection.
25 26 27 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 25 def connection_type @connection_type end |
- (Pathname?) data_path (readonly)
Returns the datapath currently in use (this may be irrelevent when using the pure connector and thus could be nil.)
30 31 32 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 30 def data_path @data_path end |
- (Pathname?) wordnet_path (readonly)
Returns the path to the wordnet collection currently in use (this may be irrelevent when using the tokyo connector and thus could be nil.)
35 36 37 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 35 def wordnet_path @wordnet_path end |
Instance Method Details
- (Object) close!
Causes the current connection to wordnet to be closed.
74 75 76 77 78 79 80 81 82 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 74 def close! if connected? @connection.close @connected = false end return nil end |
- (Object) evocations(synset_id)
Locates from a synset id any relevent evocations and constructs an evocations hash.
123 124 125 126 127 128 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 123 def evocations(synset_id) raise NoWordnetConnection, "There is presently no connection to wordnet. To attempt to reistablish a connection you should use the 'open!' command on the Wordnet object." unless connected? @connection[synset_id + "s"] end |
- (true, false) evocations?
Returns wheter evocations are currently avalable to use with the current wordnet object. (More information on setting these up can be found within the README)
111 112 113 114 115 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 111 def evocations? !evocations('n08112402').nil? end |
- (Object) homographs(term)
Locates from a term any relevent homographs and constructs a homographs hash.
89 90 91 92 93 94 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 89 def homographs(term) raise NoWordnetConnection, "There is presently no connection to wordnet. To attempt to reistablish a connection you should use the 'open!' command on the Wordnet object." unless connected? @connection[term] end |
- (Object) open!
Causes the connection specified within the wordnet object to be reopened if currently closed.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 57 def open! unless connected? if @data_path.exist? @connection = Rufus::Tokyo::Table.new(@data_path.to_s, :mode => 'r') @connected = true else @connected = false raise BadWordnetDataset, "Failed to locate the tokyo words dataset at #{@data_path}. Please insure you have created it using the words gems provided 'build_wordnet' command." end end return nil end |
- (Object) synset(synset_id)
Locates from a synset_id a specific synset and constructs a synset hash.
101 102 103 104 105 106 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 101 def synset(synset_id) raise NoWordnetConnection, "There is presently no connection to wordnet. To attempt to reistablish a connection you should use the 'open!' command on the Wordnet object." unless connected? @connection[synset_id] end |
- (String) to_s
Provides a textural description of the current connection state of the Wordnet object.
133 134 135 136 137 |
# File 'lib/wordnet_connectors/tokyo_wordnet_connection.rb', line 133 def to_s "Words running in tokyo mode with dataset at #{@dataset_path}" end |