Class: Words::Wordnet
- Inherits:
-
Object
- Object
- Words::Wordnet
- Defined in:
- lib/words.rb
Overview
The wordnet class provides a control come interface for interaction with the wordnet dataset of your choice. It creates a connection, based on specified paramaters, to a wordnet dataset and provides the means to interigate that dataset. In addition it provides control and information about that wordnet connection.
Instance Attribute Summary (collapse)
-
- (PureWordnetConnection, TokyoWordnetConnection) wordnet_connection
readonly
Returns the underlying wordnet connection object.
Instance Method Summary (collapse)
-
- (Object) close!
Causes the current connection to wordnet to be closed.
-
- (true, false) connected?
Returns the current connection status of the wordnet object.
-
- (Symbol) connection_type
Returns the type of the current wordnet connection.
-
- (Pathname?) data_path
Returns the datapath currently in use (this may be irrelevent when using the pure connector and thus could be nil.).
-
- (true, false) evocations?
Returns wheter evocations are currently avalable to use with the current wordnet object.
-
- (Homographs) find(term)
Locates the set of homographs within wordnet specific to the term entered.
-
- (Wordnet) initialize(connector_type = :pure, wordnet_path = :search, data_path = :default)
constructor
Constructs a new wordnet connection object.
-
- (Object) open!
Causes the connection specified within the wordnet object to be reopened if currently closed.
-
- (String) to_s
Provides a textural description of the current connection state of the Wordnet object.
-
- (Pathname?) wordnet_path
Returns the path to the wordnet collection currently in use (this may be irrelevent when using the tokyo connector and thus could be nil.).
Constructor Details
- (Wordnet) initialize(connector_type = :pure, wordnet_path = :search, data_path = :default)
Constructs a new wordnet connection object.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/words.rb', line 40 def initialize(connector_type = :pure, wordnet_path = :search, data_path = :default) # Check and specify useful paths wordnet_path = Wordnet::locate_wordnet(wordnet_path) data_path = (data_path == :default ? Pathname.new(File.join(File.dirname(__FILE__), '..', 'data')) : Pathname.new( data_path )) # Ensure we have a valid connector type raise BadWordnetConnector, "You specified an unsupported wordnet connector type. Supported connectors are: #{SUPPORTED_CONNECTIORS}" unless SUPPORTED_CONNECTIORS.include? connector_type # We can assume that the disired connector is now available desired_connector = SUPPORTED_CONNECTIORS[connector_type] # Assuming we have a valid connection type we can import the relevant code (the reason we do this dynamically is to reduce loadtime) require desired_connector # Construct the connector object @wordnet_connection = Words.const_get( File.basename(desired_connector, '.rb').gsub(/(^|_)(.)/) { $2.upcase } ).new(data_path, wordnet_path) end |
Instance Attribute Details
- (PureWordnetConnection, TokyoWordnetConnection) wordnet_connection (readonly)
Returns the underlying wordnet connection object.
31 32 33 |
# File 'lib/words.rb', line 31 def wordnet_connection @wordnet_connection end |
Instance Method Details
- (Object) close!
Causes the current connection to wordnet to be closed.
102 103 104 105 106 |
# File 'lib/words.rb', line 102 def close! @wordnet_connection.close! end |
- (true, false) connected?
Returns the current connection status of the wordnet object.
119 120 121 122 123 |
# File 'lib/words.rb', line 119 def connected? @wordnet_connection.connected? end |
- (Symbol) connection_type
Returns the type of the current wordnet connection.
76 77 78 79 80 |
# File 'lib/words.rb', line 76 def connection_type @wordnet_connection.connection_type end |
- (Pathname?) data_path
Returns the datapath currently in use (this may be irrelevent when using the pure connector and thus could be nil.)
94 95 96 97 98 |
# File 'lib/words.rb', line 94 def data_path @wordnet_connection.data_path 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)
128 129 130 131 132 |
# File 'lib/words.rb', line 128 def evocations? @wordnet_connection.evocations? end |
- (Homographs) find(term)
Locates the set of homographs within wordnet specific to the term entered.
65 66 67 68 69 70 71 |
# File 'lib/words.rb', line 65 def find(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? homographs = @wordnet_connection.homographs(term) Homographs.new(homographs, @wordnet_connection) unless homographs.nil? end |
- (Object) open!
Causes the connection specified within the wordnet object to be reopened if currently closed.
110 111 112 113 114 |
# File 'lib/words.rb', line 110 def open! @wordnet_connection.open! end |
- (String) to_s
Provides a textural description of the current connection state of the Wordnet object.
137 138 139 140 141 142 |
# File 'lib/words.rb', line 137 def to_s # Return a description of the connector !connected? ? "Words not connected" : @wordnet_connection.to_s end |
- (Pathname?) wordnet_path
Returns the path to the wordnet collection currently in use (this may be irrelevent when using the tokyo connector and thus could be nil.)
85 86 87 88 89 |
# File 'lib/words.rb', line 85 def wordnet_path @wordnet_connection.wordnet_path end |