
com.harium.suneidesis.linguistic.matcher.Sequence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Project to represent knowledge
The newest version!
package com.harium.suneidesis.linguistic.matcher;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Sequence implements Matcher {
protected List keywords = new ArrayList<>();
public Sequence(List keywords) {
this.keywords.addAll(keywords);
}
public Sequence(String... keywords) {
this.keywords.addAll(Arrays.asList(keywords));
}
@Override
public boolean matches(String[] tokens) {
if (keywords.isEmpty()) {
return true;
}
int cursor = 0;
String keyword = keywords.get(0);
for (String token : tokens) {
if (keyword.equals(token)) {
if (cursor + 1 == keywords.size()) {
return true;
}
cursor++;
keyword = keywords.get(cursor);
}
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy