如何确定 wordList 是否包含 Java 中短语的子字符串之一
How to determine if a wordList contains one of the substrings of a phrase in Java
我有一个 List stopWord(每个字符串只有一个词)和一个字符串短语(至少 2 个词)。我想检查我的短语是否包含 Java 中的停用词元素之一。我该怎么做?
if(!stopWord.contains(phrase.toLowerCase())
String delims = "[ ,-.…•“”‘’:;!()/?\"]+";
我使用了这段代码,但我认为它不理解包含 2 个单词的字符串,这是我的短语。 stopWord 的每个元素都是单个单词。我没有拆分我的短语。因为我正在处理大量数据。有没有更简单的方法?
String[] words = phrase.split(" ");
for (String word : words)
{
if (stopWord.contains(word))
{
// do here whatever you need :)
}
}
如果您使用 Java 8:
String phrase = "your phrase";
if (stopWord.parallelStream().anyMatch(s -> phrase.contains(s)))
{
// do stuff here
}
我有一个 List stopWord(每个字符串只有一个词)和一个字符串短语(至少 2 个词)。我想检查我的短语是否包含 Java 中的停用词元素之一。我该怎么做?
if(!stopWord.contains(phrase.toLowerCase())
String delims = "[ ,-.…•“”‘’:;!()/?\"]+";
我使用了这段代码,但我认为它不理解包含 2 个单词的字符串,这是我的短语。 stopWord 的每个元素都是单个单词。我没有拆分我的短语。因为我正在处理大量数据。有没有更简单的方法?
String[] words = phrase.split(" ");
for (String word : words)
{
if (stopWord.contains(word))
{
// do here whatever you need :)
}
}
如果您使用 Java 8:
String phrase = "your phrase";
if (stopWord.parallelStream().anyMatch(s -> phrase.contains(s)))
{
// do stuff here
}