예제 #1
0
    def test_reload(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._gender_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "gender.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.GENDER] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.GENDER] = storage_engine

        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.gender("WITH HIM"), 'with her')
        self.assertEqual(collection.genderise_string(None, "This is with him"),
                         "This is with her")

        collection.reload(storage_factory)

        self.assertEqual(collection.gender("WITH HIM"), 'with her')
        self.assertEqual(collection.genderise_string(None, "This is with him"),
                         "This is with her")
예제 #2
0
    def test_reload_jp(self):
        storage_factory = StorageFactory()
        tokenizer = TokenizerJP()

        file_store_config = FileStorageConfiguration()
        file_store_config._gender_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "gender_jp.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.GENDER] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.GENDER] = storage_engine

        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.gender("彼"), '彼女')
        self.assertEqual(collection.genderise_string(tokenizer, "彼が来た"),
                         "彼女が来た")

        collection.reload(storage_factory)

        self.assertEqual(collection.gender("彼"), '彼女')
        self.assertEqual(collection.genderise_string(tokenizer, "彼が来た"),
                         "彼女が来た")
예제 #3
0
    def test_collection(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        count = collection.load_from_text("""
                " with him "," with her "
                " with her "," with him "
                " to him "," to her "
                " to her "," to him "
                " on him "," on her "
                " on her "," on him "
                " in him "," in her "
                " in her "," in him "
                " for him "," for her "
                " for her "," for him "
                " he "," she "
                " his "," her "
                " him "," her "
                " her "," his "
                " she "," he "
        """)
        self.assertEqual(count, 15)

        self.assertEqual(collection.genderise_string("This is with him "),
                         "This is with her")

        self.assertEqual("(^with him | with him | with him$)",
                         collection.gender(" with him "))
        self.assertIsNone(collection.gender("unknown"))
예제 #4
0
    def assert_upload_from_text(self, store):

        store.empty()

        store.upload_from_text(
            None, """
                                " with him "," with her "
                                " with her "," with him "
                                " to him "," to her "
                                " to her "," to him "
                                " on him "," on her "
                                " on her "," on him "
                                " in him "," in her "
                                " in her "," in him "
                                " for him "," for her "
                                " for her "," for him "
                                " he "," she "
                                " his "," her "
                                " him "," her "
                                " her "," his "
                                " she "," he "
                                """)

        collection = GenderCollection()
        store.load(collection)

        self.assertEqual(collection.gender(" WITH HIM "), [
            re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE),
            ' WITH HER '
        ])
        self.assertEqual(collection.genderise_string("This is with him "),
                         "This is with her")
예제 #5
0
    def test_collection(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        count = collection.load_from_text("""
                " with him "," with her "
                " with her "," with him "
                " to him "," to her "
                " to her "," to him "
                " on him "," on her "
                " on her "," on him "
                " in him "," in her "
                " in her "," in him "
                " for him "," for her "
                " for her "," for him "
                " he "," she "
                " his "," her "
                " him "," her "
                " her "," his "
                " she "," he "
        """)
        self.assertEqual(count, 15)

        self.assertEqual(collection.genderise_string("This is with him "), "This is with her")

        #self.assertEqual("(^with him | with him | with him$)", collection.gender(" with him "))
        self.assertIsNone(collection.gender("unknown"))
예제 #6
0
    def test_collection_duplicate(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup("with him", 'with her')
        collection.add_to_lookup("with him", 'with you')

        self.assertEqual(collection.gender("WITH HIM"), 'with her')
예제 #7
0
    def test_collection_duplicate_jp(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup("彼", '彼女')
        collection.add_to_lookup("彼", '彼氏')

        self.assertEqual(collection.gender("彼"), '彼女')
예제 #8
0
    def assert_upload_csv_file(self, store, filename):

        store.empty()

        store.upload_from_file(filename, format=Store.CSV_FORMAT)

        collection = GenderCollection()
        store.load(collection)

        self.assertEqual(collection.gender(" WITH HIM "), [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])
        self.assertEqual(collection.genderise_string("This is with him "), "This is with her")
예제 #9
0
    def assert_upload_from_text_file(self, store):

        store.empty()

        store.upload_from_file(os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "gender.txt")

        collection = GenderCollection()
        store.load(collection)

        self.assertEqual(collection.gender(" WITH HIM "), [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])
        self.assertEqual(collection.genderise_string("This is with him "), "This is with her")
예제 #10
0
    def test_collection_operations(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup(" WITH HIM ", [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])

        self.assertTrue(collection.has_key(" WITH HIM "))
        self.assertEqual([re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '], collection.value(" WITH HIM "))

        self.assertEqual(collection.gender(" WITH HIM "), [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])
        self.assertEqual(collection.genderise_string("This is with him "), "This is with her")
예제 #11
0
    def test_collection_invalid(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup("with him", 'with her')

        self.assertFalse(collection.has_keyVal("WITH YOU"))
        self.assertIsNone(collection.value("WITH YOU"))

        self.assertIsNone(collection.gender("WITH YOU"))
        self.assertEqual(collection.genderise_string(None, "This is with you"),
                         "This is with you")
예제 #12
0
    def test_collection_operations(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup("with him", 'with her')

        self.assertTrue(collection.has_keyVal("WITH HIM"))
        self.assertEqual('with her', collection.value("WITH HIM"))

        self.assertEqual(collection.gender("WITH HIM"), 'with her')
        self.assertEqual(collection.genderise_string(None, "This is with him"),
                         "This is with her")
예제 #13
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._gender_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "gender.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileGenderStore(engine)

        gender_collection = GenderCollection()
        
        store.load(gender_collection)

        self.assertEqual(gender_collection.gender(" WITH HIM "), [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])
        self.assertEqual(gender_collection.genderise_string("This is with him "), "This is with her")
예제 #14
0
    def test_collection_invalid_JP(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup("彼", '彼女')

        self.assertFalse(collection.has_keyVal("彼氏"))
        self.assertIsNone(collection.value("彼氏"))

        tokenizer = TokenizerJP()
        self.assertIsNone(collection.gender("彼氏"))
        self.assertEqual(collection.genderise_string(tokenizer, "彼氏が来た"),
                         "彼氏が来た")
예제 #15
0
    def test_collection_operations_JP(self):
        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.add_to_lookup("彼", '彼女')
        tokenizer = TokenizerJP()

        self.assertTrue(collection.has_keyVal("彼"))
        self.assertEqual('彼女', collection.value("彼"))

        self.assertEqual(collection.gender("彼"), '彼女')
        self.assertEqual(collection.genderise_string(tokenizer, "彼が来た"),
                         "彼女が来た")