rwath 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +2 -0
- data/example/Gemfile +3 -0
- data/example/test-rwath.rb +9 -0
- data/lib/rwath.rb +13 -0
- data/lib/rwath/config.rb +29 -0
- data/lib/rwath/process.rb +16 -0
- data/lib/rwath/version.rb +3 -0
- data/rwath.gemspec +25 -0
- data/spec/rwath_spec.rb +40 -0
- data/spec/spec_helper.rb +19 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c461f5348627eaeaaf1304a830db97fef7e921d
|
4
|
+
data.tar.gz: 4e407f4c5e34ada9a0b07a05469aeccb8450ac33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1c7c93937a22d00ec674e474fb3779d282ccc5b33a124997730f984ff3a8c30f4a028f8cb73e5b1c20bc641cc0a2c37263183dff24f5b5e42f836bc9236c526
|
7
|
+
data.tar.gz: d1e0ba04c7067bc252f4c2ab579f946b334a2d7a93a4aa19e5720ca2305901cb09b1ade6ef08858383846b1d2471f3077787a45c061d5d22bf2c344d9a3f710e
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
vendor/
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 cosmo0920
|
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,55 @@
|
|
1
|
+
# Rwath
|
2
|
+
|
3
|
+
`rwath` is simple wrapper for Swath(Smart Word Analysis for THai).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Before you use `rwath`, please install `swath`.
|
8
|
+
|
9
|
+
### Debian like Linux distributions
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ sudo apt get install swath
|
13
|
+
```
|
14
|
+
|
15
|
+
### OSX with homebrew
|
16
|
+
|
17
|
+
Using my unoffical formula of `swath`:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ brew tap cosmo0920/tokenizers
|
21
|
+
$ brew install cosmo0920/tokenizers/swath
|
22
|
+
```
|
23
|
+
|
24
|
+
### install rwath
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
gem 'rwath'
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install rwath
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
conf = Rwath::Config.new
|
42
|
+
conf.delimitor(char: ' ')
|
43
|
+
conf.encode(input: :utf8, output: :utf8)
|
44
|
+
rwath = Rwath.new(config: conf.setting)
|
45
|
+
text = "ตัวอักษรไทยเป็นเรื่องยาก"
|
46
|
+
puts result = rwath.split(text) # => ตัว อักษร ไทย เป็น เรื่อง ยาก
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/cosmo0920/rwath/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/example/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rwath'
|
3
|
+
|
4
|
+
conf = Rwath::Config.new
|
5
|
+
conf.delimitor(char: ' ')
|
6
|
+
conf.encode(input: :utf8, output: :utf8)
|
7
|
+
rwath = Rwath.new(config: conf.setting)
|
8
|
+
text = "ตัวอักษรไทยเป็นเรื่องยาก"
|
9
|
+
puts result = rwath.split(text) # => ตัว อักษร ไทย เป็น เรื่อง ยาก
|
data/lib/rwath.rb
ADDED
data/lib/rwath/config.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class Rwath
|
2
|
+
class Config < String
|
3
|
+
attr_accessor :setting
|
4
|
+
def initialize
|
5
|
+
@setting = ""
|
6
|
+
end
|
7
|
+
|
8
|
+
def delimitor(char: '|')
|
9
|
+
@setting.concat(" -b \"#{char}\"")
|
10
|
+
end
|
11
|
+
|
12
|
+
def encode(input: 'u', output: 'u')
|
13
|
+
@setting.concat(" -u #{validate_encoding(input)},#{validate_encoding(output)}")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def validate_encoding(str)
|
19
|
+
case str.downcase.to_sym
|
20
|
+
when :u, :utf8, :"utf-8"
|
21
|
+
return 'u'
|
22
|
+
when :t, :thai, :tis620, :"tis-620"
|
23
|
+
return 't'
|
24
|
+
else
|
25
|
+
raise "Encoding Error"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/rwath.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rwath/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rwath"
|
8
|
+
spec.version = Rwath::VERSION
|
9
|
+
spec.authors = ["cosmo0920"]
|
10
|
+
spec.email = ["cosmo0920.wp@gamil.com"]
|
11
|
+
spec.summary = %q{Wrapper gem for Swath(Smart Word Analysis for THai).}
|
12
|
+
spec.description = %q{RWath is ruby wrapper gem for Swath(Smart Word Analysis for THai).}
|
13
|
+
spec.homepage = "https://github.com/cosmo0920/rwath"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = ">= 2.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
data/spec/rwath_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "rwath"
|
3
|
+
|
4
|
+
describe Rwath do
|
5
|
+
let(:rwath) { Rwath.new }
|
6
|
+
subject { rwath }
|
7
|
+
it { should respond_to :split }
|
8
|
+
|
9
|
+
describe "#split" do
|
10
|
+
context "when nothing specify" do
|
11
|
+
subject { rwath.split('ตัวอักษรไทยเป็นเรื่องยาก') }
|
12
|
+
it "output with TIS-620 encoding by default" do
|
13
|
+
should eq 'ัวอัษรเยเเเรืเอยา'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when specify delimitor" do
|
18
|
+
let (:space) { ' ' }
|
19
|
+
let (:config) { Rwath::Config.new }
|
20
|
+
let (:setting) do
|
21
|
+
config.delimitor(char: space)
|
22
|
+
config.encode(input: 'u', output: 'u')
|
23
|
+
end
|
24
|
+
let (:rwath_with_delimitor) { Rwath.new(config: setting) }
|
25
|
+
subject { rwath_with_delimitor.split('ตัวอักษรไทยเป็นเรื่องยาก') }
|
26
|
+
it { should eq 'ตัว อักษร ไทย เป็น เรื่อง ยาก'}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Rwath::Process do
|
32
|
+
let(:command) { 'swath -u u,u' }
|
33
|
+
let(:process) { Rwath::Process.new(command) }
|
34
|
+
subject { process }
|
35
|
+
it { should respond_to :split_exec }
|
36
|
+
describe "#split_exec" do
|
37
|
+
subject { process.split_exec('ตัวอักษรไทยเป็นเรื่องยาก') }
|
38
|
+
it { should eq 'ตัว|อักษร|ไทย|เป็น|เรื่อง|ยาก'}
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require "rwath"
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwath
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cosmo0920
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: RWath is ruby wrapper gem for Swath(Smart Word Analysis for THai).
|
56
|
+
email:
|
57
|
+
- cosmo0920.wp@gamil.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- example/Gemfile
|
69
|
+
- example/test-rwath.rb
|
70
|
+
- lib/rwath.rb
|
71
|
+
- lib/rwath/config.rb
|
72
|
+
- lib/rwath/process.rb
|
73
|
+
- lib/rwath/version.rb
|
74
|
+
- rwath.gemspec
|
75
|
+
- spec/rwath_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/cosmo0920/rwath
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Wrapper gem for Swath(Smart Word Analysis for THai).
|
101
|
+
test_files:
|
102
|
+
- spec/rwath_spec.rb
|
103
|
+
- spec/spec_helper.rb
|