在 stanford core nlp 中获取位置

Getting locations in stanford core nlp

我正在使用 stanford-corenlp-3.2.0.jarstanford-corenlp-3.2.0-models.jar 来识别特定句子中的位置。但是我观察到如果单词以小写形式传递,stanford-nlp 无法识别位置。

例如:"Find a restaurant in London"。在这里,斯坦福将确定伦敦为地点。

然而,如果下面的句子像这样传递:"Find a restaurant in london",那么斯坦福就无法将 london 识别为一个位置。

为了解决这个问题,我将句子中每个单词的首字母转换为大写。但是,如果我这样做,我会遇到其他问题。

根据 meskobalazs 提供的答案, 我已经下载了 jar:stanford-corenlp-caseless-2015-04-20-models.jar.

我用之前的jar替换了:stanford-corenlp-3.2.0-models.

但是现在我得到以下异常

SEVERE: Exception sending context initialized event to listener instance of class servlets.NLP_initializer
java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.create(StanfordCoreNLP.java:493)
    at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:81)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:260)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:127)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:123)
    at servlets.NLP_initializer.contextInitialized(NLP_initializer.java:34)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:749)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:283)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:247)
    at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:78)
    at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:62)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.create(StanfordCoreNLP.java:491)
    ... 14 more
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
    at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:419)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:744)
    ... 19 more

服务器启动时我初始化的地方是

  public static edu.stanford.nlp.pipeline.StanfordCoreNLP snlp;
    /**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
        Properties props = new Properties();
        props.put("annotators", "tokenize,ssplit,pos,lemma,parse,ner,dcoref");
        StanfordCoreNLP snlp = new StanfordCoreNLP(props);
    }

据我所知here, you should try out models which ignore the capitalization of words. You just need to add this models jar file to the existing one: caseless models

供将来参考:jar link 可能已损坏,但第一个 link 转到页面,其中可以找到最新 jar 的 link。