def _testPhrase(self, language, phrase): assert Phrases.forLanguage(language).isPhrase( phrase), "phrase='%s' language=%s" % (phrase, language) number = Phrases.forLanguage(language).toNumber(phrase) detects = Phrases.detectLanguages(phrase) for lang2 in detects: number2 = Phrases.forLanguage(lang2).toNumber(phrase) phrase2 = Phrases.forLanguage(lang2).toPhrase(number) assert number == number2 assert phrase == phrase2
def number(self, phrase): phrase = Check.toString(phrase) phrases = self._getPhrases() if phrases.isPhrase(phrase): return phrases.toNumber(phrase) detects = Phrases.detectLanguages(phrase) if len(detects) > 0: return Phrases.forLanguage(detects.pop()).toNumber(phrase) raise ValueError("unknown phrase language")