-
Notifications
You must be signed in to change notification settings - Fork 0
/
print-out-words-from-questions-questions.rb
executable file
·44 lines (39 loc) · 1.25 KB
/
print-out-words-from-questions-questions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
require 'rubygems'
require 'pp'
require 'csv'
require 'uea-stemmer'
f = File.open("stoplist.txt") or die "Unable to open stoplist.txt..."
stoplist = []
f.each_line {|line| stoplist.push line.chomp}
def cleanup(w, stoplist)
w = w.delete(":\\-()[],;.!?'@#$%^&*<>/\"\\")
return "" if w == ""
return "" if w.length < 5
w.downcase!
return "" if stoplist.include?(w)
return w
end
stemmer = UEAStemmer.new
CSV.foreach(ARGV[0], headers: true).with_index(1) do |row, ln|
product_id = row['product_id'].to_i
$stderr.puts("SKIPPING NON DESKTOP") if product_id != 1
next if product_id != 1
last_answer_id = row['last_answer_id']
$stderr.puts("SKIPPING ANSWERED") if last_answer_id != "NULL"
next if last_answer_id != "NULL"
$stderr.puts '%s product_id:%s last_answer_id:%s title:%s content:%s' % [ln, *row.values_at('product_id', 'last_answer_id', 'title', 'content')]
title = row['title']
content = row['content']
title.split(" ").each do |title_word|
t = cleanup(title_word, stoplist)
next if t == ""
$stderr.printf("TITLE_WORD:%s\n",t)
puts stemmer.stem(t)
end
content.split(" ").each do |content_word|
c = cleanup(content_word, stoplist)
next if c == ""
puts stemmer.stem(c)
end
end