Search in sources :

Example 1 with WordFilter

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);
}
Also used : WordFilter(io.github.vocabhunter.analysis.filter.WordFilter) MarkTool(io.github.vocabhunter.analysis.marked.MarkTool)

Example 2 with WordFilter

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);
    }
}
Also used : WordFilter(io.github.vocabhunter.analysis.filter.WordFilter) VocabHunterException(io.github.vocabhunter.analysis.core.VocabHunterException) MarkTool(io.github.vocabhunter.analysis.marked.MarkTool)

Example 3 with WordFilter

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()));
    }
}
Also used : Path(java.nio.file.Path) WordFilter(io.github.vocabhunter.analysis.filter.WordFilter) SimpleAnalyser(io.github.vocabhunter.analysis.simple.SimpleAnalyser) FileStreamer(io.github.vocabhunter.analysis.file.FileStreamer) AnalysisResult(io.github.vocabhunter.analysis.model.AnalysisResult)

Aggregations

WordFilter (io.github.vocabhunter.analysis.filter.WordFilter)3 MarkTool (io.github.vocabhunter.analysis.marked.MarkTool)2 VocabHunterException (io.github.vocabhunter.analysis.core.VocabHunterException)1 FileStreamer (io.github.vocabhunter.analysis.file.FileStreamer)1 AnalysisResult (io.github.vocabhunter.analysis.model.AnalysisResult)1 SimpleAnalyser (io.github.vocabhunter.analysis.simple.SimpleAnalyser)1 Path (java.nio.file.Path)1