wiktionary 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/data/noun.csv +141897 -0
- data/data/noun_countable_and_uncountable.csv +8421 -0
- data/data/noun_non_attested.csv +494 -0
- data/data/noun_pluralia_tantum.csv +1242 -0
- data/data/noun_proper.csv +22288 -0
- data/data/noun_uncountable.csv +48078 -0
- data/data/noun_unknown.csv +7301 -0
- data/data/noun_usually_uncountable.csv +3091 -0
- data/lib/wiktionary/noun.rb +83 -0
- data/spec/noun.rb +29 -0
- data/spec/spec_helper.rb +91 -0
- metadata +102 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Wiktionary
|
4
|
+
class Noun
|
5
|
+
FILES = %w[
|
6
|
+
noun
|
7
|
+
noun_uncountable
|
8
|
+
noun_usually_uncountable
|
9
|
+
noun_countable_and_uncountable
|
10
|
+
noun_non_attested
|
11
|
+
noun_unknown
|
12
|
+
noun_pluralia_tantum
|
13
|
+
noun_proper
|
14
|
+
]
|
15
|
+
PLURALS = %w[noun
|
16
|
+
noun_usually_uncountable
|
17
|
+
noun_countable_and_uncountable
|
18
|
+
]
|
19
|
+
UNCOUNTABLE = 'noun_uncountable'
|
20
|
+
PLURALIA_TANTUM = 'noun_pluralia_tantum'
|
21
|
+
|
22
|
+
# Argument path locates directory with CSV files form Wiktionary
|
23
|
+
# @param [String] path
|
24
|
+
def initialize(path=File.join(File.dirname(__FILE__),'..','..','data/'))
|
25
|
+
@plural_to_singulars = Hash.new{|h,e| h[e] = [] }
|
26
|
+
@singular_to_plurals = Hash.new{|h,e| h[e] = [] }
|
27
|
+
load_files(path)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Indicate if noun is in singular form (or uncountable).
|
31
|
+
def singular?(noun)
|
32
|
+
@singular_to_plurals.has_key?(noun)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Indicate if noun is in plural form.
|
36
|
+
def plural?(noun)
|
37
|
+
@plural_to_singulars.has_key?(noun)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns list of possible singular forms of noun.
|
41
|
+
def singularize(noun)
|
42
|
+
@plural_to_singulars[noun]
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def load_files(path)
|
48
|
+
files = Hash.new
|
49
|
+
FILES.each do |file_name|
|
50
|
+
files[file_name]=CSV.open(path+'/'+file_name+'.csv')
|
51
|
+
end
|
52
|
+
|
53
|
+
PLURALS.each do |file_name|
|
54
|
+
files[file_name].each do |singular,*plurals|
|
55
|
+
add(singular,plurals)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
files[UNCOUNTABLE].each do |singular|
|
60
|
+
add_uncountable(singular.first)
|
61
|
+
end
|
62
|
+
|
63
|
+
files[PLURALIA_TANTUM].each do |singular|
|
64
|
+
add(singular.first,singular)
|
65
|
+
end
|
66
|
+
|
67
|
+
files.each do |_,file|
|
68
|
+
file.close
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def add(singular,plurals)
|
73
|
+
plurals.each do |plural|
|
74
|
+
@plural_to_singulars[plural] << singular
|
75
|
+
@singular_to_plurals[singular] << plural
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_uncountable(singular)
|
80
|
+
@singular_to_plurals[singular] ||= []
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/noun.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.unshift "lib"
|
2
|
+
require 'wiktionary/noun'
|
3
|
+
|
4
|
+
RSpec.describe Wiktionary::Noun do
|
5
|
+
before(:all) do
|
6
|
+
@nouns = Wiktionary::Noun.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "tells if noun is singular" do
|
10
|
+
expect(@nouns.singular?("dog")).to eq true
|
11
|
+
expect(@nouns.singular?("dogs")).to eq false
|
12
|
+
expect(@nouns.singular?("politics")).to eq true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "tells if noun is plural" do
|
16
|
+
expect(@nouns.plural?("dogs")).to eq true
|
17
|
+
expect(@nouns.plural?("oxen")).to eq true
|
18
|
+
expect(@nouns.plural?("dog")).to eq false
|
19
|
+
expect(@nouns.plural?("abidingness")).to eq false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns singular form of a noun" do
|
23
|
+
expect(@nouns.singularize("dogs")).to include "dog"
|
24
|
+
expect(@nouns.singularize("boxes")).to include "box"
|
25
|
+
expect(@nouns.singularize("politics")).to include "politics"
|
26
|
+
expect(@nouns.singularize("oxen")).to include "ox"
|
27
|
+
expect(@nouns.singularize("feet")).to include "foot"
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
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
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
54
|
+
# recommended. For more details, see:
|
55
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
56
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
57
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
58
|
+
config.disable_monkey_patching!
|
59
|
+
|
60
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
61
|
+
# be too noisy due to issues in dependencies.
|
62
|
+
config.warnings = true
|
63
|
+
|
64
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
65
|
+
# file, and it's useful to allow more verbose output when running an
|
66
|
+
# individual spec file.
|
67
|
+
if config.files_to_run.one?
|
68
|
+
# Use the documentation formatter for detailed output,
|
69
|
+
# unless a formatter has already been configured
|
70
|
+
# (e.g. via a command-line flag).
|
71
|
+
config.default_formatter = 'doc'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Print the 10 slowest examples and example groups at the
|
75
|
+
# end of the spec run, to help surface which specs are running
|
76
|
+
# particularly slow.
|
77
|
+
config.profile_examples = 10
|
78
|
+
|
79
|
+
# Run specs in random order to surface order dependencies. If you find an
|
80
|
+
# order dependency and want to debug it, you can fix the order by providing
|
81
|
+
# the seed, which is printed after each run.
|
82
|
+
# --seed 1234
|
83
|
+
config.order = :random
|
84
|
+
|
85
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
86
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
87
|
+
# test failures related to randomization by passing the same `--seed` value
|
88
|
+
# as the one that triggered the failure.
|
89
|
+
Kernel.srand config.seed
|
90
|
+
=end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wiktionary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztofsz Wróbel
|
8
|
+
- Aleksander Smywiński-Pohl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.2.0
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 4.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.2.0
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.4.0
|
41
|
+
- - <
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 11.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 10.4.0
|
51
|
+
- - <
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 11.0.0
|
54
|
+
description: English words morphological description and basic conversion rules based
|
55
|
+
on the English Wiktionary.
|
56
|
+
email:
|
57
|
+
- djstrong@gmail.com
|
58
|
+
- apohllo@o2.pl
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .rspec
|
64
|
+
- data/noun.csv
|
65
|
+
- data/noun_countable_and_uncountable.csv
|
66
|
+
- data/noun_non_attested.csv
|
67
|
+
- data/noun_pluralia_tantum.csv
|
68
|
+
- data/noun_proper.csv
|
69
|
+
- data/noun_uncountable.csv
|
70
|
+
- data/noun_unknown.csv
|
71
|
+
- data/noun_usually_uncountable.csv
|
72
|
+
- lib/wiktionary/noun.rb
|
73
|
+
- spec/noun.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
homepage: http://github.com/cycloped-io/wiktionary
|
76
|
+
licenses:
|
77
|
+
- http://opensource.org/licenses/MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --main
|
82
|
+
- Readme.md
|
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.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: wiktionary
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Word morphology and conversion based on Wiktionary
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|