nlp实现词性标注+分句

public List<String> getTag(String text){
List<String> lists=new ArrayList<String>();
   @SuppressWarnings("unchecked")
   List<List<HasWord>> sentences = tagger.tokenizeText(new StringReader(text));//tagger.tokenizeText(new BufferedReader(new FileReader(args[1])));
   for (List<HasWord> sentence : sentences) {
     ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);
     String sence="";
     for(TaggedWord tw:tSentence){
     String word=tw.word();
     String tag=tw.tag();
     if(word.equals("-LRB-")){
     word="(";
     }
     if(word.equals("-RRB-")){
     word=")";
     }
     if(sence.length()>0){
     sence=sence+" "+word+"<font color='red'>/"+tag+"</font>";
     }else{
     sence=word+"<font color='red'>/"+tag+"</font>";
     }
     }
     lists.add(sence);
   }
return lists;
}

 public List<String> getClause(String args){

List<String> lists=new ArrayList<String>();
String line;
List<List<HasWord>> sentences = tagger.tokenizeText(new StringReader(args));//tagger.tokenizeText(new BufferedReader(new FileReader(args[1])));
for (List<HasWord> sentence : sentences) {
line="";
 ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);
 for(TaggedWord tw:tSentence){
 if(line.length()>0){
 line=line+" "+tw.word();
 }else{
 line=tw.word();
 }
 }
 lists.add(line+"<font color='red'>/end</font>");
}
return lists;
}
posted @ 2013-02-01 18:03  6小贝  阅读(749)  评论(0编辑  收藏  举报