我是Java新手。我需要检查statement
,如果它包含特定的ambguity word
,请执行一些操作。
所以,这是代码:
for (NlpAmbiguityWords nlpAmbiguityWord : nlpAmbiguityWordsList) {
String ambiguityWord = nlpAmbiguityWord.getWord();
if (statement.contains(ambiguityWord)) {
findAmbiguityWords(statement, ambiguityWord, ambiguityPhrase);
}
}
现在,POJO现在略有变化,除了传递ambguity word
之外,我们还必须传递另外两个参数precededBy
和followedBy
..这两个参数可以包含字符串数组(因此它们可以具有逗号分隔的值)。要求是:带有在前和在后的歧义词不应视为要在表中显示的歧义词。
例如:如果用户是歧义词,并且先行词是admin,tester,superadmin(3个逗号分隔值的集合),并且如果条件在3种情况下均为true,则其明确表示。在这种情况下不应该评估。 FollowBy使用相同的逻辑,并且beforedBy和followedBy的组合也适用。
答案 0 :(得分:0)
我不完全了解您要实现的方法,但是如果您想对先例(从逗号分隔的单词列表中),其后(从逗号分隔的单词列表中)到歧义词的每种组合应用某种逻辑,可以使用以下结构:
for (NlpAmbiguityWords nlpAmbiguityWord : nlpAmbiguityWordsList) {
String ambiguityWord = nlpAmbiguityWord.getWord();
String[] precededBys = new String[]{};
if (nlpAmbiguityWord.getPrecededBy()!=null)
precededBys =nlpAmbiguityWord.getPrecededBy().split(",");
String[] followedBys = new String[]{};
if (nlpAmbiguityWord.getFollowedBy()!=null)
followedBys =nlpAmbiguityWord.getFollowedBy().split(",");
for (String precedent:precededBys) {
// TODO: apply your logic with just precedent and ambiguityWord
for (String followed:folowedBys) {
// TODO: apply your logic using precendent, ambiguityWord and followed
}
}
for (String followed:folowedBys) {
// TODO: apply your logic using just ambiguityWord and followed
}
if (statement.contains(ambiguityWord)) {
findAmbiguityWords(statement, ambiguityWord, ambiguityPhrase);
}
}