5 from dc_crawler
import LangDetector
11 config = ConfigParser.ConfigParser()
12 config.add_section(LangDetector.CONFIG_SECTION)
13 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECTOR, LangDetector.DETECTOR_GUESS_LANGUAGE)
14 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECT_MAX_LENGTH,
"1000")
15 LangDetector.init(config)
16 self.assertEqual(LangDetector.detect(
u"hello, how old are you, between options"), [
"en"])
17 self.assertEqual(LangDetector.detect(
u"要订餐,上饿了么,现已加入肯德基豪华午餐,学挖掘机那家强"),[
"zh"])
18 self.assertEqual(LangDetector.detect(
u"中国の上海で行われたフィギュアスケート"), [
"ja"])
19 self.assertEqual(LangDetector.detect(
u"の人気特急に体験乗車,戦前から戦後にかけて親しまれた京阪電鉄の特急電車"), [
"ja"])
22 config = ConfigParser.ConfigParser()
23 config.add_section(LangDetector.CONFIG_SECTION)
24 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECTOR, LangDetector.DETECTOR_LANGID)
25 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECT_MAX_LENGTH,
"1000")
26 LangDetector.init(config)
27 self.assertEqual(LangDetector.detect(
u"hello, how old are you, between options"), [
"en"])
28 self.assertEqual(LangDetector.detect(
u"要订餐,上饿了么,现已加入肯德基豪华午餐,学挖掘机那家强"),[
"zh"])
29 self.assertEqual(LangDetector.detect(
u"中国の上海で行われたフィギュアスケート"), [
"ja"])
30 self.assertEqual(LangDetector.detect(
u"の人気特急に体験乗車,戦前から戦後にかけて親しまれた京阪電鉄の特急電車"), [
"ja"])
33 config = ConfigParser.ConfigParser()
34 config.add_section(LangDetector.CONFIG_SECTION)
35 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECTOR, LangDetector.DETECTOR_DETECTLANGUAGE)
36 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECT_MAX_LENGTH,
"1000")
37 config.set(LangDetector.CONFIG_SECTION, LangDetector.CONFIG_DETECTLANGUAGE_APIKEYS,
"a31d934a633d86cfe5a401340d98fb52")
38 LangDetector.init(config)
39 self.assertEqual(LangDetector.detect(
u"hello, how old are you, between options"), [
"en"])
40 self.assertEqual(LangDetector.detect(
u"要订餐,上饿了么,现已加入肯德基豪华午餐,学挖掘机那家强"),[
"zh"])
41 self.assertEqual(LangDetector.detect(
u"中国の上海で行われたフィギュアスケート"), [
"ja"])
42 self.assertEqual(LangDetector.detect(
u"往年の人気特急に体験乗車"), [
"ja"])
43 self.assertEqual(set(LangDetector.detect(
u'''学挖掘机那家强,山东济南找蓝翔 44 You might end up using just a few of them, but the rest will still be there for when you need them'''))
48 if __name__ ==
'__main__':
def testDetectLanguage(self)
def testGuessLanguage(self)