Class: Morphy
- Inherits:
-
Object
- Object
- Morphy
- Defined in:
- lib/morphy.rb
Defined Under Namespace
Classes: Word
Class Method Summary collapse
Instance Method Summary collapse
- #find_similar(word) ⇒ Object
-
#initialize ⇒ Morphy
constructor
A new instance of Morphy.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Morphy
Returns a new instance of Morphy.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/morphy.rb', line 65 def initialize path = File.dirname(__FILE__)+"/dictionary/" @dawg = Dawg.load("#{path}/dawg.dat") # why it's eating so much memory? @@suffixes ||= File.open("#{path}/suffixes.txt", 'r').read.split("\n") @@prefixes ||= File.open("#{path}/prefixes.txt", 'r').read.split("\n") @@grammemes ||= File.open("#{path}/grammemes.txt", 'r').read.split("\n").map{|g| g.split(",")} @@paradigms ||= Marshal.load(File.read("#{path}/paradigms.dat")) end |
Class Method Details
.grammemes ⇒ Object
84 85 86 |
# File 'lib/morphy.rb', line 84 def self.grammemes @@grammemes end |
.paradigms ⇒ Object
75 76 77 |
# File 'lib/morphy.rb', line 75 def self.paradigms @@paradigms end |
.prefixes ⇒ Object
78 79 80 |
# File 'lib/morphy.rb', line 78 def self.prefixes @@prefixes end |
.suffixes ⇒ Object
81 82 83 |
# File 'lib/morphy.rb', line 81 def self.suffixes @@suffixes end |
Instance Method Details
#find_similar(word) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/morphy.rb', line 87 def find_similar(word) results = @dawg.find_similar(word) results = results.map do |result| word,para_id,index = result.split(" ") Word.new(word,para_id,index) end results end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/morphy.rb', line 95 def to_s "Morphy" end |