moby 1.0.1beta

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.swp
2
+ *.swo
3
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.2" > .rvmrc
9
+ environment_id="ruby-1.9.2-p290@moby"
10
+
11
+ #
12
+ # Uncomment the following lines if you want to verify rvm version per project
13
+ #
14
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
15
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
16
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
17
+ # return 1
18
+ # }
19
+ #
20
+
21
+ #
22
+ # Uncomment following line if you want options to be set only for given project.
23
+ #
24
+ # PROJECT_JRUBY_OPTS=( --1.9 )
25
+ #
26
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
27
+ #
28
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
29
+ #
30
+
31
+ #
32
+ # First we attempt to load the desired environment directly from the environment
33
+ # file. This is very fast and efficient compared to running through the entire
34
+ # CLI and selector. If you want feedback on which environment was used then
35
+ # insert the word 'use' after --create as this triggers verbose mode.
36
+ #
37
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
38
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
39
+ then
40
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
41
+
42
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
43
+ then
44
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
45
+ fi
46
+ else
47
+ # If the environment file has not yet been created, use the RVM CLI to select.
48
+ if ! rvm --create "$environment_id"
49
+ then
50
+ echo "Failed to create RVM environment '${environment_id}'."
51
+ return 1
52
+ fi
53
+ fi
54
+
55
+ #
56
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
57
+ # it be automatically loaded. Uncomment the following and adjust the filename if
58
+ # necessary.
59
+ #
60
+ # filename=".gems"
61
+ # if [[ -s "$filename" ]]
62
+ # then
63
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
64
+ # fi
65
+
66
+ # If you use bundler, this might be useful to you:
67
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
68
+ # then
69
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
70
+ # gem install bundler
71
+ # fi
72
+ # if [[ -s Gemfile ]] && command -v bundle
73
+ # then
74
+ # bundle install
75
+ # fi
76
+
77
+ if [[ $- == *i* ]] # check for interactive shells
78
+ then
79
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
80
+ else
81
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
82
+ fi
83
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem "rspec", :group => :test
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ rspec (2.8.0)
6
+ rspec-core (~> 2.8.0)
7
+ rspec-expectations (~> 2.8.0)
8
+ rspec-mocks (~> 2.8.0)
9
+ rspec-core (2.8.0)
10
+ rspec-expectations (2.8.0)
11
+ diff-lcs (~> 1.1.2)
12
+ rspec-mocks (2.8.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ rspec
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ Moby
2
+ ====
3
+
4
+ **WIP**
5
+
6
+ Ruby interface for [Moby Project](http://en.wikipedia.org/wiki/Moby_Project)
7
+ [wordlists](http://www.gutenberg.org/catalog/world/results?title=moby+list)
8
+
9
+ ### Usage
10
+
11
+ ```ruby
12
+ pos = Moby::PartsOfSpeech.new
13
+ ```
14
+
15
+ ### List
16
+
17
+ Get word lists by part of speech
18
+
19
+ ```ruby
20
+ pos.nouns
21
+ pos.plurals
22
+ pos.noun_phrases
23
+ pos.adjectives
24
+ pos.adverbs
25
+ pos.conjunctions
26
+ pos.prepositions
27
+ pos.interjections
28
+ pos.pronouns
29
+ pos.definite_articles
30
+ pos.indefinite_articles
31
+ pos.nominatives
32
+ ```
33
+
34
+ `#verbs` takes an optional `:type` parameter since there's three types
35
+
36
+ ```ruby
37
+ pos.verbs
38
+ pos.verbs(:type => :all) # default
39
+ pos.verbs(:type => :usu)
40
+ pos.verbs(:type => :transitive)
41
+ pos.verbs(:type => :intransitive)
42
+ ```
43
+
44
+ ### Find
45
+
46
+ Find parts of speech info for a word
47
+
48
+ ```ruby
49
+ pos.find("word")
50
+ #=> {
51
+ #=> :word => "word",
52
+ #=> :code => "Nt",
53
+ #=> :pos => [:noun, :vert_transitive]
54
+ #=> }
55
+
56
+ pos.find("walk")
57
+ #=> {
58
+ #=> :word => "walk",
59
+ #=> :code => "iNt",
60
+ #=> :pos => [:noun, :verb_transitive, :verb_intransitive]
61
+ #=> }
62
+ ```
63
+
64
+ ### Query
65
+
66
+ Check a word by part of speech
67
+
68
+ ```ruby
69
+ pos.noun?("animal") #=> true
70
+ pos.verb?("run") #=> true
71
+ pos.intransitive_verb?("walk") #=> true
72
+ pos.adjective?("sky") #=> false
73
+ ```
74
+
75
+ `#verb?` takes an optional `:type` parameter (like `#verbs`)
76
+
77
+ ```ruby
78
+ pos.verb?("abandon", :type => :transitive) #=> true
79
+ pos.verb?("overurbanized", :type => :intransitive) #=> false
80
+ pos.verb?("overurbanized") #=> true
81
+ ```
82
+
83
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,133 @@
1
+ module Moby
2
+ class PartsOfSpeech
3
+ def find(word)
4
+ { :word => word,
5
+ :found => pos.has_key?(word),
6
+ :code => pos_code(word),
7
+ :pos => pos_breakdown(word)
8
+ }
9
+ end
10
+
11
+ # Word list methods
12
+
13
+ def nouns; words(:noun); end
14
+ def plurals; words(:plural) end
15
+ def noun_phrases; words(:noun_phrase); end
16
+ def adjectives; words(:adjective); end
17
+ def adverbs; words(:adverb); end
18
+ def conjunctions; words(:conjunction); end
19
+ def prepositions; words(:preposition); end
20
+ def interjections; words(:interjection); end
21
+ def pronouns; words(:pronoun); end
22
+ def definite_articles; words(:definite_article); end
23
+ def indefinite_articles; words(:indefinite_article); end
24
+ def nominatives; words(:nominatives); end
25
+
26
+ def verbs(options = {:type => :all})
27
+ case options[:type]
28
+ when :all
29
+ words(:verb_usu_participle) +
30
+ words(:verb_transitive) +
31
+ words(:verb_intransitive)
32
+ when :usu
33
+ words(:verb_usu_participle)
34
+ when :transitive
35
+ words(:verb_transitive)
36
+ when :intransitive
37
+ words(:verb_intransitive)
38
+ end
39
+ end
40
+
41
+ # Query methods
42
+
43
+ def noun?(word); pos?(word, :noun); end
44
+ def plural?(word); pos?(word, :plural); end
45
+ def noun_phrase?(word); pos?(word, :noun_phrase); end
46
+ def adjective?(word); pos?(word, :adjective); end
47
+ def adverb?(word); pos?(word, :adverb); end
48
+ def conjunction?(word); pos?(word, :conjunction); end
49
+ def preposition?(word); pos?(word, :preposition); end
50
+ def interjection?(word); pos?(word, :interjection); end
51
+ def pronoun?(word); pos?(word, :pronoun); end
52
+ def definite_article?(word); pos?(word, :definite_article); end
53
+ def indefinite_article?(word); pos?(word, :indefinite_article); end
54
+ def nominative?(word); pos?(word, :nominative); end
55
+
56
+ def verb?(word, options = {:type => :all})
57
+ case options[:type]
58
+ when :all
59
+ pos?(word, :verb_usu_participle) ||
60
+ pos?(word, :verb_transitive) ||
61
+ pos?(word, :verb_intransitive)
62
+ when :usu
63
+ pos?(word, :verb_usu_participle)
64
+ when :transitive
65
+ pos?(word, :verb_transitive)
66
+ when :intransitive
67
+ pos?(word, :verb_intransitive)
68
+ end
69
+ end
70
+
71
+ private
72
+ def pos
73
+ path = %w{share moby parts-of-speech mobypos.UTF-8.txt}
74
+ pos = File.open(File.join(Moby::base_path, *path))
75
+
76
+ @pos ||= Hash[
77
+ pos.readlines.map {|ln|
78
+ ln.split('\\').map {|p| p.strip }
79
+ }
80
+ ]
81
+
82
+ @pos.default = ""
83
+ @pos
84
+ end
85
+
86
+ def pos?(word, pos_name)
87
+ find(word)[:pos].include?(pos_name.to_sym)
88
+ end
89
+
90
+ # Get words by pos name
91
+ def words(pos_name)
92
+ pos.select {|w, c| c.include?(pos_code_map.key(pos_name)) }.keys
93
+ end
94
+
95
+ # Get part of speech code for word
96
+ def pos_code(word)
97
+ pos[word]
98
+ end
99
+
100
+ def pos_code_map
101
+ @pos_code_map ||= {
102
+ "N" => :noun,
103
+ "p" => :plural,
104
+ "h" => :noun_phrase,
105
+ "V" => :verb_usu_participle,
106
+ "t" => :verb_transitive,
107
+ "i" => :verb_intransitive,
108
+ "A" => :adjective,
109
+ "v" => :adverb,
110
+ "C" => :conjunction,
111
+ "P" => :preposition,
112
+ "!" => :interjection,
113
+ "r" => :pronoun,
114
+ "D" => :definite_article,
115
+ "I" => :indefinite_article,
116
+ "o" => :nominative
117
+ }
118
+ end
119
+
120
+ def pos_codes
121
+ pos_code_map.keys
122
+ end
123
+
124
+ def pos_names
125
+ pos_code_map.values
126
+ end
127
+
128
+ # Convert POS code to array of descriptive symbols from #pos_code_map
129
+ def pos_breakdown(word)
130
+ pos_code(word).chars.to_a.map {|c| pos_code_map[c] }
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,3 @@
1
+ module Moby
2
+ VERSION = "1.0.1beta"
3
+ end
data/lib/moby.rb ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'moby/version'
4
+ require "moby/parts_of_speech"
5
+
6
+ module Moby
7
+ def self.base_path
8
+ File.expand_path("../..", __FILE__)
9
+ end
10
+ end
data/moby.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "moby/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "moby"
7
+ s.version = Moby::VERSION
8
+ s.authors = ["Dan Richert"]
9
+ s.email = ["dan.richert@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Ruby interface for Moby wordlists}
12
+ s.description = %q{Ruby interface for the world's largest free phonetic database}
13
+
14
+ s.rubyforge_project = "moby"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ end