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.

Parameters:

  • connector_type (Symbol) (defaults to: :pure)

    Specifies the connector type or mode desired. Current supported connectors are :pure and :tokyo.

  • wordnet_path (String, Symbol) (defaults to: :search)

    Specifies the directory within which the wordnet dictionary can be found. It can be set to :search to attempt to locate wordnet automatically.

  • data_path (String, Symbol) (defaults to: :default)

    Specifies the directory within which constructed datasets can be found (tokyo index, evocations etc…) It can be set to :default to use the standard location inside the gem directory.

Raises:



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