def inference(target_triple: str) -> Dict:
    "\n    推理函数\n    @param target_triple: 目标需预测三元组：'头实体 关系 尾实体'\n    @return: 头尾实体的10个预测结果\n    "
    if (kge_model is None):
        return {'预测结果': '提醒：模型未加载'}
    try:
        target_triple = target_triple.split()
        head = entity2id[target_triple[0]]
        tail = entity2id[target_triple[2]]
        relation = relation2id[target_triple[1]]
        target_triple = [(head, relation, tail)]
    except KeyError as e:
        return {'预测结果': f'实体或者关系 <{e}> 不存在，请确保输入的实体或者关系已存在。'}
    prediction = kge_model.test_step(kge_model, target_triple, all_true_triples, args, True)
    head_entity_prediction = [id2entity[str(idx)] for idx in prediction['head_predict']]
    tail_entity_prediction = [id2entity[str(idx)] for idx in prediction['tail_predict']]
    result = {'头实体预测结果': head_entity_prediction, '尾实体预测结果': tail_entity_prediction}
    return result
推理函数
@param target_triple: 目标需预测三元组：'头实体 关系 尾实体'
@return: 头尾实体的10个预测结果
def inference(target_triple: str) -> Dict:
    "\n    推理函数\n    @param target_triple: 目标需预测三元组：'头实体 关系 尾实体'\n    @return: 头尾实体的10个预测结果\n    "
    if (kge_model is None):
        return {'预测结果': '提醒：模型未加载'}
    try:
        target_triple = target_triple.split()
        head = entity2id[target_triple[0]]
        tail = entity2id[target_triple[2]]
        relation = relation2id[target_triple[1]]
        target_triple = [(head, relation, tail)]
    except KeyError as e:
        return {'预测结果': f'实体或者关系 <{e}> 不存在，请确保输入的实体或者关系已存在。'}
    prediction = kge_model.test_step(kge_model, target_triple, all_true_triples, args, True)
    head_entity_prediction = [id2entity[str(idx)] for idx in prediction['head_predict']]
    tail_entity_prediction = [id2entity[str(idx)] for idx in prediction['tail_predict']]
    result = {'头实体预测结果': head_entity_prediction, '尾实体预测结果': tail_entity_prediction}
    return result