예제 #1
0
def regular_check(one_string="",
                  size=100,
                  interval=50,
                  ratio=5,
                  regular_index=None,
                  one_pattern=""):
    """
    检测字符串。
    :param one_string: 输入字符串
    :param size: 窗口大小,默认100
    :param interval: 步长,默认50
    :param ratio: 比例,默认5
    :param li: 采用的规则过滤,一共[1, 2, 3, 4, 5]五条
    :param one_pattern: 用户自定义的正则表达式
    :return: 字典,key:位置和最大字符的字符串;value:检测有问题的子字符串
    """
    check_res = char_count.char_count(one_string, size, interval, ratio)
    func_index = [1, 2, 3, 4, 5]

    if not regular_index:
        regular_index = [1, 2, 3, 4, 5]  # 若没给出参数值,则默认使用全部参数
    else:
        regular_index = list(set(regular_index)
                             & set(func_index))  # 求交集,用于参数检查
    if len(check_res) != 0:
        check_res = del_num_most(check_res)  # 先对统计结果过滤,过滤大部分不符合要求的数字和字母
        check_res = del_gene_order(check_res)

        for index in regular_index:
            if index == 1:
                check_res = filter_catalog(check_res)
                # print("1-catalog")

            elif index == 2:
                check_res = filter_engdict(check_res)
                # print("2-engdict")

            elif index == 3:
                check_res = filter_number(check_res)
                # print("3-number")

            elif index == 4:
                check_res = filter_alphabet(check_res)
                # print("4-alphabet")

            elif index == 5:
                check_res = filter_chinese_words(check_res)
                # print("5-chinese_characters")

        if one_pattern != "":
            check_res = filter_user_defined(check_res, one_pattern)
            # print("6-user_defined")

    if check_res:
        return check_res
    else:
        return "regular_check:Normal"
예제 #2
0
 def test_case_2(self):
     self.assertEqual(
         char_count("an apple a day will keep the doctor away"), {
             "a": 6,
             "e": 4,
             "l": 3,
             "p": 3,
             "w": 2,
             "d": 2,
             "o": 2,
             "t": 2,
             "y": 2,
             "k": 1,
             "h": 1,
             "i": 1,
             "c": 1,
             "n": 1,
             "r": 1
         })
예제 #3
0
def char_count_wrapper(file, queue):
    queue.put((file, char_count(file)))
예제 #4
0
 def test_case_1(self):
     self.assertEqual(char_count("aaabbc"), {"a": 3, "b": 2, "c": 1})
예제 #5
0
                "p": 3,
                "w": 2,
                "d": 2,
                "o": 2,
                "t": 2,
                "y": 2,
                "k": 1,
                "h": 1,
                "i": 1,
                "c": 1,
                "n": 1,
                "r": 1
            })


print(char_count("aaabbc") == {"a": 3, "b": 2, "c": 1})

print(
    char_count("an apple a day will keep the doctor away") == {
        "a": 6,
        "e": 4,
        "l": 3,
        "p": 3,
        "w": 2,
        "d": 2,
        "o": 2,
        "t": 2,
        "y": 2,
        "k": 1,
        "h": 1,
        "i": 1,
예제 #6
0
# Can you translate this driver code to unit tests?

from char_count import char_count

print(char_count("aaabbc") == {
  "a": 3,
  "b": 2,
  "c": 1
})

print(char_count("an apple a day will keep the doctor away") == {
  "a":6,
  "e":4,
  "l":3,
  "p":3,
  "w":2,
  "d":2,
  "o":2,
  "t":2,
  "y":2,
  "k":1,
  "h":1,
  "i":1,
  "c":1,
  "n":1,
  "r":1
})