List of usage examples for java.util TreeMap putIfAbsent
default V putIfAbsent(K key, V value)
From source file:org.apdplat.superword.tools.SentenceScorer.java
public static TreeMap<Float, Map<String, List<String>>> score(String path, int limit) { //? //from w w w . j ava2 s. c o m Set<String> fileNames = TextAnalyzer.getFileNames(path); //? Map<String, AtomicInteger> frequency = TextAnalyzer.frequency(fileNames); //? TreeMap<Float, Map<String, List<String>>> sentences = new TreeMap<>(); //?????? Set<Integer> hashes = new HashSet<>(); Set<String> repeat = new HashSet<>(); //????????? int count = 0; for (String fileName : fileNames) { try (BufferedReader reader = new BufferedReader( new InputStreamReader(new BufferedInputStream(new FileInputStream(fileName))))) { String book = Paths.get(fileName).toFile().getName().replace(".txt", ""); String line = null; while ((line = reader.readLine()) != null) { if (StringUtils.isBlank(line)) { continue; } int hc = line.hashCode(); if (hashes.contains(hc)) { repeat.add(line); continue; } hashes.add(hc); // float score = score(line, frequency); if (score > 0) { if (count >= limit) { LOGGER.debug("?????" + limit + "?"); return sentences; } count++; sentences.putIfAbsent(score, new HashMap<>()); sentences.get(score).putIfAbsent(book, new ArrayList<>()); sentences.get(score).get(book).add(line); } } } catch (IOException ex) { ex.printStackTrace(); } } LOGGER.debug("????" + repeat.size()); AtomicInteger i = new AtomicInteger(); repeat.forEach(r -> { LOGGER.debug("\t" + i.incrementAndGet() + "?" + r); }); LOGGER.debug("???" + count); return sentences; }