How to use ends_with method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

greek.py

Source:greek.py Github

copy

Full Screen

...9 'ά':'α', 'έ':'ε', 'ή':'η', 'ί':'ι', 'ό':'ο', 'ύ':'υ', 'ώ':'ω', 'Ϊ':'ϊ', 'Ϋ':'ϋ'}10r = {}11for k, v in replacements.iteritems():12 r[k] = v13def ends_with(word, suffix):14 return word[len(word) - len(suffix):] == suffix15def stem(w):16 17 18 word = ""19 for i in w:20 if i in r:21 word += r[i]22 else:23 word += i24 done = len(word) <= 325 26 ##rule-set 127 ##γιαγιαδεσ->γιαγ, ομαδεσ->ομαδ28 if not done:29 for suffix in [i.decode("utf8") for i in ['ιαδες', 'αδες', 'αδων']]:30 if ends_with(word, suffix):31 word = word[:len(word) - len(suffix)]32 remaining_part_does_not_end_on = True33 for s in [i.decode("utf8") for i in ['οκ', 'μαμ', 'μαν', 'μπαμπ', 'πατερ', 'γιαγ', 'νταντ', 'κυρ', 'θει', 'πεθερ']]:34 if ends_with(word, s):35 remaining_part_does_not_end_on = False36 break37 if remaining_part_does_not_end_on:38 word = word + 'αδ'.decode("utf8")39 done = True40 break41 ##rule-set 242 ##καφεδεσ->καφ, γηπεδων->γηπεδ43 if not done:44 for suffix in [i.decode("utf8") for i in ['εδες', 'εδων']]:45 if ends_with(word, suffix):46 word = word[:len(word) - len(suffix)]47 for s in [i.decode("utf8") for i in ['οπ', 'ιπ', 'εμπ', 'υπ', 'γηπ', 'δαπ', 'κρασπ', 'μιλ']]:48 if ends_with(word, s):49 word = word + 'εδ'.decode("utf8")50 break51 done = True52 break53 ##rule-set 354 ##παππουδων->παππ, αρκουδεσ->αρκουδ55 if not done:56 for suffix in [i.decode("utf8") for i in ['ουδες', 'ουδων']]:57 if ends_with(word, suffix):58 word = word[:len(word) - len(suffix)]59 for s in [i.decode("utf8") for i in ['αρκ', 'καλιακ', 'πεταλ', 'λιχ', 'πλεξ', 'σκ', 'ς', 'φλ', 'φρ', 'βελ', 'λουλ', 'χν', 'σπ', 'τραγ', 'φε']]:60 if ends_with(word, s):61 word = word + 'ουδ'.decode("utf8")62 break63 done = True64 break65 ##rule-set 466 ##υποθεσεωσ->υποθεσ, θεων->θε67 if not done:68 for suffix in [i.decode("utf8") for i in ['εως', 'εων']]:69 if ends_with(word, suffix):70 word = word[:len(word) - len(suffix)]71 for s in [i.decode("utf8") for i in ['θ', 'δ', 'ελ', 'γαλ', 'ν', 'π', 'ιδ', 'παρ']]:72 if ends_with(word, s):73 word = word + 'ε'.decode("utf8")74 break75 done = True76 break77 ##rule-set 578 ##παιδια->παιδ, τελειου->τελει79 if not done:80 for suffix in [i.decode("utf8") for i in ['ια', 'ιου', 'ιων']]:81 if ends_with(word, suffix):82 word = word[:len(word) - len(suffix)]83 for s in VOWELS:84 if ends_with(word, s):85 word = word + 'ι'.decode("utf8")86 break87 done = True88 break89 ##rule-set 690 ##ζηλιαρικο->ζηλιαρ, αγροικοσ->αγροικ91 if not done:92 for suffix in [i.decode("utf8") for i in ['ικα', 'ικου', 'ικων', 'ικος', 'ικο', 'ικη']]:93 if ends_with(word, suffix):94 word = word[:len(word) - len(suffix)]95 if word in [i.decode("utf8") for i in ['αλ', 'αδ', 'ενδ', 'αμαν', 'αμμοχαλ', 'ηθ', 'ανηθ', 'αντιδ', 'φυς', 'βρωμ', 'γερ', 'εξωδ', 'καλπ',96 'καλλιν', 'καταδ', 'μουλ', 'μπαν', 'μπαγιατ', 'μπολ', 'μπος', 'νιτ', 'ξικ', 'συνομηλ', 'πετς', 'πιτς',97 'πικαντ', 'πλιατς', 'ποντ', 'ποστελν', 'πρωτοδ', 'σερτ', 'συναδ', 'τσαμ', 'υποδ', 'φιλον', 'φυλοδ',98 'χας']]:99 word = word + 'ικ'.decode("utf8")100 else:101 for s in VOWELS:102 if ends_with(word, s):103 word = word + 'ικ'.decode("utf8")104 break105 done = True106 break107 ##rule-set 7108 ##αγαπαγαμε->αγαπ, αναπαμε->αναπαμ109 if not done:110 if word == 'αγαμε'.decode("utf8"): word = 2*word111 for suffix in [i.decode("utf8") for i in ['ηθηκαμε', 'αγαμε', 'ησαμε', 'ουσαμε', 'ηκαμε']]:112 if ends_with(word, suffix):113 word = word[:len(word) - len(suffix)]114 if word in ['φ'.decode("utf8")]:115 word = word + 'αγαμ'.decode("utf8")116 done = True117 break118 if not done and ends_with(word, 'αμε'.decode("utf8")):119 word = word[:len(word) - len('αμε'.decode("utf8"))]120 if word in [i.decode("utf8") for i in ['αναπ', 'αποθ', 'αποκ', 'αποστ', 'βουβ', 'ξεθ', 'ουλ', 'πεθ', 'πικρ', 'ποτ', 'σιχ', 'χ']]:121 word = word + 'αμ'.decode("utf8")122 done = True123 ##rule-set 8124 ##αγαπησαμε->αγαπ, τραγανε->τραγαν125 if not done:126 for suffix in [i.decode("utf8") for i in ['ιουντανε', 'ιοντανε', 'ουντανε', 'ηθηκανε', 'ουσανε', 'ιοτανε', 'οντανε', 'αγανε', 'ησανε',127 'οτανε', 'ηκανε']]:128 if ends_with(word, suffix):129 word = word[:len(word) - len(suffix)]130 if word in [i.decode("utf8") for i in ['τρ', 'τς', 'φ']]:131 word = word + 'αγαν'.decode("utf8")132 done = True133 break134 if not done and ends_with(word, 'ανε'.decode("utf8")):135 word = word[:len(word) - len('αμε'.decode("utf8"))]136 if word in [i.decode("utf8") for i in ['βετερ', 'βουλκ', 'βραχμ', 'γ', 'δραδουμ', 'θ', 'καλπουζ', 'καστελ', 'κορμορ', 'λαοπλ', 'μωαμεθ', 'μ',137 'μουσουλμ', 'ν', 'ουλ', 'π', 'πελεκ', 'πλ', 'πολις', 'πορτολ', 'σαρακατς', 'σουλτ', 'τσαρλατ', 'ορφ',138 'τσιγγ', 'τσοπ', 'φωτοστεφ', 'χ', 'ψυχοπλ', 'αγ', 'ορφ', 'γαλ', 'γερ', 'δεκ', 'διπλ', 'αμερικαν', 'ουρ',139 'πιθ', 'πουριτ', 'ς', 'ζωντ', 'ικ', 'καστ', 'κοπ', 'λιχ', 'λουθηρ', 'μαιντ', 'μελ', 'σιγ', 'σπ', 'στεγ',140 'τραγ', 'τσαγ', 'φ', 'ερ', 'αδαπ', 'αθιγγ', 'αμηχ', 'ανικ', 'ανοργ', 'απηγ', 'απιθ', 'ατσιγγ', 'βας',141 'βασκ', 'βαθυγαλ', 'βιομηχ', 'βραχυκ', 'διατ', 'διαφ', 'ενοργ', 'θυς', 'καπνοβιομηχ', 'καταγαλ', 'κλιβ',142 'κοιλαρφ', 'λιβ', 'μεγλοβιομηχ', 'μικροβιομηχ', 'νταβ', 'ξηροκλιβ', 'ολιγοδαμ', 'ολογαλ', 'πενταρφ',143 'περηφ', 'περιτρ', 'πλατ', 'πολυδαπ', 'πολυμηχ', 'στεφ', 'ταβ', 'τετ', 'υπερηφ', 'υποκοπ', 'χαμηλοδαπ',144 'ψηλοταβ']]:145 word = word + 'αν'.decode("utf8")146 else:147 for s in VOWELS:148 if ends_with(word, s):149 word = word + 'αν'.decode("utf8")150 break151 done = True152 ##rule-set 9153 ##αγαπησετε->αγαπ, βενετε->βενετ154 if not done:155 if ends_with(word, 'ησετε'.decode("utf8")):156 word = word[:len(word) - len('ησετε'.decode("utf8"))]157 done = True158 elif ends_with(word, 'ετε'.decode("utf8")):159 word = word[:len(word) - len('ετε'.decode("utf8"))]160 if word in [i.decode("utf8") for i in ['αβαρ', 'βεν', 'εναρ', 'αβρ', 'αδ', 'αθ', 'αν', 'απλ', 'βαρον', 'ντρ', 'σκ', 'κοπ', 'μπορ', 'νιφ', 'παγ',161 'παρακαλ', 'σερπ', 'σκελ', 'συρφ', 'τοκ', 'υ', 'δ', 'εμ', 'θαρρ', 'θ']]:162 word = word + 'ετ'.decode("utf8")163 else:164 for s in [i.decode("utf8") for i in ['οδ', 'αιρ', 'φορ', 'ταθ', 'διαθ', 'σχ', 'ενδ', 'ευρ', 'τιθ', 'υπερθ', 'ραθ', 'ενθ', 'ροθ', 'σθ', 'πυρ',165 'αιν', 'συνδ', 'συν', 'συνθ', 'χωρ', 'πον', 'βρ', 'καθ', 'ευθ', 'εκθ', 'νετ', 'ρον', 'αρκ', 'βαρ', 'βολ',166 'ωφελ']] + VOWELS:167 if ends_with(word, s):168 word = word + 'ετ'.decode("utf8")169 break170 done = True171 ##rule-set 10172 ##αγαπωντασ->αγαπ, ξενοφωντασ->ξενοφων173 if not done:174 for suffix in [i.decode("utf8") for i in ['οντας', 'ωντας']]:175 if ends_with(word, suffix):176 word = word[:len(word) - len(suffix)]177 if word in ['αρχ'.decode("utf8")]:178 word = word + 'οντ'.decode("utf8")179 elif word in [i.decode("utf8") for i in ['ξενοφ', 'κρε']]:180 word = word + 'ωντ'.decode("utf8")181 done = True182 break183 ##rule-set 11184 ##αγαπιομαστε->αγαπ, ονομαστε->ονομαστ185 if not done:186 for suffix in [i.decode("utf8") for i in ['ιομαστε', 'ομαστε']]:187 if ends_with(word, suffix):188 word = word[:len(word) - len(suffix)]189 if word in ['ον'.decode("utf8")]:190 word = word + 'ομαστ'.decode("utf8")191 done = True192 break193 ##rule-set 12194 ##αγαπιεστε->αγαπ, πιεστε->πιεστ195 if not done:196 for suffix in ['ιεστε'.decode("utf8")]:197 if ends_with(word, suffix):198 word = word[:len(word) - len(suffix)]199 if word in [i.decode("utf8") for i in ['π', 'απ', 'συμπ', 'ασυμπ', 'καταπ', 'μεταμφ']]:200 word = word + 'ιεστ'.decode("utf8")201 done = True202 break203 if not done:204 for suffix in ['εστε'.decode("utf8")]:205 if ends_with(word, suffix):206 word = word[:len(word) - len(suffix)]207 if word in [i.decode("utf8") for i in ['αλ', 'αρ', 'εκτελ', 'ζ', 'μ', 'ξ', 'παρακαλ', 'αρ', 'προ', 'νις']]:208 word = word + 'εστ'.decode("utf8")209 done = True210 break211 ##rule-set 13212 ##χτιστηκε->χτιστ, διαθηκεσ->διαθηκ213 if not done:214 for suffix in [i.decode("utf8") for i in ['ηθηκα', 'ηθηκες', 'ηθηκε']]:215 if ends_with(word, suffix):216 word = word[:len(word) - len(suffix)]217 done = True218 break219 if not done:220 for suffix in [i.decode("utf8") for i in ['ηκα', 'ηκες', 'ηκε']]:221 if ends_with(word, suffix):222 word = word[:len(word) - len(suffix)]223 if word in [i.decode("utf8") for i in ['διαθ', 'θ', 'παρακαταθ', 'προσθ', 'συνθ']]:224 word = word + 'ηκ'.decode("utf8")225 else:226 for suffix in [i.decode("utf8") for i in ['σκωλ', 'σκουλ', 'ναρθ', 'σφ', 'οθ', 'πιθ']]:227 if ends_with(word, suffix):228 word = word + 'ηκ'.decode("utf8")229 break230 done = True231 break232 233 ##rule-set 14234 ##χτυπουσεσ->χτυπ, μεδουσεσ->μεδουσ235 if not done:236 for suffix in [i.decode("utf8") for i in ['ουσα', 'ουσες', 'ουσε']]:237 if ends_with(word, suffix):238 word = word[:len(word) - len(suffix)]239 if word in [i.decode("utf8") for i in ['φαρμακ', 'χαδ', 'αγκ', 'αναρρ', 'βρομ', 'εκλιπ', 'λαμπιδ', 'λεχ', 'μ', 'πατ', 'ρ', 'λ', 'μεδ', 'μεσαζ',240 'υποτειν', 'αμ', 'αιθ', 'ανηκ', 'δεσποζ', 'ενδιαφερ', 'δε', 'δευτερευ', 'καθαρευ', 'πλε', 'τσα']]:241 word = word + 'ους'.decode("utf8")242 else:243 for s in [i.decode("utf8") for i in ['ποδαρ', 'βλεπ', 'πανταχ', 'φρυδ', 'μαντιλ', 'μαλλ', 'κυματ', 'λαχ', 'ληγ', 'φαγ', 'ομ', 'πρωτ']] + VOWELS:244 if ends_with(word, s):245 word = word + 'ους'.decode("utf8")246 break247 done = True248 break249 ##rule-set 15250 #κολλαγεσ->κολλ, αβασταγα->αβαστ251 if not done:252 for suffix in [i.decode("utf8") for i in ['αγα', 'αγες', 'αγε']]:253 if ends_with(word, suffix):254 word = word[:len(word) - len(suffix)]255 if word in [i.decode("utf8") for i in ['αβαστ', 'πολυφ', 'αδηφ', 'παμφ', 'ρ', 'ασπ', 'αφ', 'αμαλ', 'αμαλλι', 'ανυστ', 'απερ', 'ασπαρ', 'αχαρ',256 'δερβεν', 'δροσοπ', 'ξεφ', 'νεοπ', 'νομοτ', 'ολοπ', 'ομοτ', 'προστ', 'προσωποπ', 'συμπ', 'συντ', 'τ',257 'υποτ', 'χαρ', 'αειπ', 'αιμοστ', 'ανυπ', 'αποτ', 'αρτιπ', 'διατ', 'εν', 'επιτ', 'κροκαλοπ', 'σιδηροπ',258 'λ', 'ναυ', 'ουλαμ', 'ουρ', 'π', 'τρ', 'μ']]:259 word = word + 'αγ'.decode("utf8")260 else:261 for s in [i.decode("utf8") for i in ['οφ', 'πελ', 'χορτ', 'σφ', 'ρπ', 'φρ', 'πρ', 'λοχ', 'σμην']]:262 # αφαιρεθηκε: 'λλ'263 if ends_with(word, s):264 if not word in ['ψοφ'.decode("utf8"), 'ναυλοχ'.decode("utf8")]:265 word = word + 'αγ'.decode("utf8")266 break267 done = True268 break269 ##rule-set 16270 ##αγαπησε->αγαπ, νησου->νησ271 if not done:272 for suffix in [i.decode("utf8") for i in ['ησε', 'ησου', 'ησα']]:273 if ends_with(word, suffix):274 word = word[:len(word) - len(suffix)]275 if word in [i.decode("utf8") for i in ['ν', 'χερσον', 'δωδεκαν', 'ερημον', 'μεγαλον', 'επταν', 'αγαθον']]:276 word = word + 'ης'.decode("utf8")277 done = True278 break279 280 ##rule-set 17281 ##αγαπηστε->αγαπ, σβηστε->σβηστ282 if not done:283 for suffix in ['ηστε'.decode("utf8")]:284 if ends_with(word, suffix):285 word = word[:len(word) - len(suffix)]286 if word in [i.decode("utf8") for i in ['ασβ', 'σβ', 'αχρ', 'χρ', 'απλ', 'αειμν', 'δυσχρ', 'ευχρ', 'κοινοχρ', 'παλιμψ']]:287 word = word + 'ηστ'.decode("utf8")288 done = True289 break290 291 ##rule-set 18292 ##αγαπουνε->αγαπ, σπιουνε->σπιουν293 if not done:294 for suffix in [i.decode("utf8") for i in ['ουνε', 'ησουνε', 'ηθουνε']]:295 if ends_with(word, suffix):296 word = word[:len(word) - len(suffix)]297 if word in [i.decode("utf8") for i in ['ν', 'ρ', 'σπι', 'στραβομουτς', 'κακομουτς', 'εξων']]:298 word = word + 'ουν'.decode("utf8")299 done = True300 break301 302 ##rule-set 19303 ##αγαπουμε->αγαπ, φουμε->φουμ304 if not done:305 for suffix in [i.decode("utf8") for i in ['ουμε', 'ησουμε', 'ηθουμε']]:306 if ends_with(word, suffix):307 word = word[:len(word) - len(suffix)]308 if word in [i.decode("utf8") for i in ['παρασους', 'φ', 'χ', 'ωριοπλ', 'αζ', 'αλλοσους', 'ασους']]:309 word = word + 'ουμ'.decode("utf8")310 done = True311 break312 313 ##rule-set 20314 ##κυματα->κυμ, χωρατο->χωρατ315 if not done:316 for suffix in [i.decode("utf8") for i in ['ματα', 'ματων', 'ματος']]:317 if ends_with(word, suffix):318 word = word[:len(word) - len(suffix)]319 word = word + 'μ'.decode("utf8")320 done = True321 break322 323 ##rule-set 21324 if not done:325 for suffix in [i.decode("utf8") for i in ['ιοντουσαν', 'ιουμαστε', 'ιομασταν', 'ιοσασταν', 'οντουσαν', 'ιοσαστε', 'ιεμαστε', 'ιεσαστε', 'ιομουνα',326 'ιοσουνα', 'ιουνται', 'ιουνταν', 'ηθηκατε', 'ομασταν', 'οσασταν', 'ουμαστε', 'ιομουν', 'ιονταν', 'ιοσουν',327 'ηθειτε', 'ηθηκαν', 'ομουνα', 'οσαστε', 'οσουνα', 'ουνται', 'ουνταν', 'ουσατε', 'αγατε', 'ειται', 'ιεμαι',328 'ιεται', 'ιεσαι', 'ιοταν', 'ιουμα', 'ηθεις', 'ηθουν', 'ηκατε', 'ησατε', 'ησουν', 'ομουν', 'ονται',329 'ονταν', 'οσουν', 'ουμαι', 'ουσαν', 'αγαν', 'αμαι', 'ασαι', 'αται', 'ειτε', 'εσαι', 'εται', 'ηδες',330 'ηδων', 'ηθει', 'ηκαν', 'ησαν', 'ησει', 'ησες', 'ομαι', 'οταν', 'αει', 'εις', 'ηθω', 'ησω', 'ουν',331 'ους', 'αν', 'ας', 'αω', 'ει', 'ες', 'ης', 'οι', 'ον', 'ος', 'ου', 'υς', 'ων', 'ως', 'α', 'ε', 'ι', 'η',332 'ο', 'υ', 'ω']]:333 if ends_with(word, suffix):334 word = word[:len(word) - len(suffix)]335 break336 ##rule-set 22337 ##πλησιεστατοσ->πλυσι, μεγαλυτερη->μεγαλ, κοντοτερο->κοντ338 if not done:339 for suffix in [i.decode("utf8") for i in ['εστερ', 'εστατ', 'οτερ', 'οτατ', 'υτερ', 'υτατ', 'ωτερ', 'ωτατ']]:340 if ends_with(word, suffix):341 word = word[:len(word) - len(suffix)]342 break343 344 if len(word) >=3: 345 return word346 return ""...

