Source:
<code>public List<Page> generateEmbeddingVectors(List<Page> pages, int batchThreshold) throws Exception { Map<String, Page> pageMap = pages.stream() .collect(Collectors.toMap(x -> x.getUri().toString(), x -> x)); Map<String, String> queries = new HashMap<>(); Map<String, Future<BatchSentenceVectorResponse>> futureMap = new ConcurrentHashMap<>(); int dimensions = this.getFastTextInfo().getDimensions(); double[] emptyVector = new double[dimensions]; String emptyEncodedVector = FastTextHelper.convertArrayToBase64(emptyVector); try (FastTextExecutorService executorService = new FastTextExecutorService()) { for (Page page : pages) { String pageSentence = page.getPageSentence(); if (null != pageSentence && !pageSentence.isEmpty() && page.getType() != PageType.timeseries) { queries.put(page.getUri().toString(), pageSentence); } else { page.setEncodedEmbeddingVector(emptyEncodedVector); } if (queries.size() == batchThreshold) { futureMap.putAll(this.submitVectorQueries(queries, executorService)); queries.clear(); } } } for (String requestId : futureMap.keySet()) { System.out.println(String.format("Processing request %s", requestId)); Future<BatchSentenceVectorResponse> future = futureMap.get(requestId); BatchSentenceVectorResponse response = future.get(); Map<String, SentenceVectorResponse> results = response.getResults(); for (String uri : results.keySet()) { SentenceVectorResponse sentenceVectorResponse = results.get(uri); String encodedVector = sentenceVectorResponse.getVector(); Map<String, Float> generatedKeywordsMap = sentenceVectorResponse.getKeywords(); List<String> generatedKeywords = generatedKeywordsMap.entrySet().stream() <START> .filter(x -> x.getValue() >= 0.5f) <END> .map(Map.Entry::getKey) .collect(Collectors.toList()); pageMap.get(uri).setEncodedEmbeddingVector(encodedVector); pageMap.get(uri).setGeneratedKeywords(generatedKeywords); } } return new ArrayList<>(pageMap.values()); }</code><technical_language>create a constant for 0.5f a meaningful name</technical_language>

Target:
public List<Page> generateEmbeddingVectors(List<Page> pages, int batchThreshold) throws Exception { Map<String, Page> pageMap = pages.stream() .collect(Collectors.toMap(x -> x.getUri().toString(), x -> x)); Map<String, Future<BatchSentenceVectorResponse>> futureMap = this.buildQueries(pages, batchThreshold); for (String requestId : futureMap.keySet()) { logDebug("Processing dp-fasttext request") .addParameter("context", requestId) .log(); Future<BatchSentenceVectorResponse> future = futureMap.get(requestId); BatchSentenceVectorResponse response = future.get(); Map<String, SentenceVectorResponse> results = response.getResults(); for (String uri : results.keySet()) { SentenceVectorResponse sentenceVectorResponse = results.get(uri); String encodedVector = sentenceVectorResponse.getVector(); Map<String, Float> generatedKeywordsMap = sentenceVectorResponse.getKeywords(); List<String> generatedKeywords = generatedKeywordsMap.entrySet().stream() .filter(x -> x.getValue() >= CONFIDENCE_THRESHOLD) .map(Map.Entry::getKey) .collect(Collectors.toList()); pageMap.get(uri).setEncodedEmbeddingVector(encodedVector); pageMap.get(uri).setGeneratedKeywords(generatedKeywords); } } return new ArrayList<>(pageMap.values()); }