Skip to content

Commit

Permalink
🐛 fix(Word.swift): add missing case for imperative reflexive verb gen…
Browse files Browse the repository at this point in the history
…eration

🐛 fix(Word.swift): add missing case for conjugation reflexive verb generation
🐛 fix(WordService.swift): add missing conditions for reflexive verb matching in word query

🐛 fix(DynamicTableVerbs.swift): fix alignment issue in table headers
✨ feat(DynamicTableVerbs.swift): add support for reflexive present tense
✨ feat(DynamicTableVerbs.swift): add support for reflexive past tense
  • Loading branch information
andskur committed Jan 17, 2024
1 parent 34b86dd commit 3cc65f2
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 6 deletions.
94 changes: 94 additions & 0 deletions Source/Models/Word.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,30 @@ struct Word: Codable, Identifiable {
}
}

func generateImperativeReflexive(number: Number) -> String? {
switch number {
case .singular:
if let imp = generateImperative(number: number) {
return imp + "sk"
}
case .dual, .plural:
if var imp = generateImperative(number: number) {
imp.removeLast()
return imp + "zk"
}
}

return oldNorseWord
}

func generateImperative(number: Number) -> String? {
switch number {
case .singular:
if var inf = generateInfinitive() {
if inf.hasSuffix("ja") {
inf.removeLast(2)
} else if inf == "bana" {
return inf
} else {
inf.removeLast()
}
Expand Down Expand Up @@ -1678,6 +1696,82 @@ struct Word: Codable, Identifiable {
return genitiveCase
}

func generateConjugationReflexive(person: Person, number: Number, tense: Tense) -> String? {
switch tense {
case .past:
return generateConjugationPastReflexive(person: person, number: number)
case .present:
return generateConjugationPresentReflexive(person: person, number: number)
}
}

func generateConjugationPresentReflexive(person: Person, number: Number) -> String? {
var verb = generateConjugationPresent(person: person, number: number)

switch person {
case .first:
switch number {
case .singular:
if verb?.last == "a" {
verb?.removeLast()
}
return verb! + "umk"
case .dual, .plural:
return verb! + "sk"
}
case .second:
switch number {
case .singular:
verb?.removeLast()
return verb! + "sk"
case .dual, .plural:
verb?.removeLast()
return verb! + "zk"
}
case .third:
switch number {
case .singular:
verb?.removeLast()
return verb! + "sk"
case .dual, .plural:
return verb! + "sk"
}
}
}

func generateConjugationPastReflexive(person: Person, number: Number) -> String? {
var verb = generateConjugationPast(person: person, number: number)

switch person {
case .first:
switch number {
case .singular:
if verb?.last == "a" {
verb?.removeLast()
}
return verb! + "umk"
case .dual, .plural:
return verb! + "sk"
}
case .second:
switch number {
case .singular:
verb?.removeLast()
return verb! + "zk"
case .dual, .plural:
verb?.removeLast()
return verb! + "zk"
}
case .third:
switch number {
case .singular:
return verb! + "sk"
case .dual, .plural:
return verb! + "sk"
}
}
}


func generateConjugation(person: Person, number: Number, tense: Tense) -> String? {
switch tense {
Expand Down
19 changes: 18 additions & 1 deletion Source/Services/WordService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class WordService {

// This function checks if a word matches a query
func wordMatchesQuery(_ word: Word, query: String) -> Bool {
// nouns
let wordMatchesQuery = word.oldNorseWord.lowercased().contains(query)
let nominativeSingularMatchesQuery = word.generateNounNominative(number: Number.singular, article: false)?.lowercased().contains(query) == true
let nominativeDualMatchesQuery = word.generateNounNominative(number: Number.dual, article: false)?.lowercased().contains(query) == true
Expand All @@ -122,6 +123,7 @@ class WordService {
let genitivePluralMatchesQuery = word.generateNounGenitive(number: Number.plural, article: false)?.lowercased().contains(query) == true


// verbs
let firstSingularMatchesQuery = word.generateConjugation(person: .first, number: .singular, tense: .present)?.lowercased().contains(query) == true
let secondSingularMatchesQuery = word.generateConjugation(person: .second, number: .singular, tense: .present)?.lowercased().contains(query) == true
let thirdSingularMatchesQuery = word.generateConjugation(person: .third, number: .singular, tense: .present)?.lowercased().contains(query) == true
Expand All @@ -136,6 +138,21 @@ class WordService {
let secondPluralMatchesQueryPast = word.generateConjugation(person: .second, number: .plural, tense: .past)?.lowercased().contains(query) == true
let thirdPluralMatchesQueryPast = word.generateConjugation(person: .third, number: .plural, tense: .past)?.lowercased().contains(query) == true

// reflexive verbs
let firstSingularMatchesQueryR = word.generateConjugationReflexive(person: .first, number: .singular, tense: .present)?.lowercased().contains(query) == true
let secondSingularMatchesQueryR = word.generateConjugationReflexive(person: .second, number: .singular, tense: .present)?.lowercased().contains(query) == true
let thirdSingularMatchesQueryR = word.generateConjugationReflexive(person: .third, number: .singular, tense: .present)?.lowercased().contains(query) == true
let firstPluralMatchesQueryR = word.generateConjugationReflexive(person: .first, number: .plural, tense: .present)?.lowercased().contains(query) == true
let secondPluralMatchesQueryR = word.generateConjugationReflexive(person: .second, number: .plural, tense: .present)?.lowercased().contains(query) == true
let thirdPluralMatchesQueryR = word.generateConjugationReflexive(person: .third, number: .plural, tense: .present)?.lowercased().contains(query) == true

let firstSingularMatchesQueryPastR = word.generateConjugationReflexive(person: .first, number: .singular, tense: .past)?.lowercased().contains(query) == true
let secondSingularMatchesQueryPastR = word.generateConjugationReflexive(person: .second, number: .singular, tense: .past)?.lowercased().contains(query) == true
let thirdSingularMatchesQueryPastR = word.generateConjugationReflexive(person: .third, number: .singular, tense: .past)?.lowercased().contains(query) == true
let firstPluralMatchesQueryPastR = word.generateConjugationReflexive(person: .first, number: .plural, tense: .past)?.lowercased().contains(query) == true
let secondPluralMatchesQueryPastR = word.generateConjugationReflexive(person: .second, number: .plural, tense: .past)?.lowercased().contains(query) == true
let thirdPluralMatchesQueryPastR = word.generateConjugationReflexive(person: .third, number: .plural, tense: .past)?.lowercased().contains(query) == true

// nominative
let accNominativeSingularMasculine = word.generateCase(wordCase: .nominative, number: .singular, gender: .masculine)?.lowercased().contains(query) == true
let accNominativeSingularFemenine = word.generateCase(wordCase: .nominative, number: .singular, gender: .feminine)?.lowercased().contains(query) == true
Expand Down Expand Up @@ -225,6 +242,6 @@ class WordService {
let accImerativePlural = word.generateImperative(number: .plural)?.lowercased().contains(query) == true


return wordMatchesQuery || nominativeSingularMatchesQuery || nominativeDualMatchesQuery || nominativePluralMatchesQuery || accusativeSingularMatchesQuery || accusativeDualMatchesQuery || accusativePluralMatchesQuery || dativeSingularMatchesQuery || dativeDualMatchesQuery || dativePluralMatchesQuery || firstSingularMatchesQuery || secondSingularMatchesQuery || thirdSingularMatchesQuery || firstPluralMatchesQuery || secondPluralMatchesQuery || thirdPluralMatchesQuery || firstSingularMatchesQueryPast || secondSingularMatchesQueryPast || thirdSingularMatchesQueryPast || firstPluralMatchesQueryPast || secondPluralMatchesQueryPast || thirdPluralMatchesQueryPast || genitiveSingularMatchesQuery || genitiveDualMatchesQuery || genitivePluralMatchesQuery || accNominativeSingularMasculine || accNominativeSingularFemenine || accNominativeSingularNeuter || accNominativeDualMasculine || accNominativeDualFemenine || accNominativeDualNeuter || accNominativePluralMasculine || accNominativePluralFemenine || accAccusativePluralNeuter || accAccusativeSingularMasculine || accAccusativeSingularFemenine || accAccusativeSingularNeuter || accAccusativeDualMasculine || accAccusativeDualFemenine || accAccusativeDualNeuter || accAccusativePluralMasculine || accDativePluralFemenine || accDativePluralNeuter || accGenitiveSingularMasculine || accGenitiveSingularFemenine || accGenitiveSingularNeuter || accGenitiveDualMasculine || accGenitiveDualFemenine || accGenitiveDualNeuter || accGenitivePluralMasculine || accGenitivePluralFemenine || accGenitivePluralNeuter || accNominativePluralNeuter || accDativeSingularMasculine || accDativePluralMasculine || accDativeDualNeuter || accDativeDualFemenine || accDativeDualMasculine || accDativeSingularFemenine || accDativeSingularNeuter || accAccusativePluralFemenine || accComparative || accInfinitive || accImerativeSingular || accImerativePlural || accComparativeAdjective1 || accComparativeAdjective2 || accComparativeAdjective3 || accComparisonWeakAdjective1 || accComparisonWeakAdjective2 || accComparisonWeakAdjective3 || accComparisonStrongAdjective1 || accComparisonStrongAdjective2 || accComparisonStrongAdjective3 || accComparisonStrongAdjective4 || accComparisonStrongAdjective5 || accComparisonStrongAdjective6 || accComparisonStrongAdjective7 || accComparisonStrongAdjective8 || accComparisonStrongAdjective9 || accComparisonStrongAdjective10 || accComparisonStrongAdjective11 || accComparisonStrongAdjective12 || accComparisonStrongAdjective13 || accComparisonStrongAdjective14 || accComparisonStrongAdjective15 || accComparisonStrongAdjective16 || accComparisonStrongAdjective17 || accComparison
return wordMatchesQuery || nominativeSingularMatchesQuery || nominativeDualMatchesQuery || nominativePluralMatchesQuery || accusativeSingularMatchesQuery || accusativeDualMatchesQuery || accusativePluralMatchesQuery || dativeSingularMatchesQuery || dativeDualMatchesQuery || dativePluralMatchesQuery || firstSingularMatchesQuery || secondSingularMatchesQuery || thirdSingularMatchesQuery || firstPluralMatchesQuery || secondPluralMatchesQuery || thirdPluralMatchesQuery || firstSingularMatchesQueryPast || secondSingularMatchesQueryPast || thirdSingularMatchesQueryPast || firstPluralMatchesQueryPast || secondPluralMatchesQueryPast || thirdPluralMatchesQueryPast || genitiveSingularMatchesQuery || genitiveDualMatchesQuery || genitivePluralMatchesQuery || accNominativeSingularMasculine || accNominativeSingularFemenine || accNominativeSingularNeuter || accNominativeDualMasculine || accNominativeDualFemenine || accNominativeDualNeuter || accNominativePluralMasculine || accNominativePluralFemenine || accAccusativePluralNeuter || accAccusativeSingularMasculine || accAccusativeSingularFemenine || accAccusativeSingularNeuter || accAccusativeDualMasculine || accAccusativeDualFemenine || accAccusativeDualNeuter || accAccusativePluralMasculine || accDativePluralFemenine || accDativePluralNeuter || accGenitiveSingularMasculine || accGenitiveSingularFemenine || accGenitiveSingularNeuter || accGenitiveDualMasculine || accGenitiveDualFemenine || accGenitiveDualNeuter || accGenitivePluralMasculine || accGenitivePluralFemenine || accGenitivePluralNeuter || accNominativePluralNeuter || accDativeSingularMasculine || accDativePluralMasculine || accDativeDualNeuter || accDativeDualFemenine || accDativeDualMasculine || accDativeSingularFemenine || accDativeSingularNeuter || accAccusativePluralFemenine || accComparative || accInfinitive || accImerativeSingular || accImerativePlural || accComparativeAdjective1 || accComparativeAdjective2 || accComparativeAdjective3 || accComparisonWeakAdjective1 || accComparisonWeakAdjective2 || accComparisonWeakAdjective3 || accComparisonStrongAdjective1 || accComparisonStrongAdjective2 || accComparisonStrongAdjective3 || accComparisonStrongAdjective4 || accComparisonStrongAdjective5 || accComparisonStrongAdjective6 || accComparisonStrongAdjective7 || accComparisonStrongAdjective8 || accComparisonStrongAdjective9 || accComparisonStrongAdjective10 || accComparisonStrongAdjective11 || accComparisonStrongAdjective12 || accComparisonStrongAdjective13 || accComparisonStrongAdjective14 || accComparisonStrongAdjective15 || accComparisonStrongAdjective16 || accComparisonStrongAdjective17 || accComparison || firstSingularMatchesQueryR || secondSingularMatchesQueryR || thirdSingularMatchesQueryR || firstPluralMatchesQueryR || secondPluralMatchesQueryR || thirdPluralMatchesQueryR || firstSingularMatchesQueryPastR || secondSingularMatchesQueryPastR || thirdSingularMatchesQueryPastR || firstPluralMatchesQueryPastR || secondPluralMatchesQueryPastR || thirdPluralMatchesQueryPastR
}
}
Loading

0 comments on commit 3cc65f2

Please sign in to comment.