Jonathan Star 2023-07-12 10:17 采纳率: 70.5%
浏览 15

hanlp 如果自己加了词典 语义就出不来,他直接拿下标的,但是要是语义拿不到能不能也不要报错,大不了给个null

hanlp 如果自己加了词典 语义就出不来,他直接拿下标的,但是要是语义拿不到能不能也不要报错,大不了给个null

 public static void addDic(){
       boolean add = CustomDictionary.add("后天", time);
    }
// 分词
List<Term> termList = StandardTokenizer.segment(sentence);
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at com.hankcs.hanlp.seg.common.Vertex.guessNature(Vertex.java:313)
    at com.hankcs.hanlp.recognition.nr.PersonRecognition.roleObserve(PersonRecognition.java:88)
    at com.hankcs.hanlp.recognition.nr.PersonRecognition.Recognition(PersonRecognition.java:34)
    at com.hankcs.hanlp.seg.Viterbi.ViterbiSegment.segSentence(ViterbiSegment.java:78)
    at com.hankcs.hanlp.seg.Segment.seg(Segment.java:523)
    at com.hankcs.hanlp.tokenizer.StandardTokenizer.segment(StandardTokenizer.java:40)
    at top.starp.util.HanLPUtil.extractTimeRange(HanLPUtil.java:26)
    at top.starp.util.HanLPUtil.main(HanLPUtil.java:78)
/**
 * 猜测最可能的词性,也就是这个节点的词性中出现频率最大的那一个词性
 *
 * @return
 */
public Nature guessNature()
{
    return attribute.nature[0];
}

文档:hanlp 如果自己加了词典 语义就出不来
链接:http://note.youdao.com/noteshare?id=ff1069d01481b9d5d06a098c33f88270&sub=C22E4E568BB946FC8221928B04CD82BF

  • 写回答

2条回答 默认 最新

  • chenxianchong 2023-07-12 10:43
    关注

    return attribute.nature.length>0?attribute.nature[0]:null;

    评论

报告相同问题?

问题事件

  • 创建了问题 7月12日

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失