Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Om Sree Ganeshaya Namah: The first commit
- Loading branch information
0 parents
commit 8fa2975
Showing
12 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2009 [name of plugin creator] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Inflectionist | ||
============= | ||
|
||
The old school ActiveSupport's inflections allowed you to pluralize, singularize , humanize etc. And when you wanted little more complex linguistic processing , you found nothing. Here comes Inflectionist for your rescue. It is an extension to ActiveSupport inflections available in form of a rails plugin. For now, this will allow you to find simple past tense of any given word. | ||
|
||
|
||
|
||
Example | ||
======= | ||
|
||
"create".past_tensed => "created" | ||
"buy".past_tensed => "baught" | ||
"fight".past_tensed => "faught" | ||
"market".past_tensed => "marketed" | ||
"animate".past_tensed => "animated" | ||
"fluctuate".past_tensed => "fluctuated" | ||
"tag".past_tensed => "tagged" | ||
"feel".past_tensed => "felt" | ||
|
||
|
||
Installation | ||
============ | ||
|
||
... | ||
|
||
|
||
|
||
Goals & TODO | ||
============ | ||
1.) Implement past to present tense conversion | ||
2.) Implement more complex linguistic processing | ||
3.) Add more inflections | ||
|
||
|
||
|
||
Copyright (c) 2009 Er Abhishek Parolkar, released under the MIT license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the inflectionist plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the inflectionist plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'Inflectionist' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Author: Er Abhishek Parolkar | ||
|
||
require File.dirname(__FILE__) + '/lib/inflectionist' | ||
require File.dirname(__FILE__) + '/lib/inflections' | ||
require File.dirname(__FILE__) + '/lib/string_ext' | ||
ActiveSupport::Inflector.send(:extend, ParolkarInnovationLab::Inflectionist) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#Copyright (c) 2009 Er Abhishek Parolkar, released under the MIT license | ||
module ParolkarInnovationLab | ||
module Inflectionist | ||
|
||
def past_tensed(word) | ||
result = word.to_s.dup | ||
|
||
if word.empty? || inflections.uncountables.include?(result.downcase) | ||
result | ||
else | ||
inflections.past_tenses.each { |(rule, replacement)| break if result.gsub!(rule, replacement) } | ||
result | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
ActiveSupport::Inflector::Inflections.instance.instance_eval do # Keep in mind Inflections is a singleton, so what makes more sense is to inject our methods at run time to the instance | ||
|
||
def past_tenses # a attr_reader | ||
@past_tenses | ||
end | ||
def past_tense(rule, replacement) | ||
@past_tenses = [] if !@past_tenses | ||
@uncountables.delete(rule) if rule.is_a?(String) | ||
@uncountables.delete(replacement) | ||
@past_tenses.insert(0, [rule, replacement]) | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# this is where we define all the inflections for functionalities added by inflectionist plugin | ||
|
||
ActiveSupport::Inflector.inflections do |inflect| | ||
inflect.past_tense /^(.*)$/,'\1ed' | ||
inflect.past_tense /e$/,'ed' | ||
inflect.past_tense /t$/,'ted' | ||
inflect.past_tense /g$/,'gged' | ||
inflect.past_tense /ight$/,'aught' | ||
inflect.past_tense "buy",'baught' | ||
inflect.past_tense "sell",'sold' | ||
inflect.past_tense "is",'was' | ||
inflect.past_tense "are",'were' | ||
inflect.past_tense "teach",'taught' | ||
inflect.past_tense "feel",'felt' | ||
|
||
|
||
|
||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
# in case active_support/inflector is required without the rest of active_support | ||
require 'active_support/inflections' | ||
require 'active_support/core_ext/string/inflections' | ||
require 'active_support/inflector' unless defined?(ActiveSupport::Inflector) | ||
|
||
module ActiveSupport | ||
module CoreExtensions | ||
module String #:nodoc: | ||
module Inflections | ||
def past_tensed | ||
Inflector.past_tensed(self) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
String.send :include, ActiveSupport::CoreExtensions::String::Inflections # this is required for above changes to take effect | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :inflectionist do | ||
# # Task goes here | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'test_helper' | ||
|
||
class InflectionistTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rubygems' | ||
require 'active_support' | ||
require 'active_support/test_case' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Uninstall hook code here |