在使用捷通智能灵云外呼系统V6.1时.需要大量使用到模式码,也就是正则表达式.而老版本365还是使用场景文件.
当要将老版本改编成新版本的时候,需要需要将dict.define文件中的一行行的词条用"|"或的关系分开.
若手工操作就太耽误时间了.这里编写了Python脚本来实现这一过程.
#!/usr/bin/env python # coding=utf-8 import sys filePath1 = sys.argv[1] filePath2 = sys.argv[2] temp = "" with open(filePath1,"r") as f1: with open(filePath2,"w") as f2: for line in f1: line = line.strip() # 判断是否是以"#"开头的注释行,或空行,跳过这行 if not len(line) or line.startswith("#"): continue # 以"TAG:"开头的话,截取字符串. if line.startswith("TAG:"): if not len(temp): flag = "s1" else: flag = "s2" else: flag = "s3" if flag == "s1": f2.write(line[4:] + " ") elif flag == "s2": temp = temp + ")" f2.write(temp + " "*2) temp = "" f2.write(line[4:] + " ") else: if not len(temp): temp = "(" + line else: temp = temp + "|" + line else: f2.write(temp + ")" + " ")
效果对比: