Best Python code snippet using assertpy_python
iwnlp_wrapper.py
Source: iwnlp_wrapper.py
...26 if key in self.lemmatizer:27 wrong_entry = {"POS": pos, "Form": form, "Lemma": lemma}28 if wrong_entry in self.lemmatizer[key]:29 self.lemmatizer[key].remove(wrong_entry)30 def contains_entry(self, word, pos=None, ignore_case=False):31 key = word.lower().strip()32 if not pos:33 if ignore_case:34 return key in self.lemmatizer35 else:36 return key in self.lemmatizer and any(filter(lambda x: x["Form"] == word, self.lemmatizer[key]))37 elif not isinstance(pos, list):38 if ignore_case:39 return key in self.lemmatizer and any(filter(lambda x: x["POS"] == pos, self.lemmatizer[key]))40 else:41 return key in self.lemmatizer and any(42 filter(lambda x: x["POS"] == pos and x["Form"] == word, self.lemmatizer[key]))43 else:44 for pos_entry in pos:45 if self.contains_entry(word, pos_entry, ignore_case):46 return True47 return False48 def get_entries(self, word, pos=None, ignore_case=False):49 entries = []50 key = word.lower().strip()51 if not pos:52 if ignore_case:53 entries = self.lemmatizer[key]54 else:55 entries = list(filter(lambda x: x["Form"] == word, self.lemmatizer[key]))56 elif not isinstance(pos, list):57 if ignore_case:58 entries = list(filter(lambda x: x["POS"] == pos, self.lemmatizer[key]))59 else:60 entries = list(filter(lambda x: x["POS"] == pos and x["Form"] == word, self.lemmatizer[key]))61 else:62 for pos_entry in pos:63 if self.contains_entry(word, pos=pos_entry, ignore_case=ignore_case):64 entries.extend(self.get_entries(word, pos_entry, ignore_case))65 return entries66 def get_lemmas(self, word, pos=None, ignore_case=False):67 """68 Return all lemmas for a given word. This method assumes that the specified word is present in the dictionary69 :param word: Word that is present in the IWNLP lemmatizer70 """71 entries = self.get_entries(word, pos, ignore_case)72 lemmas = list(set([entry["Lemma"] for entry in entries]))73 return sorted(lemmas)74 def lemmatize_plain(self, word, ignore_case=False):75 if self.contains_entry(word, ignore_case=ignore_case):76 return self.get_lemmas(word, ignore_case=ignore_case)77 else:78 return None79 def lemmatize(self, word, pos_universal_google):80 """81 Python port of the lemmatize method, see https://github.com/Liebeck/IWNLP.Lemmatizer/blob/master/IWNLP.Lemmatizer.Predictor/IWNLPSentenceProcessor.cs82 """83 if pos_universal_google == "NOUN":84 if self.contains_entry(word, "Noun"):85 return self.get_lemmas(word, "Noun")86 elif self.contains_entry(word, "X"):87 return self.get_lemmas(word, "X")88 elif self.contains_entry(word, "AdjectivalDeclension"):89 return self.get_lemmas(word, "AdjectivalDeclension")90 elif self.contains_entry(word, ["Noun", "X"], ignore_case=True):91 return self.get_lemmas(word, ["Noun", "X"], ignore_case=True)92 else:93 return None94 elif pos_universal_google == "ADJ":95 if self.contains_entry(word, "Adjective"):96 return self.get_lemmas(word, "Adjective")97 elif self.contains_entry(word, "Adjective", ignore_case=True):98 return self.get_lemmas(word, "Adjective", ignore_case=True)99 # Account for possible errors in the POS tagger. This order was fine-tuned in terms of accuracy100 elif self.contains_entry(word, "Noun", ignore_case=True):101 return self.get_lemmas(word, "Noun", ignore_case=True)102 elif self.contains_entry(word, "X", ignore_case=True):103 return self.get_lemmas(word, "X", ignore_case=True)104 elif self.contains_entry(word, "Verb", ignore_case=True):105 return self.get_lemmas(word, "Verb", ignore_case=True)106 else:107 return None108 elif pos_universal_google in ["VERB", "AUX"]:109 if self.contains_entry(word, "Verb", ignore_case=True):110 return self.get_lemmas(word, "Verb", ignore_case=True)111 else:112 return None113 else:...
customIWNLPLemmatizer.py
Source: customIWNLPLemmatizer.py
...17 if key in self.lemmatizer:18 wrong_entry = {"POS": pos, "Form": form, "Lemma": lemma}19 if wrong_entry in self.lemmatizer[key]:20 self.lemmatizer[key].remove(wrong_entry)21 def contains_entry(self, word, pos=None, ignore_case=False):22 key = word.lower().strip()23 if not pos:24 if ignore_case:25 return key in self.lemmatizer26 else:27 return key in self.lemmatizer and any(filter(lambda x: x["Form"] == word, self.lemmatizer[key]))28 elif not isinstance(pos, list):29 if ignore_case:30 return key in self.lemmatizer and any(filter(lambda x: x["POS"] == pos, self.lemmatizer[key]))31 else:32 return key in self.lemmatizer and any(33 filter(lambda x: x["POS"] == pos and x["Form"] == word, self.lemmatizer[key]))34 else:35 for pos_entry in pos:36 if self.contains_entry(word, pos_entry, ignore_case):37 return True38 return False39 def get_entries(self, word, pos=None, ignore_case=False):40 entries = []41 key = word.lower().strip()42 if not pos:43 if ignore_case:44 entries = self.lemmatizer[key]45 else:46 entries = list(filter(lambda x: x["Form"] == word, self.lemmatizer[key]))47 elif not isinstance(pos, list):48 if ignore_case:49 entries = list(filter(lambda x: x["POS"] == pos, self.lemmatizer[key]))50 else:51 entries = list(filter(lambda x: x["POS"] == pos and x["Form"] == word, self.lemmatizer[key]))52 else:53 for pos_entry in pos:54 if self.contains_entry(word, pos=pos_entry, ignore_case=ignore_case):55 entries.extend(self.get_entries(word, pos_entry, ignore_case))56 return entries57 def get_lemmas(self, word, pos=None, ignore_case=False):58 """59 Return all lemmas for a given word. This method assumes that the specified word is present in the dictionary60 :param word: Word that is present in the IWNLP lemmatizer61 """62 entries = self.get_entries(word, pos, ignore_case)63 lemmas = list(set([entry["Lemma"] for entry in entries]))64 return sorted(lemmas)65 def lemmatize_plain(self, word, ignore_case=False):66 if self.contains_entry(word, ignore_case=ignore_case):67 return self.get_lemmas(word, ignore_case=ignore_case)68 else:69 return None70 def lemmatize(self, word, udPos):71 """72 Python port of the lemmatize method, see https://github.com/Liebeck/IWNLP.Lemmatizer/blob/master/IWNLP.Lemmatizer.Predictor/IWNLPSentenceProcessor.cs73 """74 # do not process empty strings75 if(not(word)):76 raise ValueError("Empty String!")77 # valid pos = N,V,ADJ,ADV78 elif(not(udPos in ["NOUN","VERB","ADJ","ADV","AUX"])):79 return word80 if udPos == 'NOUN':81 if len(word) > 1 and word[0].islower():82 word = word[0].upper() + word[1:]83 else:84 word = word.lower()85 if udPos == "NOUN":86 if self.contains_entry(word, "Noun"):87 return self.get_lemmas(word, "Noun")88 elif self.contains_entry(word, "X"):89 return self.get_lemmas(word, "X")90 elif self.contains_entry(word, "AdjectivalDeclension"):91 return self.get_lemmas(word, "AdjectivalDeclension")92 elif self.contains_entry(word, ["Noun", "X"], ignore_case=True):93 return self.get_lemmas(word, ["Noun", "X"], ignore_case=True)94 else:95 return None96 elif udPos in ["ADJ", "ADV"]:97 if self.contains_entry(word, "Adjective"):98 return self.get_lemmas(word, "Adjective")99 elif self.contains_entry(word, "Adjective", ignore_case=True):100 return self.get_lemmas(word, "Adjective", ignore_case=True)101 # Account for possible errors in the POS tagger. This order was fine-tuned in terms of accuracy102 elif self.contains_entry(word, "Noun", ignore_case=True):103 return self.get_lemmas(word, "Noun", ignore_case=True)104 elif self.contains_entry(word, "X", ignore_case=True):105 return self.get_lemmas(word, "X", ignore_case=True)106 elif self.contains_entry(word, "Verb", ignore_case=True):107 return self.get_lemmas(word, "Verb", ignore_case=True)108 else:109 return None110 elif udPos in ["VERB", "AUX"]:111 if self.contains_entry(word, "Verb", ignore_case=True):112 return self.get_lemmas(word, "Verb", ignore_case=True)113 else:114 return None115 else:...
test_iwnlp_wrapper.py
Source: test_iwnlp_wrapper.py
...28 def test_lemmatize_plain_example8(self):29 predicted = self.iwnlp.lemmatize_plain('ein')30 self.assertEqual(predicted, ['ein', 'einen'])31 def test_contains_entry_example1(self):32 self.assertEqual(self.iwnlp.contains_entry('Birne'), True)33 def test_contains_entry_example2(self):34 self.assertEqual(self.iwnlp.contains_entry('birne', ignore_case=False), False)35 def test_contains_entry_example3(self):36 self.assertEqual(self.iwnlp.contains_entry('birne', ignore_case=True), True)37 def test_contains_entry_example4(self):38 self.assertEqual(self.iwnlp.contains_entry('groko'), False)39 def test_contains_entry_example5(self):40 self.assertEqual(self.iwnlp.contains_entry('GroKo'), True)41 def test_contains_entry_example6(self):42 self.assertEqual(self.iwnlp.contains_entry('groko', ignore_case=True), True)43 def test_contains_entry_example7(self):44 self.assertEqual(self.iwnlp.contains_entry('groko', pos='Noun'), False)45 def test_contains_entry_example8(self):46 self.assertEqual(self.iwnlp.contains_entry('groko', pos='X'), False)47 def test_contains_entry_example9(self):48 self.assertEqual(self.iwnlp.contains_entry('groko', pos='AdjectivalDeclension'), False)49 def test_contains_entry_example10(self):50 self.assertEqual(self.iwnlp.contains_entry('groko', pos=["Noun", "X"], ignore_case=True), True)51 def test_lemmatize_example1(self):52 predicted = self.iwnlp.lemmatize('Lkws', pos_universal_google='NOUN')53 self.assertEqual(predicted, ['Lkw'])54 def test_lemmatize_example2(self):55 predicted = self.iwnlp.lemmatize('gespielt', pos_universal_google='VERB')56 self.assertEqual(predicted, ['spielen'])57 def test_get_lemmas_example1(self):58 predicted = self.iwnlp.get_lemmas('groko', pos=["Noun", "X"], ignore_case=True)...
Check out the latest blogs from LambdaTest on this topic:
In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.
Unit and functional testing are the prime ways of verifying the JavaScript code quality. However, a host of tools are available that can also check code before or during its execution in order to test its quality and adherence to coding standards. With each tool having its unique features and advantages contributing to its testing capabilities, you can use the tool that best suits your need for performing JavaScript testing.
Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.
Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!