tokenator 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tokenator.rb +8 -0
- data/lib/tokenator/core.rb +82 -0
- data/lib/tokenator/version.rb +3 -0
- data/tokenator.gemspec +32 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd99cd80d2413f71ce5c4d9e866e6d1197ea3a73
|
4
|
+
data.tar.gz: fa4bb62874db84e650c070f05db1460c5c07e95b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51fde18c5eedc5368a3667be689efb013d8ca7e30ac67f43b568feb8e85c5aca5b5332f4f2c5d3f9dc75b9135b46253a2f31334dd308c1b1cb687fcbcaf1cfcb
|
7
|
+
data.tar.gz: 7bfab5058aa41523f079b9dcc04a66719193a1cad5c259663413c24e4b8e5f00a2e6db5b6a6c0251276439ce36da5d420553ed44164ea30aa531ca6118a5b039
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Amval
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Tokenator
|
2
|
+
|
3
|
+
This is a simple rule-based tokenizer, based on the one developed by Robert Macyntyre in 1995 for the Penn Treebank, and adapted from a script lifted from [the Treat gem](https://github.com/louismullie/treat).
|
4
|
+
|
5
|
+
It's taylored to my specific use case: I don't need part-of-speech tagging or punctuation preservation.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'tokenator'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install tokenator
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Amval/tokenator.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tokenator"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/tokenator.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Tokenization based on the tokenizer developed by
|
3
|
+
# Robert Macyntyre in 1995 for the Penn Treebank
|
4
|
+
# project. This tokenizer mostly follows the conventions
|
5
|
+
# used by the Penn Treebank.
|
6
|
+
# Modified from the sript written by Utiyama Masao (mutiyama@nict.go.jp).
|
7
|
+
|
8
|
+
class PTB
|
9
|
+
|
10
|
+
# Default options for the tokenizer.
|
11
|
+
DefaultOptions = {
|
12
|
+
remove_punctuation: true
|
13
|
+
}
|
14
|
+
|
15
|
+
def tokenize(string, options = {})
|
16
|
+
options = DefaultOptions.merge(options)
|
17
|
+
|
18
|
+
s = " " + string + " "
|
19
|
+
# Transforms every quote to single quote
|
20
|
+
#s.gsub!(/[`‘’“”"]/, "'")
|
21
|
+
#Preserves acronyms deleting puncts
|
22
|
+
s.gsub!(/((\w\.){2,})/) {$1.gsub!(/\./,'')}
|
23
|
+
|
24
|
+
s.gsub!(/ (([A-Z]\.){2,}) /,' ')
|
25
|
+
s.gsub!(/\w\./)
|
26
|
+
s.gsub!(/\s+/, ' ')
|
27
|
+
s.gsub!(/(\s+)''/, '\1"')
|
28
|
+
s.gsub!(/(\s+)``/, '\1"')
|
29
|
+
s.gsub!(/''(\s+)/, '"\1')
|
30
|
+
s.gsub!(/``(\s+)/, '"\1')
|
31
|
+
s.gsub!(/ (['`]+)([^0-9].+) /, ' \1 \2 ')
|
32
|
+
s.gsub!(/([ (\[{<])"/, '\1 `` ')
|
33
|
+
s.gsub!(/\.\.\./, ' ... ')
|
34
|
+
s.gsub!(/[,;:@\#$%&]/, ' \& ')
|
35
|
+
s.gsub!(/([^.])([.])([\])}>"']*)[ ]*$/, '\1 \2\3 ')
|
36
|
+
s.gsub!(/[?!]/, ' \& ')
|
37
|
+
s.gsub!(/[\]\[(){}<>]/, ' \& ')
|
38
|
+
s.gsub!(/--/, ' -- ')
|
39
|
+
s.sub!(/$/, ' ')
|
40
|
+
s.sub!(/^/, ' ')
|
41
|
+
s.gsub!(/'ll /, ' will ')
|
42
|
+
s.gsub!(/'re /, ' are ')
|
43
|
+
s.gsub!(/'ve /, ' have ')
|
44
|
+
s.gsub!(/n't /, ' not ')
|
45
|
+
s.gsub!(/'LL /, ' WILL ')
|
46
|
+
s.gsub!(/'RE /, ' ARE ')
|
47
|
+
s.gsub!(/'VE /, ' HAVE ')
|
48
|
+
s.gsub!(/N'T /, ' NOT ')
|
49
|
+
s.gsub!(/ ([Cc])annot /, ' \1an not ')
|
50
|
+
s.gsub!(/ ([Ii])'m /, ' \1 am ')
|
51
|
+
s.gsub!(/ ([Hh]|[Ss]h)e's /, ' \1e is ')
|
52
|
+
s.gsub!(/ ([Ii])t's /, ' \1t is ')
|
53
|
+
s.gsub!(/ ([Ww](hat|ho))'s/, ' \1 is')
|
54
|
+
s.gsub!(/ ([Dd])idn't /, ' \1id not ')
|
55
|
+
s.gsub!(/ ([Dd])'ye /, ' \1\' ye ')
|
56
|
+
s.gsub!(/ ([Gg])imme /, ' \1ive me ')
|
57
|
+
s.gsub!(/ ([Gg])onna /, ' \1oing to ')
|
58
|
+
s.gsub!(/ ([Gg])otta /, ' \1ot to ')
|
59
|
+
s.gsub!(/ ([Ll])emme /, ' \1et me ')
|
60
|
+
s.gsub!(/ ([Mm])ore'n /, ' \1ore \'n ')
|
61
|
+
s.gsub!(/ '([Tt])is /, ' \'\1 is ')
|
62
|
+
s.gsub!(/ '([Tt])was /, ' \'\1 was ')
|
63
|
+
s.gsub!(/ ([Ww])anna /, ' \1ant to ')
|
64
|
+
|
65
|
+
while s.sub!(/(\s)([0-9]+) , ([0-9]+)(\s)/, '\1\2,\3\4'); end
|
66
|
+
s.gsub!(/\//, ' / ')
|
67
|
+
s.gsub!(/\s+/, ' ')
|
68
|
+
s.strip!
|
69
|
+
# Remove directional quotes.
|
70
|
+
if options[:remove_punctuation]
|
71
|
+
s.gsub!(/ [-:;?!]/, ' ')
|
72
|
+
s.gsub!(/ , /, ' ')
|
73
|
+
s.gsub!(/ '(\w+)' /, ' \1 ')
|
74
|
+
s.gsub!(/([a-zA-Z]+)\./, '\1 ')
|
75
|
+
s.gsub!(/\.\.\./, '')
|
76
|
+
s.gsub!(/ \./, ' ')
|
77
|
+
s.gsub!(/- /, ' ')
|
78
|
+
end
|
79
|
+
s.split(/\s+/)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
data/tokenator.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tokenator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tokenator"
|
8
|
+
spec.version = Tokenator::VERSION
|
9
|
+
spec.authors = ["Amval"]
|
10
|
+
spec.email = ["alberto.m.valdunciel@gmail.com"]
|
11
|
+
# project
|
12
|
+
spec.summary = "Simple Rule-based tokenizator."
|
13
|
+
spec.homepage = "https://github.com/Amval/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tokenator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amval
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- alberto.m.valdunciel@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/tokenator.rb
|
71
|
+
- lib/tokenator/core.rb
|
72
|
+
- lib/tokenator/version.rb
|
73
|
+
- tokenator.gemspec
|
74
|
+
homepage: https://github.com/Amval/
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Simple Rule-based tokenizator.
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|