def test_removeText(self): p = Punctuation() for key, value in self.remove_text.items(): result = p.removeVerbalized(key) == value if not result: print key, '|', p.removeVerbalized(key), '|', value self.assertTrue(result)
def test_removeText(self): p = Punctuation() for key, value in list(self.remove_text.items()): result = p.removeVerbalized(key) == value if not result: print((key, '|', p.removeVerbalized(key), '|', value)) self.assertTrue(result)
def test_replaceText(self): p = Punctuation() # all dictionary is replaced correctly for key in self.replace_text : result = p.replaceText(key) == self.replace_text[key].strip() if not result : print key, '|', p.replaceText(key), '|', self.replace_text[key].strip() self.assertTrue(result)
def test_countPresenceText(self): p = Punctuation() # all the dictionary is detected at least once for key in self.presence_text : result = len(p.countPresenceText(key)) == self.presence_text[key] if not result : print key, '|', p.countPresenceText(key), '|', self.presence_text[key] self.assertTrue(result)
def test_contructor(self): d = [ (r"\." , 1, u"a"), (r"-" , 1, u"b") ] r = [ (r"a" , 1, u"."), (r"b" , 1, u"-") ] p = Punctuation(d, r) res = p.replaceText(".-.-.-..--..--") self.assertEqual(res, "abababaabbaabb") res2 = p.symbolText(res) self.assertEqual(res2, u".-.-.-..--..--")
def test_contructor(self): d = [(r"\.", 1, "a"), (r"-", 1, "b")] r = [(r"a", 1, "."), (r"b", 1, "-")] p = Punctuation(d, r) res = p.replaceText(".-.-.-..--..--") self.assertEqual(res, "abababaabbaabb") res2 = p.symbolText(res) self.assertEqual(res2, ".-.-.-..--..--")
def verbalizeTextPunctuation(self): """Transform punctuation symbols to words. Currently only implemented for French. """ if self.isFrench(): p = Punctuation() self.setTextSentence(p.replaceText(self.getTextSentence())) else: raise Exception("Text verbalization is only implemented for French!")
def test_symbolText(self): p = Punctuation() inv_map = {v:k for k, v in self.replace_text.items()} for key in inv_map : test = " ".join(inv_map[key].split()) result = p.symbolText(key) == test if not result : print key, '|', p.symbolText(key), '|', test self.assertTrue(result)
def test_replaceText(self): p = Punctuation() # all dictionary is replaced correctly for key in self.replace_text: result = p.replaceText(key) == self.replace_text[key].strip() if not result: print((key, '|', p.replaceText(key), '|', self.replace_text[key].strip())) self.assertTrue(result)
def test_countPresenceText(self): p = Punctuation() # all the dictionary is detected at least once for key in self.presence_text: result = len(p.countPresenceText(key)) == self.presence_text[key] if not result: print((key, '|', p.countPresenceText(key), '|', self.presence_text[key])) self.assertTrue(result)
def test_symbolText(self): p = Punctuation() inv_map = {v: k for k, v in list(self.replace_text.items())} for key in inv_map: test = " ".join(inv_map[key].split()) result = p.symbolText(key) == test if not result: print((key, '|', p.symbolText(key), '|', test)) self.assertTrue(result)
def verbalizeTextPunctuation(self): """Transform punctuation symbols to words. Currently only implemented for French. """ if self.isFrench(): p = Punctuation() self.setTextSentence(p.replaceText(self.getTextSentence())) else: raise Exception( "Text verbalization is only implemented for French!")