⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pymmseg

📁 用python写的分词程序,实现的是最大匹配方法,简单易用
💻
字号:
#!/usr/bin/env pythonimport sysimport getoptfrom os.path import dirname, joinsys.path.append(join(dirname(__file__), '..'))import mmsegdef print_usage():    print """\mmseg  Segment Chinese text. Read from stdin and print to stdout.Options:  -h  --help      Print this message  -s  --separator Select the separator of the segmented text. Default is              space.    """    sys.exit(0)separator = " "optlst, args = getopt.getopt(sys.argv[1:], 'hs:')for opt, val in optlst:    if opt == '-h':        print_usage()        elif opt == '-s':        separator = val# load default dictionariesmmseg.dict_load_defaults()algor = mmseg.Algorithm(sys.stdin.read())first = Truefor tk in algor:    if not first:        sys.stdout.write(separator)    first = False    sys.stdout.write(tk.text)print

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -