-
Notifications
You must be signed in to change notification settings - Fork 22
/
README
123 lines (82 loc) · 3.35 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
张沈鹏([email protected]) 修改版 rmmseg-cpp
github
https://github.com/42qu/mmseg
安装:
python setup.py install
用法如:
import mmseg
for i in mmseg.seg_txt("我爱天安门"):
print i
输出:
我爱
天安门
-------------------------------
原版信息
-------------------------------
pymmseg-cpp
by pluskid
http://code.google.com/p/pymmseg-cpp/
== DESCRIPTION:
pymmseg-cpp is a Python interface to rmmseg-cpp. rmmseg-cpp is a high
performance Chinese word segmentation utility for Ruby. However, the
core part is written in C++ independent of Ruby. So I decide to write
a Python interface for it in order to use it in my Python project.
== FEATURES/PROBLEMS:
* Runs fast and the memory consumption is small.
* Support user customized dictionaries.
* Only UTF-8 encoding is supported.
== SYNOPSIS:
=== A simple script
pymmseg-cpp provides a simple script (bin/pymmseg), which can read the
text from standard input and print the segmented result to standard
output. Try pymmseg -h for help on the options.
=== As a Python module
To use pymmseg-cpp in normal Python program, first import the module and
init by loading the dictionaries:
from pymmseg import mmseg
mmseg.dict_load_defaults()
Then create a Algorithm object and call next_token until got a
None. Or you can simply iterate through it:
algor = mmseg.Algorithm(text)
for tok in algor:
print '%s [%d..%d]' % (tok.text, tok.start, tok.end)
=== Customize the dictionary
You can load your own character dictionary or word dictionary in the
following way:
from pymmseg import mmseg
mmseg.dict_load_words('customize_words.dic')
mmseg.dict_load_chars('customize_chars.dic')
The format for the dictionary is very simple. On each line, you specify
the frequency followed by an whitespace and then the word/character. Just
don't forget the final newline at the end of the file.
== REQUIREMENTS:
* python 2.5
* g++
== INSTALL:
Download the package at
http://code.google.com/p/pymmseg-cpp/downloads/list . If you download
the source tarball, you'll need to compile it by
make build
if you download the pre-compiled version, this step can be skipped.
Then copy the pymmseg directory to your Python's package path. e.g.
/usr/lib/python2.5/site-packages/ . Now you can use pymmseg in your
application.
== LICENSE:
(The MIT License)
Copyright (c) 2008 FIXME (different license?)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.