Full Screen

Full Screen

PorterStemmer.py

Source:PorterStemmer.py Github

copy

Full Screen

...81 ch = self.word[i]82 if ch == 'w' or ch == 'x' or ch == 'y':83 return 084 return 185 def ends_with(self, s):86 """:returns TRUE when {start...end} ends with the string s."""87 length = len(s)88 if s[length - 1] != self.word[self.end]: # tiny speed-up89 return False90 if length > (self.end - self.start + 1):91 return False92 if self.word[self.end - length + 1: self.end + 1] != s:93 return False94 self.offset = self.end - length95 return True96 def set_to(self, s):97 """sets [offset + 1, end] to the characters in the string s, readjusting end."""98 length = len(s)99 self.word = self.word[:self.offset + 1] + s + self.word[self.offset + length + 1:]100 self.end = self.offset + length101 def replace_morpheme(self, s):102 """is a mapping function to change morphemes"""103 if self.m() > 0:104 self.set_to(s)105 def remove_plurals(self):106 """This is step 1 ab and gets rid of plurals and -ed or -ing. e.g.107 caresses -> caress108 ponies -> poni109 ties -> ti110 caress -> caress111 cats -> cat112 feed -> feed113 agreed -> agree114 disabled -> disable115 matting -> mat116 mating -> mate117 meeting -> meet118 milling -> mill119 messing -> mess120 meetings -> meet121 """122 if self.word[self.end] == 's':123 if self.ends_with("sses"):124 self.end = self.end - 2125 elif self.ends_with("ies"):126 self.set_to("i")127 elif self.word[self.end - 1] != 's':128 self.end = self.end - 1129 if self.ends_with("eed"):130 if self.m() > 0:131 self.end = self.end - 1132 elif (self.ends_with("ed") or self.ends_with("ing")) and self.contains_vowel():133 self.end = self.offset134 if self.ends_with("at"):135 self.set_to("ate")136 elif self.ends_with("bl"):137 self.set_to("ble")138 elif self.ends_with("iz"):139 self.set_to("ize")140 elif self.contains_double_consonant(self.end):141 self.end = self.end - 1142 ch = self.word[self.end]143 if ch == 'l' or ch == 's' or ch == 'z':144 self.end = self.end + 1145 elif self.m() == 1 and self.is_of_form_cvc(self.end):146 self.set_to("e")147 def terminal_y_to_i(self):148 """This defines step 1 c which turns terminal y to i when there is another vowel in the stem."""149 if self.ends_with('y') and self.contains_vowel():150 self.word = self.word[:self.end] + 'i' + self.word[self.end + 1:]151 def map_double_to_single_suffix(self):152 """Defines step 2 and maps double suffices to single ones.153 so -ization ( = -ize plus -ation) maps to -ize etc. note that the154 string before the suffix must give m() > 0.155 """156 if self.word[self.end - 1] == 'a':157 if self.ends_with("ational"):158 self.replace_morpheme("ate")159 elif self.ends_with("tional"):160 self.replace_morpheme("tion")161 elif self.word[self.end - 1] == 'c':162 if self.ends_with("enci"):163 self.replace_morpheme("ence")164 elif self.ends_with("anci"):165 self.replace_morpheme("ance")166 elif self.word[self.end - 1] == 'e':167 if self.ends_with("izer"): self.replace_morpheme("ize")168 elif self.word[self.end - 1] == 'l':169 if self.ends_with("bli"):170 self.replace_morpheme("ble") # --DEPARTURE--171 # To match the published algorithm, replace this phrase with172 # if self.ends("abli"): self.r("able")173 elif self.ends_with("alli"):174 self.replace_morpheme("al")175 elif self.ends_with("entli"):176 self.replace_morpheme("ent")177 elif self.ends_with("eli"):178 self.replace_morpheme("e")179 elif self.ends_with("ousli"):180 self.replace_morpheme("ous")181 elif self.word[self.end - 1] == 'o':182 if self.ends_with("ization"):183 self.replace_morpheme("ize")184 elif self.ends_with("ation"):185 self.replace_morpheme("ate")186 elif self.ends_with("ator"):187 self.replace_morpheme("ate")188 elif self.word[self.end - 1] == 's':189 if self.ends_with("alism"):190 self.replace_morpheme("al")191 elif self.ends_with("iveness"):192 self.replace_morpheme("ive")193 elif self.ends_with("fulness"):194 self.replace_morpheme("ful")195 elif self.ends_with("ousness"):196 self.replace_morpheme("ous")197 elif self.word[self.end - 1] == 't':198 if self.ends_with("aliti"):199 self.replace_morpheme("al")200 elif self.ends_with("iviti"):201 self.replace_morpheme("ive")202 elif self.ends_with("biliti"):203 self.replace_morpheme("ble")204 elif self.word[self.end - 1] == 'g':205 if self.ends_with("logi"): self.replace_morpheme("log")206 def step3(self):207 """step3() deals with -ic-, -full, -ness etc."""208 if self.word[self.end] == 'e':209 if self.ends_with("icate"):210 self.replace_morpheme("ic")211 elif self.ends_with("ative"):212 self.replace_morpheme("")213 elif self.ends_with("alize"):214 self.replace_morpheme("al")215 elif self.word[self.end] == 'i':216 if self.ends_with("iciti"): self.replace_morpheme("ic")217 elif self.word[self.end] == 'l':218 if self.ends_with("ical"):219 self.replace_morpheme("ic")220 elif self.ends_with("ful"):221 self.replace_morpheme("")222 elif self.word[self.end] == 's':223 if self.ends_with("ness"): self.replace_morpheme("")224 def step4(self):225 """step4() takes off -ant, -ence etc., in context <c>vcvc<v>."""226 if self.word[self.end - 1] == 'a':227 if self.ends_with("al"):228 pass229 else:230 return231 elif self.word[self.end - 1] == 'c':232 if self.ends_with("ance"):233 pass234 elif self.ends_with("ence"):235 pass236 else:237 return238 elif self.word[self.end - 1] == 'e':239 if self.ends_with("er"):240 pass241 else:242 return243 elif self.word[self.end - 1] == 'i':244 if self.ends_with("ic"):245 pass246 else:247 return248 elif self.word[self.end - 1] == 'l':249 if self.ends_with("able"):250 pass251 elif self.ends_with("ible"):252 pass253 else:254 return255 elif self.word[self.end - 1] == 'n':256 if self.ends_with("ant"):257 pass258 elif self.ends_with("ement"):259 pass260 elif self.ends_with("ment"):261 pass262 elif self.ends_with("ent"):263 pass264 else:265 return266 elif self.word[self.end - 1] == 'o':267 if self.ends_with("ion") and (self.word[self.offset] == 's' or self.word[self.offset] == 't'):268 pass269 elif self.ends_with("ou"):270 pass271 # takes care of -ous272 else:273 return274 elif self.word[self.end - 1] == 's':275 if self.ends_with("ism"):276 pass277 else:278 return279 elif self.word[self.end - 1] == 't':280 if self.ends_with("ate"):281 pass282 elif self.ends_with("iti"):283 pass284 else:285 return286 elif self.word[self.end - 1] == 'u':287 if self.ends_with("ous"):288 pass289 else:290 return291 elif self.word[self.end - 1] == 'v':292 if self.ends_with("ive"):293 pass294 else:295 return296 elif self.word[self.end - 1] == 'z':297 if self.ends_with("ize"):298 pass299 else:300 return301 else:302 return303 if self.m() > 1:304 self.end = self.offset305 def step5(self):306 """step5() removes a final -e if m() > 1, and changes -ll to -l if m > 1."""307 self.offset = self.end308 if self.word[self.end] == 'e':309 a = self.m()310 if a > 1 or (a == 1 and not self.is_of_form_cvc(self.end - 1)):311 self.end = self.end - 1...

