如何使用 OpenNLP 从文本中获取位置?

How to get location from text using OpenNLP?

我正在使用分块来标记数据并从文本中获取位置最初我尝试从下一个中提取名词短语当我们使用名词短语名称也被称为名词短语时所以它不能 use.then我搬到了核心 nlp 的位置 ner 我尝试 运行 下面的代码

 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    try {

InputStream inputStreamTokenizer = new 文件输入流("D:\project\Relation Extraction in Text Document\Libraray\parsing/en-token.bin"); TokenizerModel tokenModel = new TokenizerModel(inputStreamTokenizer);

  //String paragraph = "Mike and Smith are classmates"; 
  String paragraph = "Tutorialspoint is located in Hyderabad"; 

  //Instantiating the TokenizerME class 
  TokenizerME tokenizer = new TokenizerME(tokenModel); 
  String tokens[] = tokenizer.tokenize(paragraph); 

  //Loading the NER-location moodel 
  InputStream inputStreamNameFinder = new 
     FileInputStream("D:\project\Relation Extraction in Text Document\Libraray\parsing/en-ner-location.bin");       
  TokenNameFinderModel location = new TokenNameFinderModel(inputStreamNameFinder); 

  //Instantiating the NameFinderME class 
  NameFinderME nameFinder;      
        nameFinder = new NameFinderME(location);

  //Finding the names of a location 
  Span nameSpans[] = nameFinder.find(tokens);        
  //Printing the spans of the locations in the sentence 
 for(Span s: nameSpans)        
     System.out.println(s.toString()+"  "+tokens[s.getStart()]);

我收到一个错误 "java.lang.UnsupportedOperationException: Not supported yet."

错误符号位于“nameFinder = new NameFinderME(location);”说 "exmp.TokenNameFinderModel cannot be converted to opennlp.tools.namefind.TokenNameFinderModel" 它的共鸣是什么

您的导入不正确,这是一个有效的版本:

import java.io.FileInputStream;
import java.io.InputStream;

import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.namefind.TokenNameFinderModel;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.util.Span;

和输出:[4..5) location Hyderabad