Class: OOThesaurus

Inherits:
Object show all
Defined in:
lib/oothesaurus.rb

Overview

The Open Office Thesaurus object. Create a new object with idx file and main database file name and search words with “lookup”. Works with OO Thesaurus files 2.x by kesiev at www.kesiev.com/

Instance Method Summary collapse

Instance Method Details

#dosearch(the, history, word, add, filepathidx, filepathdat) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/oothesaurus.rb', line 9

def dosearch(the,history,word,add,filepathidx,filepathdat)
	a = []
  if add then history.push(word) end
  word=word
  #$itemslist.clear
  rt=the.lookup(word,filepathidx,filepathdat)
  if rt.length>0
    rt.each { |ent|
      ent.each_with_index { |line,i|
       # a=itemslist.append
        a[0]=(i!=0 ? "\t" : "" )+ line
      }
    }
  else
   # a=$itemslist.append
    a[0]="No hits."
  end
end

#lookup(word, idxfile, datfile) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/oothesaurus.rb', line 29

def lookup(word,idxfile,datfile)
	Dir.chdir($progdir)
	if $DEBUG
	$stderr.puts "in lookup\n"
	$stderr.puts  idxfile.to_s
	end 
	seek=-1
	ret=[]
	 if File::exist?(idxfile) && File::exist?(datfile)
		
 		open(idxfile,"r").each { |f|
			f.each { |line|
				line=line.split("|")
				if line[0]==word
					seek=line[1].to_i
					break
				end
			}
		}
		ret=[]
		ret2 = []
		if seek!=-1
			open(datfile,"r") { |a|
				a.seek(seek)
				data=a.gets.split("|")
				data[1].to_i.times {
					ret << a.gets.strip.split("|")
				
				}
			}
			
		end
	 end
	
	ret
end