Full Screen

Full Screen

porter_stemmer.py

Source:porter_stemmer.py Github

copy

Full Screen

...79 ch = self.word[i]80 if ch == 'w' or ch == 'x' or ch == 'y':81 return 082 return 183 def ends_with(self, s):84 """:returns TRUE when {start...end} ends with the string s."""85 length = len(s)86 if s[length - 1] != self.word[self.end]: # tiny speed-up87 return False88 if length > (self.end - self.start + 1):89 return False90 if self.word[self.end - length + 1: self.end + 1] != s:91 return False92 self.offset = self.end - length93 return True94 def set_to(self, s):95 """sets [offset + 1, end] to the characters in the string s, readjusting end."""96 length = len(s)97 self.word = self.word[:self.offset + 1] + s + self.word[self.offset + length + 1:]98 self.end = self.offset + length99 def replace_morpheme(self, s):100 """is a mapping function to change morphemes"""101 if self.m() > 0:102 self.set_to(s)103 def remove_plurals(self):104 """This is step 1 ab and gets rid of plurals and -ed or -ing. e.g.105 caresses -> caress106 ponies -> poni107 ties -> ti108 caress -> caress109 cats -> cat110 feed -> feed111 agreed -> agree112 disabled -> disable113 matting -> mat114 mating -> mate115 meeting -> meet116 milling -> mill117 messing -> mess118 meetings -> meet119 """120 if self.word[self.end] == 's':121 if self.ends_with("sses"):122 self.end = self.end - 2123 elif self.ends_with("ies"):124 self.set_to("i")125 elif self.word[self.end - 1] != 's':126 self.end = self.end - 1127 if self.ends_with("eed"):128 if self.m() > 0:129 self.end = self.end - 1130 elif (self.ends_with("ed") or self.ends_with("ing")) and self.contains_vowel():131 self.end = self.offset132 if self.ends_with("at"):133 self.set_to("ate")134 elif self.ends_with("bl"):135 self.set_to("ble")136 elif self.ends_with("iz"):137 self.set_to("ize")138 elif self.contains_double_consonant(self.end):139 self.end = self.end - 1140 ch = self.word[self.end]141 if ch == 'l' or ch == 's' or ch == 'z':142 self.end = self.end + 1143 elif self.m() == 1 and self.is_of_form_cvc(self.end):144 self.set_to("e")145 def terminal_y_to_i(self):146 """This defines step 1 c which turns terminal y to i when there is another vowel in the stem."""147 if self.ends_with('y') and self.contains_vowel():148 self.word = self.word[:self.end] + 'i' + self.word[self.end + 1:]149 def map_double_to_single_suffix(self):150 """Defines step 2 and maps double suffices to single ones.151 so -ization ( = -ize plus -ation) maps to -ize etc. note that the152 string before the suffix must give m() > 0.153 """154 if self.word[self.end - 1] == 'a':155 if self.ends_with("ational"):156 self.replace_morpheme("ate")157 elif self.ends_with("tional"):158 self.replace_morpheme("tion")159 elif self.word[self.end - 1] == 'c':160 if self.ends_with("enci"):161 self.replace_morpheme("ence")162 elif self.ends_with("anci"):163 self.replace_morpheme("ance")164 elif self.word[self.end - 1] == 'e':165 if self.ends_with("izer"): self.replace_morpheme("ize")166 elif self.word[self.end - 1] == 'l':167 if self.ends_with("bli"):168 self.replace_morpheme("ble") # --DEPARTURE--169 # To match the published algorithm, replace this phrase with170 # if self.ends("abli"): self.r("able")171 elif self.ends_with("alli"):172 self.replace_morpheme("al")173 elif self.ends_with("entli"):174 self.replace_morpheme("ent")175 elif self.ends_with("eli"):176 self.replace_morpheme("e")177 elif self.ends_with("ousli"):178 self.replace_morpheme("ous")179 elif self.word[self.end - 1] == 'o':180 if self.ends_with("ization"):181 self.replace_morpheme("ize")182 elif self.ends_with("ation"):183 self.replace_morpheme("ate")184 elif self.ends_with("ator"):185 self.replace_morpheme("ate")186 elif self.word[self.end - 1] == 's':187 if self.ends_with("alism"):188 self.replace_morpheme("al")189 elif self.ends_with("iveness"):190 self.replace_morpheme("ive")191 elif self.ends_with("fulness"):192 self.replace_morpheme("ful")193 elif self.ends_with("ousness"):194 self.replace_morpheme("ous")195 elif self.word[self.end - 1] == 't':196 if self.ends_with("aliti"):197 self.replace_morpheme("al")198 elif self.ends_with("iviti"):199 self.replace_morpheme("ive")200 elif self.ends_with("biliti"):201 self.replace_morpheme("ble")202 elif self.word[self.end - 1] == 'g':203 if self.ends_with("logi"): self.replace_morpheme("log")204 def step3(self):205 """step3() deals with -ic-, -full, -ness etc."""206 if self.word[self.end] == 'e':207 if self.ends_with("icate"):208 self.replace_morpheme("ic")209 elif self.ends_with("ative"):210 self.replace_morpheme("")211 elif self.ends_with("alize"):212 self.replace_morpheme("al")213 elif self.word[self.end] == 'i':214 if self.ends_with("iciti"): self.replace_morpheme("ic")215 elif self.word[self.end] == 'l':216 if self.ends_with("ical"):217 self.replace_morpheme("ic")218 elif self.ends_with("ful"):219 self.replace_morpheme("")220 elif self.word[self.end] == 's':221 if self.ends_with("ness"): self.replace_morpheme("")222 def step4(self):223 """step4() takes off -ant, -ence etc., in context <c>vcvc<v>."""224 if self.word[self.end - 1] == 'a':225 if self.ends_with("al"):226 pass227 else:228 return229 elif self.word[self.end - 1] == 'c':230 if self.ends_with("ance"):231 pass232 elif self.ends_with("ence"):233 pass234 else:235 return236 elif self.word[self.end - 1] == 'e':237 if self.ends_with("er"):238 pass239 else:240 return241 elif self.word[self.end - 1] == 'i':242 if self.ends_with("ic"):243 pass244 else:245 return246 elif self.word[self.end - 1] == 'l':247 if self.ends_with("able"):248 pass249 elif self.ends_with("ible"):250 pass251 else:252 return253 elif self.word[self.end - 1] == 'n':254 if self.ends_with("ant"):255 pass256 elif self.ends_with("ement"):257 pass258 elif self.ends_with("ment"):259 pass260 elif self.ends_with("ent"):261 pass262 else:263 return264 elif self.word[self.end - 1] == 'o':265 if self.ends_with("ion") and (self.word[self.offset] == 's' or self.word[self.offset] == 't'):266 pass267 elif self.ends_with("ou"):268 pass269 # takes care of -ous270 else:271 return272 elif self.word[self.end - 1] == 's':273 if self.ends_with("ism"):274 pass275 else:276 return277 elif self.word[self.end - 1] == 't':278 if self.ends_with("ate"):279 pass280 elif self.ends_with("iti"):281 pass282 else:283 return284 elif self.word[self.end - 1] == 'u':285 if self.ends_with("ous"):286 pass287 else:288 return289 elif self.word[self.end - 1] == 'v':290 if self.ends_with("ive"):291 pass292 else:293 return294 elif self.word[self.end - 1] == 'z':295 if self.ends_with("ize"):296 pass297 else:298 return299 else:300 return301 if self.m() > 1:302 self.end = self.offset303 def step5(self):304 """step5() removes a final -e if m() > 1, and changes -ll to -l if m > 1."""305 self.offset = self.end306 if self.word[self.end] == 'e':307 a = self.m()308 if a > 1 or (a == 1 and not self.is_of_form_cvc(self.end - 1)):309 self.end = self.end - 1...

