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
-
#connected ⇒ true, false
(also: #connected?)
readonly
Returns the current connection status of the wordnet object.
-
#connection_type ⇒ Symbol
readonly
Returns the type of the current wordnet connection.
-
#data_path ⇒ Pathname?
readonly
Returns the datapath currently in use (this may be irrelevent when using the pure connector and thus could be nil.).
-
#wordnet_path ⇒ Pathname?
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
-
#close! ⇒ Object
Causes the current connection to wordnet to be closed.
-
#evocations(synset_id) ⇒ Object
Locates from a synset id any relevent evocations and constructs an evocations hash.
-
#evocations? ⇒ true, false
Returns wheter evocations are currently avalable to use with the current wordnet object.
-
#homographs(term) ⇒ Object
Locates from a term any relevent homographs and constructs a homographs hash.
-
#initialize(data_path, wordnet_path) ⇒ PureWordnetConnection
constructor
Constructs a new tokyo ruby connector for use with the words wordnet class.
-
#open! ⇒ Object
Causes the connection specified within the wordnet object to be reopened if currently closed.
-
#synset(synset_id) ⇒ Object
Locates from a synset_id a specific synset and constructs a synset hash.
-
#to_s ⇒ String
Provides a textural description of the current connection state of the Wordnet object.
Constructor Details
#initialize(data_path, wordnet_path) ⇒ PureWordnetConnection
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
#connected ⇒ true, false (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 |
#connection_type ⇒ Symbol (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 |
#data_path ⇒ Pathname? (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 |
#wordnet_path ⇒ Pathname? (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
#close! ⇒ Object
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 |
#evocations(synset_id) ⇒ Object
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 |
#evocations? ⇒ true, false
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 |
#homographs(term) ⇒ Object
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 |
#open! ⇒ Object
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 |
#synset(synset_id) ⇒ Object
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 |
#to_s ⇒ String
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 |