forked from isnowfy/snownlp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.py[cod] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import codecs | ||
|
||
import zh | ||
|
||
data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), | ||
'stopwords') | ||
stop = set() | ||
fr = codecs.open(data_path, 'r', 'utf-8') | ||
for word in fr: | ||
stop.add(word.strip()) | ||
fr.close() | ||
|
||
|
||
def filter_stop(words): | ||
return filter(lambda x: x not in stop, words) | ||
|
||
|
||
def zh2hans(sent): | ||
return zh.transfer(sent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
|
||
import seg as TnTseg | ||
|
||
data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), | ||
'data.txt') | ||
segger = TnTseg.Seg() | ||
segger.train(data_path) | ||
|
||
|
||
def seg(sent): | ||
return list(segger.seg(sent)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import codecs | ||
|
||
from ..utils.tnt import TnT | ||
|
||
data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), | ||
'199801.txt') | ||
tagger = TnT() | ||
|
||
|
||
def train(file_name): | ||
fr = codecs.open(file_name, 'r', 'utf-8') | ||
data = [] | ||
for i in fr: | ||
line = i.strip() | ||
if not line: | ||
continue | ||
tmp = map(lambda x: x.split('/'), line.split()) | ||
data.append(tmp) | ||
fr.close() | ||
tagger.train(data) | ||
|
||
train(data_path) | ||
|
||
|
||
def tag_all(words): | ||
return tagger.tag(words) | ||
|
||
|
||
def tag(words): | ||
return map(lambda x: x[1], tag_all(words)) |
Empty file.