示例#1
0
 def test_escaping(self):
     texts = [
         "Maradona",
         "El Diego",
         "El Diego ( el 10 )",
         "|()|",
         "æßðæßð",
         "\ hello \ ",
         "*",
     ]
     gm = GazetteManager()
     for text in texts:
         escaped = gm.escape_text(text)
         self.assertEqual(escaped.count("\Q"), len(text.split()))
         self.assertEqual(escaped.count("\E"), len(text.split()))
示例#2
0
 def test_escaping(self):
     texts = [
         "Maradona",
         "El Diego",
         "El Diego ( el 10 )",
         "|()|",
         "æßðæßð",
         "\ hello \ ",
         "*",
     ]
     gm = GazetteManager()
     for text in texts:
         escaped = gm.escape_text(text)
         self.assertEqual(escaped.count("\Q"), len(text.split()))
         self.assertEqual(escaped.count("\E"), len(text.split()))
示例#3
0
    def _test_single_gazette(self, text=None):
        if text:
            gazette_item = GazetteItemFactory(text=text)
        else:
            gazette_item = GazetteItemFactory()
        gzmanager = GazetteManager()
        filepath = gzmanager.generate_stanford_gazettes_file()
        self.assertNotEqual(filepath, None)
        data = open(filepath).read().split("\n")
        self.assertEqual(len(data), 2)
        data = data[0].split("\t")
        self.assertEqual(len(data), 3)

        self.assertEqual(data[0], gzmanager.escape_text(gazette_item.text))
        self.assertEqual(data[1], "{}{}".format(gzmanager._PREFIX, gazette_item.kind.name))
        gazette_item.delete()
示例#4
0
    def _test_single_gazette(self, text=None):
        if text:
            gazette_item = GazetteItemFactory(text=text)
        else:
            gazette_item = GazetteItemFactory()
        gzmanager = GazetteManager()
        filepath = gzmanager.generate_stanford_gazettes_file()
        self.assertNotEqual(filepath, None)
        data = open(filepath).read().split("\n")
        self.assertEqual(len(data), 2)
        data = data[0].split("\t")
        self.assertEqual(len(data), 3)

        self.assertEqual(data[0], gzmanager.escape_text(gazette_item.text))
        self.assertEqual(data[1], "{}{}".format(gzmanager._PREFIX, gazette_item.kind.name))
        gazette_item.delete()
示例#5
0
 def test_generate_gazettes_several_lines(self):
     [GazetteItemFactory() for x in range(10)]
     filepath = GazetteManager().generate_stanford_gazettes_file()
     self.assertNotEqual(filepath, None)
     data = open(filepath).read()
     self.assertEqual(data.count("\n"), 10)
     for line in data.split("\n")[:-1]:
         self.assertEqual(line.count("\t"), 2)
示例#6
0
 def test_generate_gazettes_file_empty(self):
     self.assertEqual(GazetteManager().generate_stanford_gazettes_file(), None)