3
#================================================================
5
# CGI script to dump related words
6
#================================================================
15
DBNAME = "relwords.qdb"
19
scriptname = ENV["SCRIPT_NAME"]
20
scriptname = $0 unless scriptname
21
scriptname = scriptname.gsub(/.*\//, "")
29
printf("Content-Type: text/html; charset=UTF-8\r\n\r\n")
34
<?xml version="1.0" encoding="UTF-8"?>
35
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
36
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
38
<meta http-equiv="Content-Language" content="en" />
39
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
40
<meta http-equiv="Content-Style-Type" content="text/css" />
41
<link rel="contents" href="./" />
42
<title>Related Word Extractor</title>
43
<style type="text/css">html { margin: 0em 0em; padding 0em 0em; background: #eeeeee none; }
44
body { margin: 1em 2em; padding 0em 0em;
45
background: #eeeeee none; color: #444444;
46
font-style: normal; font-weight: normal; }
47
h1 { margin-top: 1.8em; margin-bottom: 1.3em; font-weight: bold; font-size: larger; }
48
div.myform { margin: 1em 1em; }
49
p { margin: 1em 1em; }
50
a { color: #0022aa; text-decoration: none; font-weight: bold; }
51
a:hover,a:focus { color: #0033ee; text-decoration: underline; }
52
a.head { color: #111111; text-decoration: none; }
53
strong { color: #000000; }
54
ul { line-height: 150%; }
64
escword = CGI::escapeHTML(word)
66
<form method="get" action="#{scriptname}">
67
<div class="myform">Word:
68
<input type="text" name="word" value="#{escword}" size="32" />
69
<input type="submit" value="Extract" />
82
db = Villa::new(DBNAME)
83
terms = word.split(/[ \t]/)
85
next if term.length < 1
91
fields = line.split(/\t/)
92
num = fields.shift.to_i
94
diam = 32 / ((num + 8) ** 0.6)
95
for i in 0...fields.length
98
val = fields[i+1].to_i * diam
100
allkwd[key] = cur ? cur + val : val
107
if sum > 0 && allkwd.size > 0
108
escword = CGI::escapeHTML(word)
109
printf("<p>Related words of \"<strong id=\"origword\">%s</strong>\"" + \
110
" (<span id=\"orignum\">%d</span>).</p>\n", escword, sum)
112
allkwd.each do |key, val|
113
scores.push([key, val])
115
scores.sort! do |a, b|
120
scores.each do |elem|
123
printf("<li><a href=\"%s?word=%s\" id=\"relword%04d\">%s</a>" + \
124
" (<span id=\"relnum%04d\">%d</span>)</li>\n", scriptname, CGI::escape(key),
125
i / 2 + 1, CGI::escapeHTML(key), i / 2 + 1, val)
131
printf("<p>There is no related word for \"<strong id=\"origword\">%s</strong>\".</p>\n",
133
printf("<p>\"%s\" could not be opened.</p>", DBNAME) unless db
136
printf("<p>Input a source word of relation.</p>\n")