# Path: janome/charfilter.py
# class RegexReplaceCharFilter(CharFilter):
#     """
#     RegexReplaceCharFilter replaces string matched with a regular expression pattern to replacement string.
# 
#     Added in *version 0.3.4*
#     """
# 
#     def __init__(self, pat: str, repl: str):
#         """
#         Initialize RegexReplaceCharFilter with a regular expression pattern string and replacement.
# 
#         :param pattern: regular expression string.
#         :param repl: replacement string.
#         """
#         self.pattern = re.compile(pat)
#         self.replacement = repl
# 
#     def apply(self, text: str) -> str:
#         return re.sub(self.pattern, self.replacement, text)
# 
# class UnicodeNormalizeCharFilter(CharFilter):
#     """
#     UnicodeNormalizeCharFilter normalizes Unicode string.
# 
#     Added in *version 0.3.4*
#     """
# 
#     def __init__(self, form: str = 'NFKC'):
#         """
#         Initialize UnicodeNormalizeCharFilter with normalization form.
# 
#         See also `unicodedata.normalize <https://docs.python.org/3.6/library/unicodedata.html#unicodedata.normalize>`_
# 
#         :param form: (Optional) normalization form. valid values for *form* are 'NFC', 'NFKC', 'NFD', and 'NFKD'.
#                      default is 'NFKC'
#         """
#         self.form = form
# 
#     def apply(self, text: str) -> str:
#         return unicodedata.normalize(self.form, text)


import unittest
import os
import sys
from janome.charfilter import RegexReplaceCharFilter, UnicodeNormalizeCharFilter
# Copyright 2015 moco_beta
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# TODO: better way to find package...
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir)


class TestCharFilter(unittest.TestCase):
    def test_regex_replace_charfilter(self):
        cf = RegexReplaceCharFilter('蛇の目', 'janome')
        self.assertEqual('janomeは形態素解析器です。', cf.apply('蛇の目は形態素解析器です。'))

        cf = RegexReplaceCharFilter('\s+', '')
        self.assertEqual('abcd', cf.apply(' a  b c   d  '))


# Path: janome/charfilter.py
# class RegexReplaceCharFilter(CharFilter):
#     """
#     RegexReplaceCharFilter replaces string matched with a regular expression pattern to replacement string.
# 
#     Added in *version 0.3.4*
#     """
# 
#     def __init__(self, pat: str, repl: str):
#         """
#         Initialize RegexReplaceCharFilter with a regular expression pattern string and replacement.
# 
#         :param pattern: regular expression string.
#         :param repl: replacement string.
#         """
#         self.pattern = re.compile(pat)
#         self.replacement = repl
# 
#     def apply(self, text: str) -> str:
#         return re.sub(self.pattern, self.replacement, text)
# 
# class UnicodeNormalizeCharFilter(CharFilter):
#     """
#     UnicodeNormalizeCharFilter normalizes Unicode string.
# 
#     Added in *version 0.3.4*
#     """
# 
#     def __init__(self, form: str = 'NFKC'):
#         """
#         Initialize UnicodeNormalizeCharFilter with normalization form.
# 
#         See also `unicodedata.normalize <https://docs.python.org/3.6/library/unicodedata.html#unicodedata.normalize>`_
# 
#         :param form: (Optional) normalization form. valid values for *form* are 'NFC', 'NFKC', 'NFD', and 'NFKD'.
#                      default is 'NFKC'
#         """
#         self.form = form
# 
#     def apply(self, text: str) -> str:
#         return unicodedata.normalize(self.form, text)


# Path: tests/test_charfilter.py
import unittest
import os
import sys
from janome.charfilter import RegexReplaceCharFilter, UnicodeNormalizeCharFilter

# Copyright 2015 moco_beta
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# TODO: better way to find package...
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir)


class TestCharFilter(unittest.TestCase):
    def test_regex_replace_charfilter(self):
        cf = RegexReplaceCharFilter('蛇の目', 'janome')
        self.assertEqual('janomeは形態素解析器です。', cf.apply('蛇の目は形態素解析器です。'))

        cf = RegexReplaceCharFilter('\s+', '')
        self.assertEqual('abcd', cf.apply(' a  b c   d  '))


        cf = RegexReplaceCharFilter('', '')