colorful_reading 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97ee1e22dc7fd6c2610ee307babbae358689fd38
4
+ data.tar.gz: 5b90a7b3131fce5498381c181a271d2e0fb4d7bf
5
+ SHA512:
6
+ metadata.gz: 7b5f4daa98b80815bf63ced0ea029dc5a2102ad8438c70dec0b2f447054f85658d1f167012644b845161cf2fb5777d67648b89256fc5ef683876223c7ebaf535
7
+ data.tar.gz: ce9c4e491d896b538ef4117ce00d91e4cc100e028c1a426c0659d2ea1dad0471d790d2e921a355828eb5ce23aba125d7380a0eee3abf2db9d35fa3db70f51523
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /pkg/
4
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in colorful_reading.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Masafumi Yokoyama <myokoym@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # ColorfulReading
2
+
3
+ Colorize sentences by part of speech in English for CLI.
4
+
5
+ ![ColorfulReading](http://myokoym.net/public/colorful_reading.png)
6
+
7
+ ## Installation
8
+
9
+ $ gem install colorful_reading
10
+
11
+ ## Usage
12
+
13
+ $ colorful_reading FILE
14
+
15
+ or
16
+
17
+ $ echo TEXT | colorful_reading
18
+
19
+ ## License
20
+
21
+ MIT License.
22
+
23
+ See [LICENSE.txt](https://github.com/myokoym/colorful_reading/blob/master/LICENSE.txt) for details.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run test"
4
+ task :test do
5
+ ruby("test/run-test.rb")
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "colorful_reading/command"
4
+
5
+ ColorfulReading::Command.run
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'colorful_reading/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "colorful_reading"
8
+ spec.version = ColorfulReading::VERSION
9
+ spec.authors = ["Masafumi Yokoyama"]
10
+ spec.email = ["myokoym@gmail.com"]
11
+
12
+ spec.summary = "Colorize sentences by part of speech in English for CLI."
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/myokoym/colorful_reading"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency("engtagger")
23
+ spec.add_runtime_dependency("colorize")
24
+
25
+ spec.add_development_dependency("test-unit")
26
+ spec.add_development_dependency("bundler")
27
+ spec.add_development_dependency("rake")
28
+ end
@@ -0,0 +1,6 @@
1
+ require "colorful_reading/colors"
2
+ require "colorful_reading/tagger"
3
+ require "colorful_reading/version"
4
+
5
+ module ColorfulReading
6
+ end
@@ -0,0 +1,27 @@
1
+ require "colorize"
2
+
3
+ module ColorfulReading
4
+ class Colors
5
+ COLORS = {
6
+ nn: :green,
7
+ pr: :blue,
8
+ vb: :red,
9
+ jj: :yellow,
10
+ rb: :blue,
11
+ de: :magenta,
12
+ in: :magenta,
13
+ cc: :cyan,
14
+ w: :cyan,
15
+ }
16
+
17
+ def self.colorize(tagged_text)
18
+ COLORS.each do |prefix, color|
19
+ tagged_text.gsub!(/<#{prefix}\w*>(.+?)<\/#{prefix}\w*>/) do
20
+ $1.colorize(color)
21
+ end
22
+ end
23
+ tagged_text.gsub!(/<\w+>([^<]+)<\/\w+>/) { $1 }
24
+ tagged_text
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require "colorful_reading/tagger"
2
+ require "colorful_reading/colors"
3
+
4
+ module ColorfulReading
5
+ class Command
6
+ def self.run
7
+ tagger = Tagger.new
8
+
9
+ ARGF.readlines.each do |text|
10
+ text.chomp!
11
+ tagged_text = tagger.tagging(text)
12
+ if tagged_text
13
+ puts Colors.colorize(tagged_text)
14
+ else
15
+ puts text
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require "engtagger"
2
+
3
+ module ColorfulReading
4
+ class Tagger
5
+ def initialize
6
+ @tagger = EngTagger.new
7
+ end
8
+
9
+ def tagging(text)
10
+ @tagger.add_tags(text)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ColorfulReading
2
+ VERSION = "0.0.1"
3
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ base_dir = File.expand_path("..", File.dirname(__FILE__))
4
+ lib_dir = File.join(base_dir, "lib")
5
+ test_dir = File.join(base_dir, "test")
6
+ $LOAD_PATH.unshift(lib_dir)
7
+
8
+ require "test-unit"
9
+
10
+ exit Test::Unit::AutoRunner.run(true, test_dir)
@@ -0,0 +1,15 @@
1
+ require "colorful_reading/colors"
2
+
3
+ class ColorsTest < Test::Unit::TestCase
4
+ include ColorfulReading
5
+
6
+ class ColorizeTest < self
7
+ def test_nn
8
+ assert_equal("\e[0;32;49mdata\e[0m", Colors.colorize("<nn>data</nn>"))
9
+ end
10
+
11
+ def test_nnp
12
+ assert_equal("\e[0;32;49mVenice\e[0m", Colors.colorize("<nnp>Venice</nnp>"))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require "colorful_reading/tagger"
2
+
3
+ class TaggerTest < Test::Unit::TestCase
4
+ include ColorfulReading
5
+
6
+ def setup
7
+ @tagger = Tagger.new
8
+ end
9
+
10
+ def test_tagging
11
+ assert_equal("<nnp>Ruby</nnp>", @tagger.tagging("Ruby"))
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorful_reading
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masafumi Yokoyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: engtagger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Colorize sentences by part of speech in English for CLI.
84
+ email:
85
+ - myokoym@gmail.com
86
+ executables:
87
+ - colorful_reading
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/colorful_reading
97
+ - colorful_reading.gemspec
98
+ - lib/colorful_reading.rb
99
+ - lib/colorful_reading/colors.rb
100
+ - lib/colorful_reading/command.rb
101
+ - lib/colorful_reading/tagger.rb
102
+ - lib/colorful_reading/version.rb
103
+ - test/run-test.rb
104
+ - test/test-colors.rb
105
+ - test/test-tagger.rb
106
+ homepage: https://github.com/myokoym/colorful_reading
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Colorize sentences by part of speech in English for CLI.
130
+ test_files:
131
+ - test/run-test.rb
132
+ - test/test-colors.rb
133
+ - test/test-tagger.rb
134
+ has_rdoc: