Skip to content

Commit 8997fc8

Browse files
committed
modify for abstracttagger parallel
1 parent 9279d26 commit 8997fc8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

fnlp-core/src/main/java/org/fnlp/nlp/cn/tag/AbstractTagger.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ public AbstractTagger(String file) throws LoadModelException {
8888
* @throws LoadModelException
8989
*/
9090
public AbstractTagger(AbstractTagger tagger){
91+
//modify for parallel
92+
Linear originClassifier = tagger.getClassifier();
93+
Linear newClassifier = new Linear(originClassifier.getInferencer(),originClassifier.getAlphabetFactory());
94+
setClassifier(newClassifier);
9195

92-
setClassifier(tagger.getClassifier());
9396
factory = getClassifier().getAlphabetFactory();
9497
labels = factory.DefaultLabelAlphabet();
9598
IFeatureAlphabet features = factory.DefaultFeatureAlphabet();
96-
featurePipe = new Sequence2FeatureSequence(templets, features,
99+
featurePipe = new Sequence2FeatureSequence(tagger.templets, features,
97100
labels);
98101
}
99102

fnlp-core/src/main/java/org/fnlp/nlp/cn/tag/POSTagger.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ public class POSTagger extends AbstractTagger {
6262
public POSTagger(String cwsmodel, String str) throws LoadModelException {
6363
super(str);
6464
cws = new CWSTagger(cwsmodel);
65+
}
66+
67+
/**
68+
* 构造函数
69+
* @param cwsmodel 分词模型文件
70+
* @param str 词性模型文件
71+
* @throws Exception
72+
*/
73+
public POSTagger(CWSTagger cwsmodel, POSTagger posmodel) throws LoadModelException {
74+
super(posmodel);
75+
prePipe = posmodel.prePipe;
76+
cws = new CWSTagger(cwsmodel);
6577
}
6678

6779
//分词词典也被dict指定

fnlp-core/src/main/java/org/fnlp/nlp/corpus/WordCount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class WordCount {
4646
public static void main(String[] args) throws Exception {
4747

4848
WordCount wc = new WordCount();
49-
wc.seg = new CWSTagger("./models/seg.m");
49+
wc.seg = new CWSTagger("../models/seg.m");
5050

5151
wc.count("./tmp/filterTweets.y");
5252
wc.count("./tmp/filterTweets.n");

0 commit comments

Comments
 (0)