def main_func(): if len(sys.argv) < 2: if '.py' in sys.argv[0]: print 'Usage: python %s PHRASE' % sys.argv[0] else: print 'Usage: cldict PHRASE' print 'Look up the PHRASE from online dictionary' return phrase = ' '.join(sys.argv[1:]) info = look_up(phrase) if not info or ('phrase' in info and not info['phrase']): print 'No result found.' return if 'phrase' in info: print info['phrase'], if 'phonetic' in info: print info['phonetic'] else: print if 'explanation' in info: print add_spaces(info['explanation']) if 'transform' in info: print add_spaces(info['transform'])
def test_halfwidth_punctuation(self): self.assertEqual(bisheng.add_spaces(u'hello,世界'), u'hello, 世界') self.assertEqual(bisheng.add_spaces(u'hello.世界'), u'hello. 世界') self.assertEqual(bisheng.add_spaces(u'hello!世界'), u'hello! 世界') self.assertEqual(bisheng.add_spaces(u'hello[世界]'), u'hello[世界]') self.assertEqual(bisheng.add_spaces(u'hello(世界)'), u'hello(世界)') self.assertEqual(bisheng.add_spaces(u'你好,世界'), u'你好, 世界') self.assertEqual(bisheng.add_spaces(u'你好.世界'), u'你好. 世界') self.assertEqual(bisheng.add_spaces(u'你好!世界'), u'你好! 世界') self.assertEqual(bisheng.add_spaces(u'你好[世界]'), u'你好 [世界]') self.assertEqual(bisheng.add_spaces(u'你好(世界)'), u'你好 (世界)')
def test_exclude(self): self.assertEqual(bisheng.add_spaces(u'方[括]孤'), u'方 [括] 孤') self.assertEqual(bisheng.add_spaces(u'方[括]孤', exclude='['), u'方[括] 孤') self.assertEqual(bisheng.add_spaces(u'方[括]孤', exclude='[]'), u'方[括]孤') self.assertEqual(bisheng.add_spaces(u'圓(括)孤方[括]孤'), u'圓 (括) 孤方 [括] 孤') self.assertEqual(bisheng.add_spaces(u'圓(括)孤方[括]孤', exclude='[)'), u'圓 (括)孤方[括] 孤') self.assertEqual(bisheng.add_spaces(u'圓(括)孤方[括]孤', exclude='[]()'), u'圓(括)孤方[括]孤') self.assertEqual(bisheng.add_spaces(u'雙"引"號'), u'雙 "引" 號') self.assertEqual(bisheng.add_spaces(u'雙"引"號', exclude='"'), u'雙"引"號')
def test_fullwidth_punctuation(self): self.assertEqual(bisheng.add_spaces(u'hello,世界'), u'hello,世界') self.assertEqual(bisheng.add_spaces(u'hello。世界'), u'hello。世界') self.assertEqual(bisheng.add_spaces(u'hello!世界'), u'hello!世界') self.assertEqual(bisheng.add_spaces(u'hello「世界」'), u'hello「世界」') self.assertEqual(bisheng.add_spaces(u'hello(世界)'), u'hello(世界)')
def test_korean(self): self.assertEqual(bisheng.add_spaces(u'듯하더니test'), u'듯하더니 test') self.assertEqual(bisheng.add_spaces(u'Hello바라보느냐'), u'Hello 바라보느냐') self.assertEqual(bisheng.add_spaces(u'김첨Q지는'), u'김첨 Q 지는')
def test_japanese(self): self.assertEqual(bisheng.add_spaces(u'樊隊じょtest'), u'樊隊じょ test') self.assertEqual(bisheng.add_spaces(u'Helloブケひゃ'), u'Hello ブケひゃ') self.assertEqual(bisheng.add_spaces(u'ブケひゃQちょ'), u'ブケひゃ Q ちょ')
def test_simp_chinese(self): self.assertEqual(bisheng.add_spaces(u'测试test'), u'测试 test') self.assertEqual(bisheng.add_spaces(u'Hello世界'), u'Hello 世界') self.assertEqual(bisheng.add_spaces(u'阿Q正传'), u'阿 Q 正传')
def test_trad_chinese(self): self.assertEqual(bisheng.add_spaces(u'測試test'), u'測試 test') self.assertEqual(bisheng.add_spaces(u'Hello世界'), u'Hello 世界') self.assertEqual(bisheng.add_spaces(u'阿Q正傳'), u'阿 Q 正傳')
def test_single_quotes(self): self.assertEqual(bisheng.add_spaces(u"'hello'世界"), u"'hello' 世界") self.assertEqual(bisheng.add_spaces(u"hello'世界'"), u"hello'世界'") self.assertEqual(bisheng.add_spaces(u"你好'世界'"), u"你好 '世界'") self.assertEqual(bisheng.add_spaces(u"'hello'world'"), u"'hello'world'")
def test_double_quotes(self): self.assertEqual(bisheng.add_spaces(u'"hello"世界'), u'"hello" 世界') self.assertEqual(bisheng.add_spaces(u'hello"世界"'), u'hello"世界"')
def test_simple_cases(self): self.assertEqual(bisheng.add_spaces(u'測試test'), u'測試 test')