private void processTranslationTable( @NotNull String queryString, @NotNull Document document, @NotNull BilingualQueryResultBuilder resultBuilder, @NotNull Language sourceLanguage, @NotNull Language targetLanguage) { // Find main table (german to X) String languageIdentifier = sourceLanguage.getIdentifier().toLowerCase(); Element translationTable = document.getElementById("gridTranslations-" + languageIdentifier); // Process the main table with its entries if (translationTable != null) { // Find all relevant entries, filter them by class and process them translationTable .getElementsByClass("hover") .stream() .filter(e -> e.hasClass("default") || e.hasClass("alt")) .forEach( e -> processEntry(queryString, e, resultBuilder, sourceLanguage, targetLanguage)); // Extract synonyms extractBilingualSynonyms(translationTable, resultBuilder, sourceLanguage); } else { LOGGER.debug( "Translation table for {} -> {} with query \"{}\" is null", languageIdentifier, targetLanguage.getIdentifier(), queryString); } }
/** * Returns the one of two languages that is not GERMAN. If none of the two is german, an * IllegalArgumentException will be thrown. * * @param inputLanguage First language to compare. * @param outputLanguage Second language to compare. * @return The non-german language. */ @NotNull private Language findTargetLanguage( @NotNull Language inputLanguage, @NotNull Language outputLanguage) { if (Language.GERMAN.equals(inputLanguage)) return outputLanguage; else if (Language.GERMAN.equals(outputLanguage)) { return inputLanguage; } else { throw new IllegalArgumentException( "Expected at least one language to be german - got " + inputLanguage.getIdentifier() + " and " + outputLanguage.getDisplayName()); } }