コード例 #1
0
ファイル: cmdln.py プロジェクト: maxwu/cldict
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'])
コード例 #2
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
    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'你好 (世界)')
コード例 #3
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
    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'你好 (世界)')
コード例 #4
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
    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'雙"引"號')
コード例 #5
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
    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'雙"引"號')
コード例 #6
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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(世界)')
コード例 #7
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 지는')
コード例 #8
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 ちょ')
コード例 #9
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 正传')
コード例 #10
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 ちょ')
コード例 #11
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 正傳')
コード例 #12
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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'")
コード例 #13
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 def test_double_quotes(self):
     self.assertEqual(bisheng.add_spaces(u'"hello"世界'), u'"hello" 世界')
     self.assertEqual(bisheng.add_spaces(u'hello"世界"'), u'hello"世界"')
コード例 #14
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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(世界)')
コード例 #15
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 지는')
コード例 #16
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 def test_double_quotes(self):
     self.assertEqual(bisheng.add_spaces(u'"hello"世界'), u'"hello" 世界')
     self.assertEqual(bisheng.add_spaces(u'hello"世界"'), u'hello"世界"')
コード例 #17
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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'")
コード例 #18
0
ファイル: test_api.py プロジェクト: imicky/bisheng
 def test_simple_cases(self):
     self.assertEqual(bisheng.add_spaces(u'測試test'), u'測試 test')
コード例 #19
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 正傳')
コード例 #20
0
ファイル: test_bisheng.py プロジェクト: eliangcs/bisheng
 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 正传')