Full Screen

Full Screen

features.py

Source:features.py Github

copy

Full Screen

...19 return helper.followed_by(['am','is','was','are','will','were','become','becomes','became','seem','seems','seemed'])(L, i)20def is_preceded_by_common_linking_verb(L, i):21 return helper.preceded_by(['am','is','was','are','will','were','become','becomes','became','seem','seems','seemed'])(L, i)22def ends_in_ly(L, i):23 return helper.ends_with("ly")(L, i)24def ends_in_able(L, i):25 return helper.ends_with("able")(L, i)26def ends_in_ible(L, i):27 return helper.ends_with("ible")(L, i)28def ends_in_al(L, i):29 return helper.ends_with("al")(L, i)30def ends_in_an(L, i):31 return helper.ends_with("an")(L, i)32def ends_in_ar(L, i):33 return helper.ends_with("ar")(L, i)34def ends_in_ent(L, i):35 return helper.ends_with("ent")(L, i)36def ends_in_ful(L, i):37 return helper.ends_with("ful")(L, i)38def ends_in_ic(L, i):39 return helper.ends_with("ic")(L, i)40def ends_in_ical(L, i):41 return helper.ends_with("ical")(L, i)42def ends_in_ine(L, i):43 return helper.ends_with("ine")(L, i)44def ends_in_ile(L, i):45 return helper.ends_with("ile")(L, i)46def ends_in_ive(L, i):47 return helper.ends_with("ive")(L, i)48def ends_in_less(L, i):49 return helper.ends_with("less")(L, i)50def ends_in_ous(L, i):51 return helper.ends_with("ous")(L, i)52def ends_in_some(L, i):53 return helper.ends_with("some")(L, i)54def ends_in_ing(L, i):55 return helper.ends_with("ing")(L, i)56def ends_in_ed(L, i):57 return helper.ends_with("ed")(L, i)58def is_adjective(L, i):59 adjectives = helper.make_set("word_lists/adjectives.txt")60 return L[i].lower() in adjectives61def is_pronouns(L, i):62 pronouns_mods = helper.make_set("word_lists/pronouns_mod.txt")63 return L[i].lower() in pronouns_mods64def is_verb(L, i):65 verbs_mod = helper.make_set("word_lists/verbs_mod.txt")66 return L[i].lower() in verbs_mod67def is_preposition(L, i):68 prepositions_mod = helper.make_set("word_lists/prepositions_mod.txt")69 return L[i].lower() in prepositions_mod70def is_noun(L, i):71 nouns_mod = helper.make_set("word_lists/nouns_mod.txt")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful