當前位置: 首頁>>代碼示例>>Java>>正文


Java MaxentTagger.tagSentence方法代碼示例

本文整理匯總了Java中edu.stanford.nlp.tagger.maxent.MaxentTagger.tagSentence方法的典型用法代碼示例。如果您正苦於以下問題:Java MaxentTagger.tagSentence方法的具體用法?Java MaxentTagger.tagSentence怎麽用?Java MaxentTagger.tagSentence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在edu.stanford.nlp.tagger.maxent.MaxentTagger的用法示例。


在下文中一共展示了MaxentTagger.tagSentence方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tagPos

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
/**
 * Tags the tokens with part of speech
 * 
 * @param tokens Array of token strings
 * @return Part of speech tags
 */
public static String[] tagPos(String[] tokens) {
	Sentence untagged = createSentence(tokens);
	Sentence tagged = MaxentTagger.tagSentence(untagged);
	
	String[] pos = new String[tagged.size()];
	for (int i = 0; i < tagged.size(); i++) {
		HasWord w = (HasWord) tagged.get(i);
		String[] s = w.toString().split("/");
		if (s.length > 1)
			pos[i] = s[s.length - 1];
		else
			pos[i] = "";
	}
	
	return pos;
}
 
開發者ID:claritylab,項目名稱:lucida,代碼行數:23,代碼來源:StanfordPosTagger.java

示例2: main

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length != 2) {
    System.err.println("usage: java TaggerDemo modelFile fileToTag");
    return;
  }
  MaxentTagger tagger = new MaxentTagger(args[0]);
  TokenizerFactory<CoreLabel> ptbTokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(),
							   "untokenizable=noneKeep");
  BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "utf-8"));
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, "utf-8"));
  DocumentPreprocessor documentPreprocessor = new DocumentPreprocessor(r);
  documentPreprocessor.setTokenizerFactory(ptbTokenizerFactory);
  for (List<HasWord> sentence : documentPreprocessor) {
    List<TaggedWord> tSentence = tagger.tagSentence(sentence);
    pw.println(Sentence.listToString(tSentence, false));
  }
  pw.close();
}
 
開發者ID:jaimeguzman,項目名稱:data_mining,代碼行數:19,代碼來源:TaggerDemo2.java

示例3: main

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
/**
 * @param args
 */
public static void main(String[] args) throws Exception{
	// TODO Auto-generated method stub

	
	  if (args.length != 2) {
	      System.err.println("usage: java TaggerDemo modelFile fileToTag");
	      return;
	    }
	    MaxentTagger tagger = new MaxentTagger(args[0] );
	    List<List<HasWord>> sentences = MaxentTagger.tokenizeText(new BufferedReader(new FileReader(args[1])));
	    for (List<HasWord> sentence : sentences) {
	    ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);
	    System.out.println(Sentence.listToString(tSentence, false));

	    
	    }
	  
	
}
 
開發者ID:jaimeguzman,項目名稱:data_mining,代碼行數:23,代碼來源:testPostagger.java

示例4: main

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
public static void main(String[] args) {
	String modelPath = DependencyParser.DEFAULT_MODEL;
	String taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger";

	for (int argIndex = 0; argIndex < args.length;) {
		switch (args[argIndex]) {
		case "-tagger":
			taggerPath = args[argIndex + 1];
			argIndex += 2;
			break;
		case "-com.dukenlidb.nlidb.model":
			modelPath = args[argIndex + 1];
			argIndex += 2;
			break;
		default:
			throw new RuntimeException("Unknown argument " + args[argIndex]);
		}
	}

	String text = "Return authors who have more papers than Bob in VLDB after 2000";

	MaxentTagger tagger = new MaxentTagger(taggerPath);
	DependencyParser parser = DependencyParser.loadFromModelFile(modelPath);

	DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));
	for (List<HasWord> sentence : tokenizer) {
		List<TaggedWord> tagged = tagger.tagSentence(sentence);
		GrammaticalStructure gs = parser.predict(tagged);

		// Print typed dependencies
		log.info(gs);
	}
	
}
 
