Method: Words::PureWordnetConnection#synset

Defined in:
lib/wordnet_connectors/pure_wordnet_connection.rb

#synset(synset_id) ⇒ Object

Locates from a synset_id a specific synset and constructs a synset hash.

Parameters:

  • synset_id (String)

    The synset id to locate.

Raises:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/wordnet_connectors/pure_wordnet_connection.rb', line 111

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?

    pos = synset_id[0,1]
    File.open(@wordnet_path + "data.#{SHORT_TO_POS_FILE_TYPE[pos]}","r") do |file|
  file.seek(synset_id[1..-1].to_i)
  data_line, gloss = file.readline.strip.split(" | ")
  lexical_filenum, synset_type, word_count, *data_parts = data_line.split(" ")[1..-1]
  words = Array.new(word_count.to_i(16)).map { "#{data_parts.shift}.#{data_parts.shift}" }
  relations = Array.new(data_parts.shift.to_i).map { "#{data_parts.shift}.#{data_parts.shift}.#{data_parts.shift}.#{data_parts.shift}" }
  return { "synset_id" => synset_id, "lexical_filenum" => lexical_filenum, "synset_type" => synset_type, "words" => words.join('|'), "relations" => relations.join('|'), "gloss" => gloss.strip }
    end

end