use of io.github.vocabhunter.analysis.filter.WordFilter in project VocabHunter by VocabHunter.
the class SessionWordsToolTest method validate.
private void validate(final Function<Path, List<String>> filterMethod, final List<String> expected) throws Exception {
WordFilter filter = buildFilter(filterMethod);
List<? extends MarkedWord> words = read(SESSION_FILE);
MarkTool<? extends MarkedWord> markTool = new MarkTool<>(filter, words);
List<? extends MarkedWord> shownWords = markTool.getShownWords();
List<String> actual = shownWords.stream().map(MarkedWord::getWordIdentifier).collect(toList());
assertEquals("Filtered words", expected, actual);
}
use of io.github.vocabhunter.analysis.filter.WordFilter in project VocabHunter by VocabHunter.
the class SessionController method updateWordList.
private void updateWordList() {
boolean isEditable = sessionModel.isEditable();
FilterSettings filterSettings = sessionModel.getFilterSettings();
boolean isFilterEnabled = sessionModel.isEnableFilters();
VocabHunterException exception;
boolean isFilterSuccess;
try {
WordFilter filter = filterSettingsTool.filter(filterSettings, isFilterEnabled);
MarkTool<WordModel> markTool = new MarkTool<>(filter, sessionModel.getAllWords());
isFilterSuccess = markTool.isValidFilter();
if (isFilterSuccess) {
sessionModel.updateWordList(isEditable, markTool);
wordListHandler.selectClosestWord(isEditable, filter);
}
exception = null;
} catch (final VocabHunterException e) {
LOG.error("Failed to activate filter", e);
exception = e;
isFilterSuccess = false;
}
if (!isFilterSuccess) {
processFilterFailure(exception);
}
}
use of io.github.vocabhunter.analysis.filter.WordFilter in project VocabHunter by VocabHunter.
the class VocabHunterConsoleExecutable method processInput.
private static void processInput(final VocabHunterConsoleArguments bean, final PrintWriter out) {
for (String input : bean.getInput()) {
Path file = Paths.get(input);
SimpleAnalyser analyser = new SimpleAnalyser();
FileStreamer streamer = new FileStreamer(analyser);
WordFilter wordFilter = buildFilter(bean);
AnalysisResult model = streamer.analyse(file);
model.getOrderedUses().stream().filter(wordFilter::isShown).forEach(w -> display(out, model.getLines(), w, bean.isHideUses()));
}
}
Aggregations