wordcloud 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wordcloud.rb +54 -0
- metadata +48 -0
data/lib/wordcloud.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
class WordCloud
|
2
|
+
def initialize(input)
|
3
|
+
@input = input
|
4
|
+
@output = ""
|
5
|
+
@wordhash = Hash.new
|
6
|
+
end
|
7
|
+
|
8
|
+
# Splits corpus on words
|
9
|
+
def parse
|
10
|
+
splitinput = @input.split(" ")
|
11
|
+
|
12
|
+
splitinput.each do |w|
|
13
|
+
if w.include? "\\n"
|
14
|
+
w.gsub!("\\n", "<br />")
|
15
|
+
end
|
16
|
+
wordCount(w)
|
17
|
+
end
|
18
|
+
|
19
|
+
genOutput
|
20
|
+
return @output
|
21
|
+
end
|
22
|
+
|
23
|
+
# Counts number of times a word shows up
|
24
|
+
def wordCount(word)
|
25
|
+
commonwords = ["the", "and", "of", "a", "to", "is", "in", "its", "The", "on", "as", "for", "has", "will", "As", "or", "have", "while", "While", "that", "out", "such", "also", "by", "said", "with", "than", "only", "into", "an", "one", "other", "but", "from", "<br />"]
|
26
|
+
|
27
|
+
if (@wordhash[word]) && (!commonwords.include? word)
|
28
|
+
@wordhash[word] += 1
|
29
|
+
else
|
30
|
+
@wordhash[word] = 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generates HTML output based on word size
|
35
|
+
def genOutput
|
36
|
+
splitinput = @input.split(" ")
|
37
|
+
|
38
|
+
splitinput.each do |w|
|
39
|
+
if w.include? "\\n"
|
40
|
+
w.gsub!("\\n", "<br />")
|
41
|
+
end
|
42
|
+
|
43
|
+
if @wordhash[w]
|
44
|
+
size = 13 + @wordhash[w]
|
45
|
+
@output = @output + " <span style=\"font-size:" + size.to_s + "\">" + w + "</span>"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO:
|
52
|
+
# Make gem
|
53
|
+
# Add gem to TT
|
54
|
+
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- M. C. McGrath
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Takes input and outputs the same text with word size changed based on
|
15
|
+
frequency.
|
16
|
+
email: shidash@shidash.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/wordcloud.rb
|
22
|
+
homepage: http://transparencytoolkit.org
|
23
|
+
licenses:
|
24
|
+
- GPL
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.23
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Outputs text with word size determined by their frequency
|
47
|
+
test_files: []
|
48
|
+
has_rdoc:
|