開發者ID:DukeNLIDB,項目名稱:NLIDB,代碼行數:35,代碼來源:ParserDemo.java

示例5: main

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length != 2) {
    System.err.println("usage: java TaggerDemo2 modelFile fileToTag");
    return;
  }
  MaxentTagger tagger = new MaxentTagger(args[0]);
  TokenizerFactory<CoreLabel> ptbTokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(),
							   "untokenizable=noneKeep");
  BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "utf-8"));
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, "utf-8"));
  DocumentPreprocessor documentPreprocessor = new DocumentPreprocessor(r);
  documentPreprocessor.setTokenizerFactory(ptbTokenizerFactory);
  for (List<HasWord> sentence : documentPreprocessor) {
    List<TaggedWord> tSentence = tagger.tagSentence(sentence);
    pw.println(Sentence.listToString(tSentence, false));
  }

  // print the adjectives in one more sentence. This shows how to get at words and tags in a tagged sentence.
  List<HasWord> sent = Sentence.toWordList("The", "slimy", "slug", "crawled", "over", "the", "long", ",", "green", "grass", ".");
  List<TaggedWord> taggedSent = tagger.tagSentence(sent);
  for (TaggedWord tw : taggedSent) {
    if (tw.tag().startsWith("JJ")) {
      pw.println(tw.word());
    }
  }

  pw.close();
}
 
開發者ID:tudarmstadt-lt,項目名稱:sentiment,代碼行數:29,代碼來源:TaggerDemo2.java

示例6: main

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length != 2) {
    System.err.println("usage: java TaggerDemo modelFile fileToTag");
    return;
  }
  MaxentTagger tagger = new MaxentTagger(args[0]);
  List<List<HasWord>> sentences = MaxentTagger.tokenizeText(new BufferedReader(new FileReader(args[1])));
  for (List<HasWord> sentence : sentences) {
    List<TaggedWord> tSentence = tagger.tagSentence(sentence);
    System.out.println(Sentence.listToString(tSentence, false));
  }
}
 
開發者ID:tudarmstadt-lt,項目名稱:sentiment,代碼行數:13,代碼來源:TaggerDemo.java

示例7: countNamedEntity

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
public static int countNamedEntity(String commment) {
	List<HasWord> sentence = new ArrayList<HasWord>();
	MaxentTagger tagger = new MaxentTagger("models/wsj-0-18-bidirectional-nodistsim.tagger");
  

	String[] commmentArray = commment.split(" ");

	for (String s: commmentArray) {
		HasWord h = new HasWord1(s);
		sentence.add(h);
	}

	ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);

	int count = 0;
	for (TaggedWord t : tSentence) {
		if (namedEntitySet.contains(t.tag())) {
			count++;
		}
	}
	//System.out.println(Sentence.listToString(tSentence, false));
	
	//System.out.println("---->>"+count);
	return count;
	

}
 
開發者ID:tejasshah93,項目名稱:blog-summarization,代碼行數:28,代碼來源:Tagger.java

示例8: main

import edu.stanford.nlp.tagger.maxent.MaxentTagger; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  if (args.length != 2) {
    System.err.println("usage: java TaggerDemo modelFile fileToTag");
    return;
  }
  MaxentTagger tagger = new MaxentTagger(args[0]);
  List<List<HasWord>> sentences = MaxentTagger.tokenizeText(new BufferedReader(new FileReader(args[1])));
  for (List<HasWord> sentence : sentences) {
    ArrayList<TaggedWord> tSentence = tagger.tagSentence(sentence);
    System.out.println(Sentence.listToString(tSentence, false));
  }
}
 
開發者ID:jaimeguzman,項目名稱:data_mining,代碼行數:13,代碼來源:TaggerDemo.java


注:本文中的edu.stanford.nlp.tagger.maxent.MaxentTagger.tagSentence方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。