Method: Words::Wordnet#initialize
- Defined in:
- lib/words.rb
#initialize(connector_type = :pure, wordnet_path = :search, data_path = :default) ⇒ Wordnet
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 |