Method: WordNet::Synset#initialize

Defined in:
lib/rwordnet/synset.rb

#initialize(pos, offset) ⇒ Synset

Create a new synset by reading from the data file specified by pos, at offset bytes into the file. This is how the WordNet database is organized. You shouldn’t be creating Synsets directly; instead, use Lemma#synsets.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rwordnet/synset.rb', line 51

def initialize(pos, offset)
  data_line = DB.open(File.join("dict", "data.#{SYNSET_TYPES.fetch(pos)}")) do |f|
    f.seek(offset)
    f.readline.strip
  end

  info_line, @gloss = data_line.split(" | ", 2)
  line = info_line.split(" ")

  @pos = pos
  @pos_offset = offset
  @synset_offset = line.shift
  @lex_filenum = line.shift
  @synset_type = line.shift

  @word_counts = {}
  word_count = line.shift.to_i
  word_count.times do
    @word_counts[line.shift] = line.shift.to_i
  end

  pointer_count = line.shift.to_i
  @pointers = Array.new(pointer_count).map do
    Pointer.new(
      symbol: line.shift[0],
      offset: line.shift.to_i,
      pos: line.shift,
      source: line.shift
    )
  end
end