gpt4 book ai didi

java - 扫描大量文件几十个字

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:45:06 25 4
gpt4 key购买 nike

我有大量文档(超过一百万),我需要定期扫描并匹配大约 100 个“多词关键字”(即不仅是“电影”等关键字,还有“北美”)。我有以下代码可以很好地处理单个单词关键字(即“书”):

/** 
* Scan a text for certain keywords
* @param keywords the list of keywords we are searching for
* @param text the text we will be scanning
* @return a list of any keywords from the list which we could find in the text
*/
public static List<String> scanWords(List<String> keywords, String text) {

// prepare the BreakIterator
BreakIterator wb = BreakIterator.getWordInstance();
wb.setText(text);

List<String> results = new ArrayList<String>();

// iterate word by word
int start = wb.first();
for (int end = wb.next(); end != BreakIterator.DONE; start = end, end = wb.next()) {

String word = text.substring(start, end);

if (!StringUtils.isEmpty(word) && keywords.contains(word)){

// we have this word in our keywords so return it
results.add(word);
}
}

return results;
}

注意:我需要这段代码尽可能高效,因为文档数量非常大。

我当前的代码无法找到 2 个关键词关键字中的任何一个。关于如何修复的任何想法?我也可以采用完全不同的方法。

最佳答案

扫描每个文档根本无法缩放。在 inverted index 中更好地索引您的文档或者在评论中使用 Lucene。

关于java - 扫描大量文件几十个字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27047698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com