wfreq 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (8) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +22 -0
  3. data/lib/counts.rb +14 -0
  4. data/lib/data.rb +21 -0
  5. data/lib/guide.rb +22 -0
  6. data/lib/split.rb +12 -0
  7. data/lib/wfreq.rb +123 -0
  8. metadata +54 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmQwMjE5MTIxYWE2NjNkMzYxZDRhODljMDM3NTJlNTIzM2UxNWE4OQ==
5
+ data.tar.gz: !binary |-
6
+ ZTJkZDM3M2YzNDg2ODBhMGQxYzZjNTA4ODJlNGM5ZGRjMGZiZWJjMA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWNmOWJmZmM4NDg2NjcwM2I5MmZlMDRiMTMxOWZlOGI4NzY1YWQ1ZDYzM2I5
10
+ NWIxOTFiMDYxZGIwMjgxY2QzYjc5NjYxYjMwZmFiYzczN2IxNzllNTJhZjhk
11
+ NDQxNWE4M2Y3OTE2NDcyNjdiMzU4YmVhYmIxNDA0NGY3MTIyZWI=
12
+ data.tar.gz: !binary |-
13
+ ZmJjNGJhYjg4ZTRhNWIwZDljYTU3NjI1OTY4YjJlZGM0OTFkMDJmZmNlNGQy
14
+ NWZkZTA2NTk4MThiNGVkZDRmNDZlZjRlNDNiYmIwMzdlMWFmOGNmOTg5YTlj
15
+ MzU4NmM3YTFmYzE1YzQ3ZGM5OWI3Nzk3N2Y1MWU4MzQxNmEwMmI=
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ Wfreq is a graphic user interface application to return a list of words frequency from a text file.
2
+
3
+ USAGE:
4
+ ======
5
+ Create a text file containing:
6
+
7
+ ```
8
+ require 'wfreq'
9
+ Editor.run
10
+ ```
11
+
12
+ save the text file as "wfreq.rbw" or "wfreq.rb" on your desktop if you are using Microsoft Windows as an Operating System.
13
+
14
+ if Ruby is in your PATH, clicking on this Ruby file will start the Widget.
15
+
16
+ The Application open a window with a large text frame and a menu.
17
+ Select a file name from the opened system window. Once selected the frequency is displayed in the text window sorted in a descending area.
18
+
19
+ If you want to save the result appearing in the text window, choose save from the file menu and enter the desired filename.
20
+
21
+ To clear the Text Area select Close or New from the File Menu
22
+
data/lib/counts.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Counting frequency of words in a list
2
+ class Counts
3
+
4
+ def self.count(word_list)
5
+ counts =Hash.new(0)
6
+ for word in word_list
7
+ counts[word] +=1
8
+ end
9
+ #counts
10
+ sorted = counts.sort_by{|w, count| count}.reverse
11
+ return sorted
12
+ end
13
+
14
+ end
data/lib/data.rb ADDED
@@ -0,0 +1,21 @@
1
+ require_relative 'split.rb'
2
+ require_relative 'counts.rb'
3
+ ############# VARIABLES ###################
4
+ $filename =TkVariable.new
5
+ $newfilename =TkVariable.new
6
+ $title = 'Word Frequency Counter'
7
+
8
+ ######### METHODS #######
9
+ def get(file)
10
+ text = File.read(file)
11
+ word_list = Splits.words(text)
12
+ list = Counts.count(word_list)
13
+ array = []
14
+ list.each do |k, v|
15
+ array.push("#{k} : #{v}")
16
+ end
17
+ return array
18
+ end
19
+ #######################################
20
+
21
+
data/lib/guide.rb ADDED
@@ -0,0 +1,22 @@
1
+ #here document to use in Help Window accessed through the menu
2
+ class Guide
3
+ #__________________________________________________________
4
+ def self.view
5
+ return $guide
6
+ end
7
+ #__________________________________________________________
8
+ $guide = %q{
9
+ Wfreq is a graphic user interface application to return a list of words frequency from a text file.
10
+
11
+ USAGE:
12
+ ======
13
+ The Application open a window with a large text frame and a menu.
14
+ Select a file name from the opened system window.
15
+ Once selected, the frequency is displayed in the text window sorted in a descending area.
16
+
17
+ If you want to save the result appearing in the text window, choose save from the file menu and enter the target file name with extension to save the result.
18
+
19
+ To clear the Text Area select Close or New from the File Menu
20
+ }
21
+ #________________________________________________________
22
+ end
data/lib/split.rb ADDED
@@ -0,0 +1,12 @@
1
+ # Split a string into words, o use :-
2
+ # require_relative 'String_split'
3
+ # a = "This is part of the string, and this is the rest of it"
4
+ # puts Splits.words(a)
5
+ class Splits
6
+ def self.words(string)
7
+ string.downcase.scan(/[\w']+/)
8
+ end
9
+
10
+
11
+
12
+ end
data/lib/wfreq.rb ADDED
@@ -0,0 +1,123 @@
1
+ require 'tk'
2
+ require_relative 'data'
3
+ require_relative 'guide'
4
+ #____ Install A Run link on the desktop ________________________________
5
+ ## Save a ".rb" file on desktop which contains : require 'wfreq'; Wfreq.run #####
6
+ class Wfreq
7
+
8
+ def self.run
9
+ puts `wfreq.rb`
10
+ end
11
+
12
+ end
13
+ #________________________ Main Window _________________
14
+ #Building the root main frame of the Gui
15
+ root = TkRoot.new{title "#$title"}
16
+ root['geometry'] = '1540x700+1+1'
17
+ #_____________ MENU METHODS ____________________
18
+ newfile = Proc.new{$text.delete(1.0, 'end')}
19
+ #________________________
20
+ openfile = Proc.new{
21
+ $filename = Tk::getOpenFile()
22
+ freq = get("#$filename")
23
+ content = freq.join("\n")
24
+ $text.delete(1.0, 'end')
25
+ $text.insert('end', "#{content}")
26
+ }
27
+ #___________________________________
28
+ closefile = Proc.new{$text.delete(1.0, 'end')}
29
+ #____________________________________
30
+ #____________________________________
31
+ savefileas = Proc.new{
32
+ thetext = $text.get("1.0", 'end')
33
+ $newfilename = Tk::getSaveFile('filetypes' => [["All Files", "."], ["Text Files", ".txt"]])
34
+ File.write($newfilename, "Word Frequency for file: #{$filename} \n =====================================================
35
+ #{thetext}")
36
+ }
37
+ #____________________________________
38
+ exitapp = Proc.new{exit}
39
+ help = Proc.new{
40
+ $win = TkToplevel.new{title "Help Window"}
41
+ $scrollbar = TkScrollbar.new($win){command proc{|*args| $textwin.yview(*args)}
42
+ }.pack('side' => 'right', 'fill' => 'y')
43
+ $textwin =TkText.new($win){
44
+ borderwidth 5
45
+ wrap 'word'
46
+ font TkFont.new('times 16 bold')
47
+ background "yellow"
48
+ pack('side' => 'right')
49
+ }
50
+ $guide = Guide.view
51
+ $textwin.insert(1.0, "#{$guide}")
52
+ $textwin.yscrollcommand(proc{|first, last| $scrollbar.set(first, last)})
53
+ }
54
+ ############## Building Menu ###################
55
+ TkOption.add '*tearOff', 0
56
+ file_menu = TkMenu.new(root)
57
+ helpMenu = TkMenu.new(root)
58
+ #______________________________
59
+ file_menu.add('command',
60
+ 'label' => "New...",
61
+ 'command' => newfile,
62
+ 'underline' => 0)
63
+ file_menu.add('command',
64
+ 'label' => "Open...",
65
+ 'command' => openfile,
66
+ 'underline' => 0)
67
+ file_menu.add('command',
68
+ 'label' => 'Close',
69
+ 'command' => closefile,
70
+ 'underline' => 0)
71
+ file_menu.add('separator')
72
+ file_menu.add('command',
73
+ 'label' => "Save",
74
+ 'command' => savefileas,
75
+ 'underline' => 5)
76
+ file_menu.add('separator')
77
+ file_menu.add('command',
78
+ 'label' => "Exit",
79
+ 'command' => exitapp,
80
+ 'underline' => 3)
81
+ helpMenu.add('command',
82
+ 'label' => "Help",
83
+ 'command' => help,
84
+ 'underline' => 3)
85
+ #_________________________________________
86
+ menu_bar = TkMenu.new
87
+ menu_bar.add('cascade',
88
+ 'menu' => file_menu,
89
+ 'label' => "File")
90
+ menu_bar.add('cascade',
91
+ 'menu' => helpMenu,
92
+ 'label' => "Help")
93
+
94
+ root.menu(menu_bar)
95
+ #________________ TEXT ____________________________
96
+ ## Text Area where the output is displayed ###########
97
+ $text = TkText.new(root) do
98
+ width 100
99
+ height 24
100
+ background "black"
101
+ foreground "white"
102
+ font TkFont.new('tahoma 14 bold')
103
+ wrap 'word'
104
+ insertbackground "yellow"
105
+ insertwidth 30
106
+ cursor "draft_large"
107
+ end
108
+
109
+ $text.focus
110
+ #________________ SCROLLBAR _________________________
111
+ scrollbar = TkScrollbar.new(root){command proc{|*args| $text.yview(*args)}
112
+ }
113
+ $text.yscrollcommand(proc{|first, last| scrollbar.set(first, last)})
114
+ #________________ GEOMETRY ____________________________
115
+ $text.grid('row' => 0, 'column' => 0)
116
+ scrollbar.grid('row' => 0, 'column' => 1, 'sticky' => 'NS')
117
+ TkGrid.columnconfigure( root, 0, :weight => 1 )
118
+ TkGrid.rowconfigure( root, 0, :weight => 1 )
119
+ TkGrid.columnconfigure( $text, 0, :weight => 0 )
120
+ TkGrid.rowconfigure( $text, 0, :weight => 0)
121
+ ###################### Show ##################
122
+ Tk.mainloop
123
+ #################################################
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wfreq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sabry Fattah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Wfreq is a graphic user interface application to return a list of words
14
+ frequency from a text file.
15
+ email: sabryabdelfattah@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
21
+ - README.md
22
+ - lib/counts.rb
23
+ - lib/data.rb
24
+ - lib/guide.rb
25
+ - lib/split.rb
26
+ - lib/wfreq.rb
27
+ homepage: http://sabryfattah.com
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options:
33
+ - --main
34
+ - README.md
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>'
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.4.5
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Wfreq is a graphic user interface application to return a list of words frequency
53
+ from a text file. The GUI is based on Tc/Tk commands
54
+ test_files: []