gpt4 book ai didi

java - 斯坦福自然语言处理 : Keeping punctuation tokens?

转载 作者:行者123 更新时间:2023-11-30 02:33:24 25 4
gpt4 key购买 nike

我正在寻找诸如

之类的句子

Bachelors Degree in early childhood teaching, psychology

  • 我使用斯坦福解析器对文本进行注释。
  • 然后,我迭代每个句子并使用 NER(命名实体识别)识别“学士学位”。
  • 通过处理三元组,我可以看到该对象遵循“BE IN”并且很可能是大学专业。
  • 因此我发送宾语短语以供进一步分析。我的问题是我不知道如何分开

early childhood teaching

来自

psychology

此过程的代码循环遍历对象三元组,并在满足某些 POS 要求时保留它。

private void processTripleObject(List<CoreLabel> objectPhrase )
{
try
{
StringBuilder sb = new StringBuilder();
for(CoreLabel token: objectPhrase)
{
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);

TALog.getLogger().debug("pos: "+pos+" word "+token.word());
if(!matchDegreeNameByPos(pos))
{
return;
}

sb.append(token.word());
sb.append(SPACE);
}

IdentifiedToken itoken = new IdentifiedToken(IdentifiedToken.SKILL, sb.toString());

}
catch(Exception e)
{
TALog.getLogger().error(e.getMessage(),e);
}

由于教学和心理学之间的逗号不在标记中,所以我不知道如何识别分歧。

谁能给点建议吗?

最佳答案

请注意,如果未找到 POS 标签,token.get(CoreAnnotations.PartOfSpeechAnnotation.class) 将返回 token 。使用 CoreNLP 3.7.0 和“tokenize ssplit pos”注释器进行测试。然后,您可以检查 pos 是否在带有您感兴趣的标点符号的字符串中。例如,我刚刚测试了一些代码:

String punctuations = ".,;!?";
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
// pos could be "NN" but could also be ","
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
if (punctuations.contains(pos)) {
// do something with it
}
}
}

关于java - 斯坦福自然语言处理 : Keeping punctuation tokens?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43729848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com