@@ -52,18 +52,33 @@ func convertFullGenderToAbbr(_ genderFull: String) -> String {
5252/// - wordToAnnotate: the word that an annotation should be created for.
5353/// - KVC: the keyboard view controller.
5454func wordAnnotation( wordToAnnotate: String , KVC: KeyboardViewController ) {
55- var nounForm : String
55+ var genderAnnotations : [ String ] = [ ]
56+ var pluralAnnotation : String ?
57+
58+ // Get gender(s)
59+ let nounForm = LanguageDBManager . shared. queryNounForm ( of: wordToAnnotate) [ 0 ]
60+ if !nounForm. isEmpty {
61+ // nounForm might already be "M/F" if multiple genders found
62+ genderAnnotations = nounForm. components ( separatedBy: " / " )
63+ }
5664
57- // Check if word is plural first
65+ // Check if plural
5866 if let pluralWords = pluralWords, pluralWords. contains ( wordToAnnotate. lowercased ( ) ) {
59- nounForm = " PL "
60- } else {
61- nounForm = LanguageDBManager . shared. queryNounForm ( of: wordToAnnotate) [ 0 ]
67+ pluralAnnotation = " PL "
68+ }
69+
70+ // Combine: gender(s) first, then PL if applicable
71+ var allAnnotations = genderAnnotations
72+ if let pl = pluralAnnotation, !allAnnotations. contains ( " PL " ) {
73+ allAnnotations. append ( pl)
6274 }
6375
76+ // Join back with "/"
77+ let combinedNounForm = allAnnotations. joined ( separator: " / " )
78+
6479 prepAnnotationForm = LanguageDBManager . shared. queryPrepForm ( of: wordToAnnotate. lowercased ( ) ) [ 0 ]
6580
66- hasNounForm = !nounForm . isEmpty
81+ hasNounForm = !combinedNounForm . isEmpty
6782 hasPrepForm = !prepAnnotationForm. isEmpty
6883
6984 annotationsToAssign = [ String] ( )
@@ -105,10 +120,10 @@ func wordAnnotation(wordToAnnotate: String, KVC: KeyboardViewController) {
105120 )
106121 } else {
107122 if hasNounForm {
108- if !nounForm . contains ( " / " ) {
109- annotationsToAssign. append ( nounForm )
123+ if !combinedNounForm . contains ( " / " ) {
124+ annotationsToAssign. append ( combinedNounForm )
110125 } else {
111- for a in nounForm . components ( separatedBy: " / " ) {
126+ for a in combinedNounForm . components ( separatedBy: " / " ) {
112127 annotationsToAssign. append ( a)
113128 }
114129 }
@@ -262,16 +277,29 @@ func typedWordAnnotation(KVC: KeyboardViewController) {
262277/// - index: the auto action key index that the annotation should be set for.
263278/// - KVC: the keyboard view controller.
264279func autoActionAnnotation( autoActionWord: String , index: Int , KVC: KeyboardViewController ) {
265- var nounForm : String
280+ var genderAnnotations : [ String ] = [ ]
281+ var pluralAnnotation : String ?
266282
267- // Check if word is plural first
283+ // Get gender(s)
284+ let nounForm = LanguageDBManager . shared. queryNounForm ( of: autoActionWord) [ 0 ]
285+ if !nounForm. isEmpty {
286+ genderAnnotations = nounForm. components ( separatedBy: " / " )
287+ }
288+
289+ // Check if plural
268290 if let pluralWords = pluralWords, pluralWords. contains ( autoActionWord. lowercased ( ) ) {
269- nounForm = " PL "
270- } else {
271- nounForm = LanguageDBManager . shared. queryNounForm ( of: autoActionWord) [ 0 ]
291+ pluralAnnotation = " PL "
272292 }
273293
274- hasNounForm = !nounForm. isEmpty
294+ // Combine
295+ var allAnnotations = genderAnnotations
296+ if let pl = pluralAnnotation, !allAnnotations. contains ( " PL " ) {
297+ allAnnotations. append ( pl)
298+ }
299+
300+ let combinedNounForm = allAnnotations. joined ( separator: " / " )
301+
302+ hasNounForm = !combinedNounForm. isEmpty
275303
276304 newAutoActionAnnotationsToAssign = [ String] ( )
277305 newAutoActionAnnotationBtns = [ UIButton] ( )
@@ -282,10 +310,10 @@ func autoActionAnnotation(autoActionWord: String, index: Int, KVC: KeyboardViewC
282310 let annotationHeight = KVC . scribeKey. frame. height * 0.1
283311
284312 if hasNounForm {
285- if !nounForm . contains ( " / " ) {
286- newAutoActionAnnotationsToAssign. append ( nounForm )
313+ if !combinedNounForm . contains ( " / " ) {
314+ newAutoActionAnnotationsToAssign. append ( combinedNounForm )
287315 } else {
288- for a in nounForm . components ( separatedBy: " / " ) {
316+ for a in combinedNounForm . components ( separatedBy: " / " ) {
289317 newAutoActionAnnotationsToAssign. append ( a)
290318 }
291319 }
0 commit comments