java - 从存在于第二个字符串列表中的字符串列表中删除所有项目
问题描述
我将对一系列 PDF 执行一些基本的 NLP,我想在将单词列表输出到 CSV 之前从 PDF 中删除所谓的“停用词”。我创建了一个停用词以及 PDF 中的单词的 ArrayList,并尝试使用 removeAll。我收到一个无用的错误 -Exception in thread main
在 removeAll 行上。
public class ReadingText {
public static void main(String args[]) throws IOException {
String stopList = "i,me,my,...";
String[] stopList1 = stopList.split(",");
List<String> stopList2 = Arrays.asList(stopList1);
File file = new File("C:/Users/Documents/Walmart_2020_Annual_Report.pdf");
PDDocument document = PDDocument.load(file);
PDFTextStripper pdfStripper = new PDFTextStripper();
String text = pdfStripper.getText(document);
text = text.replace(",", "");
text = text.trim().replaceAll(" +", " ");
text = text.replace(" ", ",");
String[] text2 = text.split(",");
List<String> wordList = Arrays.asList(text2);
wordList.removeAll(stopList2);
System.out.println(wordList.size());
} }
解决方案
推荐阅读
- sql-server - 无法连接到 Azure VM 上的远程 MSSQL(经典)
- python - 如何使用 Python (BeautifulSoup) 从网上抓取表格?
- python - PyCharm:在运行测试之前配置环境
- python-3.x - 将数据框写入 Excel 时为浮点数设置数字格式
- mongodb - Mongoose 在更新时附加到字符串
- javascript - 滑块切换后悬停效果不起作用
- sql - SQL Server - 如何将散列密码插入表?
- android-jetpack-compose - 如何解释 Android Jetpack Compose 中“组”的概念?
- python - 使用 RandomizedCV 调整随机森林分类器的问题
- python - (
, ProtocolError('无效数据或不支持的协议版本'), )