Skip to content

Commit

Permalink
Merge pull request #35 from nerixim/add-passive-voice
Browse files Browse the repository at this point in the history
Add passive voice
  • Loading branch information
nerixim authored Dec 12, 2020
2 parents 3e2bc07 + 59112b6 commit 3210ce3
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 24 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ on:

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ tmtags
coverage
rdoc
pkg
vendor
.bundle

## PROJECT::SPECIFIC
Gemfile.lock
5 changes: 5 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ One of <tt>:indicative</tt>, <tt>:imperative</tt>, or <tt>:subjunctive</tt>. Def

Set this to a string to prepend the conjugated verb with it. When set to <tt>true</tt>, a standard personal pronoun will be used.

=== <tt>:diathesis</tt>

One of <tt>:active</tt> or <tt>:passive</tt>. Defaults to <tt>:active</tt>.

== Tense/aspect quick reference

EXAMPLE TENSE ASPECT
Expand Down Expand Up @@ -71,6 +75,7 @@ Set this to a string to prepend the conjugated verb with it. When set to <tt>tru
* {Pat Byrd and Tom McKlin}[http://www2.gsu.edu/~wwwesl/egw/pluralsv.htm]
* {Rick Harrison}[http://www.rickharrison.com/language/aspect.html]
* {Anatoli Makarevich}[https://github.com/makaroni4] for {#6}[https://github.com/rossmeissl/verbs/pull/6]
* {Nikita Kamaev}[https://github.com/nerixim] for {#35}[https://github.com/rossmeissl/verbs/pull/35]

== Copyright

Expand Down
60 changes: 41 additions & 19 deletions lib/verbs/conjugator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def conjugate(infinitive, options = {})
mood = options[:mood] || :indicative # imperative, subjunctive
aspect = options[:aspect] || :habitual # perfective, habitual, progressive, perfect, prospective

check_for_improper_constructions(tense, person, mood) # find incompatabilities
form = form_for(tense, aspect) # find form array based on tense and aspect
check_for_improper_constructions(infinitive, tense, person, mood, diathesis) # find incompatabilities
form = form_for(tense, aspect, diathesis) # find form array based on tense and aspect

# map form array to conjugation array, applying infinitive and options to the array
conjugation = form.map { |e| resolve e, infinitive, tense, person, plurality, mood }.join(' ').strip
Expand Down Expand Up @@ -275,23 +275,41 @@ def present_participle_with_doubled_terminal_consonant_for(verb)
# Params:
# * tense, an option given by the user
# * aspect, an option given by the user
def form_for(tense, aspect)
# * diathesis, an option given by the user
def form_for(tense, aspect, diathesis)
form = []
if tense == :future
form << 'will'
form << :infinitive if aspect == :habitual
form.concat ['have', :past_participle] if aspect == :perfect
form.concat ['be having', :past_participle] if aspect == :perfective
form.concat ['be', :present_participle] if aspect == :progressive
form.concat ['be about to', :infinitive] if aspect == :prospective
else
form.concat ['used to', :infinitive] if [tense, aspect] == [:past, :habitual]
form.concat [:have, :past_participle] if aspect == :perfect
form << :past if [tense, aspect] == [:past, :perfective]
form.concat [:be, :present_participle] if aspect == :progressive
form.concat [:be, 'about to', :infinitive] if aspect == :prospective
form << :present if [tense, aspect] == [:present, :habitual]
form.concat [:be, 'having', :past_participle] if [tense, aspect] == [:present, :perfective]
if diathesis == :active
if tense == :future
form << 'will'
form << :infinitive if aspect == :habitual
form.concat ['have', :past_participle] if aspect == :perfect
form.concat ['be having', :past_participle] if aspect == :perfective
form.concat ['be', :present_participle] if aspect == :progressive
form.concat ['be about to', :infinitive] if aspect == :prospective
else
form.concat ['used to', :infinitive] if [tense, aspect] == [:past, :habitual]
form.concat [:have, :past_participle] if aspect == :perfect
form << :past if [tense, aspect] == [:past, :perfective]
form.concat [:be, :present_participle] if aspect == :progressive
form.concat [:be, 'about to', :infinitive] if aspect == :prospective
form << :present if [tense, aspect] == [:present, :habitual]
form.concat [:be, 'having', :past_participle] if [tense, aspect] == [:present, :perfective]
end
elsif diathesis == :passive
if tense == :future
form << 'will'
form.concat ['be', :past_participle] if aspect == :habitual
form.concat ['have been', :past_participle] if aspect == :perfect
form.concat ['be being', :past_participle] if aspect == :progressive
form.concat ['be about to be', :past_participle] if aspect == :prospective
else
form.concat ['used to be', :past_participle] if [tense, aspect] == [:past, :habitual]
form.concat [:have, 'been', :past_participle] if aspect == :perfect
form.concat [:be, :past_participle] if [tense, aspect] == [:past, :perfective]
form.concat [:be, 'being', :past_participle] if aspect == :progressive
form.concat [:be, 'about to be', :past_participle] if aspect == :prospective
form.concat [:be, :past_participle] if [tense, aspect] == [:present, :habitual]
end
end
form
end
Expand All @@ -301,10 +319,14 @@ def form_for(tense, aspect)
# * tense, an option given by the user
# * person, how the conjugation refers to the subject
# * mood, an option given by the user
def check_for_improper_constructions(tense, person, mood)
# * diathesis, an option given by the user
def check_for_improper_constructions(infinitive, tense, person, mood, diathesis)
if mood == :imperative and not (person == :second and tense == :present)
raise Verbs::ImproperConstruction, 'The imperative mood requires present tense and second person'
end
if infinitive.to_sym == :be and diathesis == :passive
raise Verbs::ImproperConstruction, 'There is no passive diathesis for the copula'
end
end
end
end
38 changes: 38 additions & 0 deletions test/test_verbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,42 @@ def test_second_person_plural_forms
assert_equal 'You were about to accept', standard.conjugate(:accept, :tense => :past, :aspect => :prospective)
end
end

def test_passive
Verbs::Conjugator.with_options :diathesis => :passive, :person => :first, :plurality => :singular, :subject => true do |standard|
assert_equal 'I used to be accepted', standard.conjugate(:accept, :tense => :past, :aspect => :habitual)
assert_equal 'I had been accepted', standard.conjugate(:accept, :tense => :past, :aspect => :perfect)
assert_equal 'I was accepted', standard.conjugate(:accept, :tense => :past, :aspect => :perfective)
assert_equal 'I was being accepted', standard.conjugate(:accept, :tense => :past, :aspect => :progressive)
assert_equal 'I was about to be accepted', standard.conjugate(:accept, :tense => :past, :aspect => :prospective)
assert_equal 'I am accepted', standard.conjugate(:accept, :tense => :present, :aspect => :habitual)
assert_equal 'I have been accepted', standard.conjugate(:accept, :tense => :present, :aspect => :perfect)
assert_equal 'I am being accepted', standard.conjugate(:accept, :tense => :present, :aspect => :progressive)
assert_equal 'I am about to be accepted', standard.conjugate(:accept, :tense => :present, :aspect => :prospective)
assert_equal 'I will be accepted', standard.conjugate(:accept, :tense => :future, :aspect => :habitual)
assert_equal 'I will have been accepted', standard.conjugate(:accept, :tense => :future, :aspect => :perfect)
assert_equal 'I will be being accepted', standard.conjugate(:accept, :tense => :future, :aspect => :progressive)
assert_equal 'I will be about to be accepted', standard.conjugate(:accept, :tense => :future, :aspect => :prospective)
end

Verbs::Conjugator.with_options :diathesis => :passive, :person => :third, :plurality => :plural, :subject => true do |standard|
assert_equal 'They used to be accepted', standard.conjugate(:accept, :tense => :past, :aspect => :habitual)
assert_equal 'They had been accepted', standard.conjugate(:accept, :tense => :past, :aspect => :perfect)
assert_equal 'They were accepted', standard.conjugate(:accept, :tense => :past, :aspect => :perfective)
assert_equal 'They were being accepted', standard.conjugate(:accept, :tense => :past, :aspect => :progressive)
assert_equal 'They were about to be accepted', standard.conjugate(:accept, :tense => :past, :aspect => :prospective)
assert_equal 'They are accepted', standard.conjugate(:accept, :tense => :present, :aspect => :habitual)
assert_equal 'They have been accepted', standard.conjugate(:accept, :tense => :present, :aspect => :perfect)
assert_equal 'They are being accepted', standard.conjugate(:accept, :tense => :present, :aspect => :progressive)
assert_equal 'They are about to be accepted', standard.conjugate(:accept, :tense => :present, :aspect => :prospective)
assert_equal 'They will be accepted', standard.conjugate(:accept, :tense => :future, :aspect => :habitual)
assert_equal 'They will have been accepted', standard.conjugate(:accept, :tense => :future, :aspect => :perfect)
assert_equal 'They will be being accepted', standard.conjugate(:accept, :tense => :future, :aspect => :progressive)
assert_equal 'They will be about to be accepted', standard.conjugate(:accept, :tense => :future, :aspect => :prospective)
end

assert_raise Verbs::ImproperConstruction do
Verbs::Conjugator.conjugate(:be, :diathesis => :passive)
end
end
end

0 comments on commit 3210ce3

Please sign in to comment.