All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbb.auto.summary.api.impl.AbstractAutoSummary Maven / Gradle / Ivy

There is a newer version: 0.0.3
Show newest version
package com.github.houbb.auto.summary.api.impl;

import com.github.houbb.auto.summary.api.IAutoSummary;
import com.github.houbb.auto.summary.api.IAutoSummaryContext;
import com.github.houbb.auto.summary.api.IAutoSummaryResult;
import com.github.houbb.heaven.annotation.ThreadSafe;
import com.github.houbb.heaven.util.lang.StringUtil;
import com.github.houbb.heaven.util.util.CollectionUtil;
import com.github.houbb.keyword.api.IKeywordResult;

import java.util.List;

/**
 * 

project: auto-summary-IAutoSummary

*

create on 2020/3/12 21:56

* * @author binbin.hou * @since 0.0.2 */ @ThreadSafe public abstract class AbstractAutoSummary implements IAutoSummary { /** * 获取摘要列表 * @param sentenceList 句子列表 * @param keywordResults 关键词信息 * @param context 上下文 * @return 结果列表 * @since 0.0.2 */ protected abstract List getSummaryList(final List sentenceList, final List keywordResults, final IAutoSummaryContext context); /** * 自动摘要 * * @param context 上下文 * @return 结果 * @since 0.0.1 */ @Override public List autoSummary(final IAutoSummaryContext context) { //1. 文本 final String text = getText(context); //2. 句子 List sentenceList = getSentenceList(text, context); //3. 关键字 List keywordList = getKeywordResults(text, context); //4. 构建 summary 列表 List summaryList = getSummaryList(sentenceList, keywordList, context); //5. 返回结果对象 return summaryList; } /** * 获取文本信息 * @param context 上下文 * @return 字符串 * @since 0.0.2 */ protected String getText(final IAutoSummaryContext context) { return context.reader().reader(); } /** * 获取断句信息 * @param text 文本 * @param context 上下文 * @return 句子列表 * @since 0.0.2 */ protected List getSentenceList(final String text, final IAutoSummaryContext context) { return context.sentence().sentence(text); } /** * 获取关键词信息 * * map(string, integer) 关键词,权重 * @param text 文本 * @param context 上下文 * @return 句子列表 * @since 0.0.2 */ protected List getKeywordResults(final String text, final IAutoSummaryContext context) { final int limit = context.limit(); final int keywordLimit = limit * 3; return context.keyword().keyword(text, keywordLimit); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy