gpt4 book ai didi

java - 在字符串中搜索停用词

转载 作者:行者123 更新时间:2023-12-01 08:45:56 24 4
gpt4 key购买 nike

我正在尝试在字符串“zach”中搜索停用词 THE”、“BE”、“TO”、“OF”、“AND”、“A”、“IN”、“THAT”、“I ”、“IT”、“ON”、“IN”、“但是”、“IS”、“WIT​​H”。

我不确定字符串搜索方法是否有效,或者是否有更好的方法来做到这一点。

package zk;

public class Class
{

public boolean isNonStopWord(int[] nums, int value)
{

}
public String search( String [] Strings , String july) {
String [] skoal = {"THE", "BE", "TO", "OF", "AND", "A", "IN",
"THAT", "I", "IT", "ON", "IN", "BUT", "IS", "WITH"};
for ( String i = 0, ) {
return false;
}
return true;
}

public static void main(String [] args) {

String zach = ("Amazon offered up more answers Thursday about what"
+ " caused a bunch of websites to fail two days ago. According "
+ "to a postmortem by the company's cloud services business, "
+ "around 9:37 a.m. PT Tuesday an Amazon worker incorrectly"
+ " punched in a command while trying to debug an issue. "
+ "That command shut down a large set of servers at Amazon Web "
+ "Services' Northern Virginia site, causing a domino effect of"
+ " problems. Other services that relied on those S3 cloud"
+ " storage servers were disrupted. Also, removing so much "
+ "server capacity required a full system restart, which then "
+ "took longer than expected, AWS said. The sites affected "
+ "included Quora, Imgur, IFTTT, Giphy and Slack. Amazon was "
+ "able to fix the issue by about 2 p.m. PT.");
zach = zach.replace(",","");
zach = zach.replace(".","");
zach = zach.toUpperCase();
String [] strings = zach.split(" ");
for (String s1: strings)
{
System.out.println(s1);

}
}
}

最佳答案

假设您使用的是 Java 8+,您可以使用 Stream.noneMatch喜欢

String[] strings = zach.split("\\s+");
for (String s1 : strings) {
System.out.println(s1 + ": "
+ Stream.of(skoal).noneMatch(s -> s.equals(s1)));
}

并且,\\s+ 匹配正则表达式中的一个(或多个)空格。

关于java - 在字符串中搜索停用词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43037811/

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