Ejemplo n.º 1
0
    def test_getSchema(self):
        ps = ProjectSetting()
        ps.parseFromFile(self.settingFile)
        self.assertRaisesRegexp(Exception, "Get schema 'Temp' error",
                                ps.getSchema, "Temp")
        schema = ps.getSchema("Temporal")
        self.assertEqual(schema.name, "Temporal")

        schema2 = ps.getSchema("Thyme2v1")
        self.assertEqual(schema2.name, "Thyme2v1")
        self.assertListEqual(sorted(schema2.modes),
                             sorted(["Anatomy", "Correction", "Coreference"]))
        for tModeName in schema2.modes:
            tMode = ps.getMode("Thyme2v1", tModeName)
            print(
                tMode, tMode.needPreannotation, tMode.preannotationFromMode
            )  #, None if tMode.preannotationFromMode is None else tMode.preannotationFromMode.name)
Ejemplo n.º 2
0
    def test_parseFromFile(self):
        fakeSettingFile = os.path.join(settings.ANAFORA_PROJECT_FILE_ROOT,
                                       "qq.xml")
        ps = ProjectSetting()
        self.assertRaisesRegexp(
            ImproperlyConfigured,
            "Can not find setting file '%s', please check your setting of ``ANAFORA_PROJECT_FILE_ROOT'' and ``ANAFORA_PROJECT_SETTING_FILENAME'' in your setting file"
            % fakeSettingFile, ps.parseFromFile, fakeSettingFile)

        ps = ProjectSetting()
        ps.parseFromFile(
            os.path.join(settings.ANAFORA_PROJECT_FILE_ROOT,
                         settings.ANAFORA_PROJECT_SETTING_FILENAME))
        self.assertEqual(len(ps.projectList), 9)
        self.assertListEqual(
            sorted([
                "Demo", "EventWorkshop", "Temporal", "CrossDocument", "EPIC",
                "SHARP", 'TempEval-2013-Train', "THYME-subevent",
                "THYMEColonFinal"
            ]), sorted([str(projName) for projName in ps.projectList.keys()]))
        self.assertListEqual(
            sorted([
                "Temporal", "UMLS", "Coreference", "PropBank", "Medicine",
                "BLT", "BLT-alt", "THYME_QA", "TimeNorm", "Thyme2v1"
            ]), sorted(ps.schemaList.keys()))
        project0 = ps.projectList["EventWorkshop"]
        self.assertEqual(project0.name, "EventWorkshop")
        self.assertListEqual(project0.admins, ["anaforaadmin"])
        self.assertEqual(len(project0.allowedSchemas), 4)
        self.assertTrue(
            reduce(lambda x, y: x and y, [
                isinstance(schema, Schema)
                for schema in project0.allowedSchemas
            ]))
        self.assertEqual(project0.numOfAnnotator, 2)
        self.assertListEqual(project0.annotators,
                             ["temporal", "verbs", "sharp"])
        schema0 = ps.getSchema("Temporal")
        self.assertEqual(schema0.name, "Temporal")
        self.assertEqual(len(schema0.modes), 3)
        mode0_0 = schema0.getMode("Entity")
        self.assertEqual(mode0_0.name, "Entity")
        self.assertEqual(mode0_0.needPreannotation, False)
        self.assertEqual(mode0_0.preannotationFromMode, None)
        self.assertEqual(mode0_0.directSetGold, False)
        mode0_1 = schema0.getMode("Relation")
        self.assertEqual(mode0_1.name, "Relation")
        self.assertEqual(mode0_1.needPreannotation, True)
        self.assertTrue(isinstance(mode0_1.preannotationFromMode, Mode))
        self.assertEqual(mode0_1.preannotationFromMode.name, "Entity")
        self.assertEqual(mode0_1.directSetGold, False)
        mode0_2 = schema0.getMode("RelationReGold")
        self.assertEqual(mode0_2.name, "RelationReGold")
        self.assertEqual(mode0_2.needPreannotation, True)
        self.assertTrue(isinstance(mode0_2.preannotationFromMode, Mode))
        self.assertEqual(mode0_2.preannotationFromMode.name, "Relation")
        self.assertEqual(mode0_2.directSetGold, True)