我在找像这样的句子
幼儿教育学士学位,心理学
幼儿教学
从…
心理学
我为这个过程的代码循环通过对象三重,并保持它,如果特定的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);
}
由于教学和心理学之间的逗号不在符号中,我不知道如何识别这一鸿沟。
有人能告诉我吗?
发布于 2017-05-02 16:58:46
注意,如果没有找到POS标记,token.get(CoreAnnotations.PartOfSpeechAnnotation.class)
将返回令牌。使用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
}
}
}
https://stackoverflow.com/questions/43729848
复制相似问题