【问题标题】:StanfordNLP: Unable to identify Date with 7-class-nerStanfordNLP:无法用 7-class-ner 识别日期
【发布时间】:2020-11-11 16:44:18
【问题描述】:

我正在使用 stanfordNLP 从文本中获取日期实体。这是我尝试过的代码:-

import java.io.IOException;
import java.util.List;
import edu.stanford.nlp.ie.AbstractSequenceClassifier;
import edu.stanford.nlp.ie.crf.CRFClassifier;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;

public class StanfordNLP_POC
{

    public static void main(String[] args) throws IOException
    {
        // TODO Auto-generated method stub
        String classifierPath = "src//main//resources//classifiers//english.muc.7class.distsim.crf.ser.gz";

        String inputString = "Appointment Facility: ABC Medicine Clinic 05/07/2020 Progress Notes: Niel Armstrong, DO Current Medications Reason for Appointment";

        AbstractSequenceClassifier classifier = CRFClassifier.getClassifierNoExceptions(classifierPath);

        List<List<CoreLabel>> out = classifier.classify(inputString);

        System.out.println(out.toString());

        for (List<CoreLabel> sentence : out)
        {
            for (CoreLabel word : sentence)
            {

                if (word.getString(CoreAnnotations.AnswerAnnotation.class).equals("O"))
                    continue;
                System.out.println(word.word() + " = " + word.get(CoreAnnotations.AnswerAnnotation.class));
            }
        }

    }

}

我不明白为什么它没有提取日期,即使它在文本中非常清晰可识别。

【问题讨论】:

    标签: nlp stanford-nlp


    【解决方案1】:

    您应该使用完整的管道。这是一个查找日期的示例。

    package edu.stanford.nlp.examples;
    
    import edu.stanford.nlp.pipeline.*;
    
    import java.util.*;
    import java.util.stream.*;
    
    public class DateExtractionExample {
    
      public static void main(String[] args) {
        String text = "Appointment Facility: ABC Medicine Clinic 05/07/2020 Progress Notes: Niel Arrmstrong, DO Current " +
            "Medications Reason For Appointment";
        Properties props = new Properties();
        props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        CoreDocument doc = pipeline.processToCoreDocument(text);
        List<CoreEntityMention> dates = doc.entityMentions().stream().filter(em -> em.entityType().equals("DATE")).collect(
            Collectors.toList());
        System.err.println(dates);
      }
    
    }
    

    【讨论】:

    • 感谢您的回答。它正在提取示例中提供的此日期。但是,您能否具体说明 NER 和全管道在工作方面的区别,为什么它对相同模型的相同文本给出不同的结果?这种差异是否也会影响自定义 NER 模型?
    • 整个管道还使用 SUTime,这是一种基于规则的机制,用于识别日期和其他时间表达式。
    猜你喜欢
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-25
    • 2023-04-09
    • 1970-01-01
    • 2020-05-03
    相关资源
    最近更新 更多