com.github.houbb.auto.summary.api.impl.AbstractAutoSummary Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of auto-summary Show documentation
Show all versions of auto-summary Show documentation
The auto-summary tool for java.
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);
}
}