Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def test_getSchemaFileNameFromSchemaAndMode(self):
        ps = ProjectSetting()
        ps.parseFromFile(self.settingFile)

        self.assertRaises(Exception, ps.getSchemaFileNameFromSchemaAndMode,
                          "Temp")
        (fileName, needMoreSchema) = ps.getSchemaFileNameFromSchemaAndMode(
            "Temporal", modeName="Entity")
        self.assertEqual(fileName, "temporal-schema.xml")
        self.assertEqual(needMoreSchema, False)
        self.assertRaisesRegexp(
            Exception,
            "The schema 'Temporal' with mode name 'Entity' of file index 1 is more than the size of schema files",
            ps.getSchemaFileNameFromSchemaAndMode, "Temporal", 1, "Entity")

        (fileName,
         needMoreSchema) = ps.getSchemaFileNameFromSchemaAndMode("BLT")
        self.assertEqual(fileName, "blt-schema.xml")
        self.assertEqual(needMoreSchema, True)
        (fileName, needMoreSchema) = ps.getSchemaFileNameFromSchemaAndMode(
            "BLT", schemaFileIdx=1)
        self.assertEqual(fileName, "med-schema.xml")
        self.assertEqual(needMoreSchema, True)
        (fileName, needMoreSchema) = ps.getSchemaFileNameFromSchemaAndMode(
            "BLT", schemaFileIdx=2)
        self.assertEqual(fileName, "thyme-qa-schema.xml")
        self.assertEqual(needMoreSchema, False)
        self.assertRaisesRegexp(
            Exception,
            "The schema 'BLT' of file index 3 is more than the size of schema files",
            ps.getSchemaFileNameFromSchemaAndMode, "BLT", 3)
Ejemplo n.º 3
0
    def test_getMode(self):
        ps = ProjectSetting()
        ps.parseFromFile(self.settingFile)
        self.assertRaisesRegexp(Exception, "Get schema 'Temporal' error",
                                ps.getMode, "Temporal")
        self.assertRaisesRegexp(
            Exception,
            "Get schema 'Temporal' with mode name 'FakeEntity' error",
            ps.getMode, "Temporal", "FakeEntity")
        mode0 = ps.getMode("Temporal", "Entity")
        self.assertTrue(isinstance(mode0, Mode))
        self.assertEqual(mode0.name, "Entity")

        self.assertRaisesRegexp(Exception, "Get schema 'FakeTemporal' error",
                                ps.getMode, "FakeTemporal")
        self.assertRaisesRegexp(Exception, "Get schema 'FakeTemporal' error",
                                ps.getMode, "FakeTemporal", None)

        self.assertRaisesRegexp(
            Exception, "Get schema 'PropBank' with mode name 'fakeMode' error",
            ps.getMode, "PropBank", "fakeMode")

        mode1 = ps.getMode("PropBank")
        self.assertTrue(isinstance(mode1, Mode))
        self.assertEqual(mode1.name, None)
Ejemplo n.º 4
0
    def test_isSchemaExist(self):
        ps = ProjectSetting()
        ps.parseFromFile(self.settingFile)

        self.assertTrue(ps.isSchemaExist("Temporal", "Entity"))
        self.assertFalse(ps.isSchemaExist("Temporal"))
        self.assertTrue(ps.isSchemaExist("Coreference"))
        self.assertFalse(ps.isSchemaExist("Coreference", "Entity"))
Ejemplo n.º 5
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.º 6
0
    def test_getSchemaMap(self):
        ps = ProjectSetting()
        ps.parseFromFile(self.settingFile)

        schemaMap = ps.getSchemaMap()
        self.assertListEqual(
            sorted([
                "Temporal", "UMLS", "Coreference", "PropBank", "Medicine",
                "BLT", "BLT-alt", "THYME_QA", "TimeNorm", "Thyme2v1"
            ]), sorted(schemaMap.keys()))
        self.assertListEqual(sorted(["Entity", "Relation", "RelationReGold"]),
                             sorted(schemaMap["Temporal"]))
        self.assertListEqual(sorted(["Entity", "Relation"]),
                             sorted(schemaMap["UMLS"]))
        self.assertEqual(0, schemaMap["Coreference"])
        self.assertEqual(0, schemaMap["PropBank"])
        self.assertEqual(0, schemaMap["Medicine"])
        self.assertEqual(0, schemaMap["BLT"])
        self.assertEqual(0, schemaMap["BLT-alt"])
        self.assertEqual(0, schemaMap["THYME_QA"])
        self.assertEqual(0, schemaMap["TimeNorm"])
        self.assertListEqual(sorted(["Coreference", "Correction", "Anatomy"]),
                             sorted(schemaMap["Thyme2v1"]))
 def setUp(self):
     self.ps = ProjectSetting()
     self.ps.parseFromFile(
         os.path.join(settings.ANAFORA_PROJECT_FILE_ROOT,
                      settings.ANAFORA_PROJECT_SETTING_FILENAME))