List of usage examples for com.google.common.util.concurrent AtomicDouble floatValue
public float floatValue()
From source file:zipkin.finagle.ReporterMetricsAdapter.java
static AtomicDouble gaugeFor(StatsReceiver stats, String scope) { final AtomicDouble result = new AtomicDouble(); StatsReceivers.addGauge(stats, new Callable<Float>() { @Override//w ww. j a v a 2 s .c om public Float call() throws Exception { return result.floatValue(); } }, scope); return result; }
From source file:com.qwazr.utils.WordCount.java
public static float compare(WordCount dic1, WordCount dic2) { HashSet<String> wordSet = new HashSet<String>(dic1.wordCount.keySet()); wordSet.addAll(dic2.wordCount.keySet()); AtomicDouble similarity = new AtomicDouble(); wordSet.forEach(new Consumer<String>() { @Override//from w w w . j a v a2s. co m public void accept(String word) { final AtomicInteger c1 = dic1.wordCount.get(word); final AtomicInteger c2 = dic2.wordCount.get(word); if (c1 == null || c2 == null) return; final double v1 = c1.doubleValue(); final double v2 = c2.doubleValue(); final double delta = v1 > v2 ? v2 / v1 : v1 / v2; similarity.addAndGet(delta); } }); return similarity.floatValue() / (float) wordSet.size(); }
From source file:pt.ua.ri.search.ProximitySearch.java
@Override public Iterable<Result> search(String query) { String nquery = null;/* w w w . jav a2 s . com*/ int dist = 1; Matcher m = queryPattern.matcher(query); if (m.matches()) { nquery = m.group("query"); try { dist = Integer.parseInt(m.group("dist")); } catch (NumberFormatException ex) { dist = 1; } } if (nquery == null) { return super.search(query); } List<Result> ret = new ArrayList<>(); Map<String, IndexTuple> tokenInfos = new HashMap<>(); TObjectFloatHashMap<String> palavrasNLize = new TObjectFloatHashMap<>(); TIntFloatMap docsnLize = new TIntFloatHashMap(); tok.setText(query); List<String> palavras = new ArrayList<>(); while (tok.hasNext()) { palavras.add(tok.next().getString()); } final AtomicDouble queryLength = new AtomicDouble(0.0); for (String palavra : palavras) { index.get(palavra).ifPresent(postingList -> { tokenInfos.put(palavra, postingList); int df = postingList.getDocumentFrequency(); float idf = (float) (Math.log(index.numberOfDocuments()) - Math.log(df)); queryLength.addAndGet(idf * idf); palavrasNLize.put(palavra, idf); }); } queryLength.set(Math.sqrt(queryLength.doubleValue())); palavrasNLize.transformValues(new TransformationFunction(queryLength.floatValue())); Iterator<String> it = palavras.iterator(); // for each two words if (it.hasNext()) { String p_actual; String p_next = it.next(); ProximityIndexTuple t_ac; ProximityIndexTuple t_nx = (ProximityIndexTuple) tokenInfos.get(p_next); while (it.hasNext()) { p_actual = p_next; p_next = it.next(); t_ac = t_nx; t_nx = (ProximityIndexTuple) tokenInfos.get(p_next); // get all documents from both words // see documents in common Collection<Integer> isect = CollectionUtils.intersection(t_ac.getDocumentsID(), t_nx.getDocumentsID()); // for each document get positions of words for (int doc_id : isect) { Iterable<Integer> lp_ac = t_ac.getDocumentPositions(doc_id); Iterable<Integer> lp_nx = t_nx.getDocumentPositions(doc_id); Iterator<Integer> it_ac = lp_ac.iterator(); Iterator<Integer> it_nx = lp_nx.iterator(); if (!it_ac.hasNext() || !it_nx.hasNext()) { break; } int pos_ac = it_ac.next(), pos_nx = it_nx.next(); float score = docsnLize.containsKey(doc_id) ? docsnLize.get(doc_id) : 0; score += comparePos(pos_ac, pos_nx, dist, doc_id, palavrasNLize, p_actual, p_next, t_ac, t_nx); while (score <= 0.0f && (it_ac.hasNext() || it_nx.hasNext())) { if (pos_ac < pos_nx) { if (it_ac.hasNext()) { pos_ac = it_ac.next(); } else { pos_nx = it_nx.next(); } } else { if (it_nx.hasNext()) { pos_nx = it_nx.next(); } else { pos_ac = it_ac.next(); } } score += comparePos(pos_ac, pos_nx, dist, doc_id, palavrasNLize, p_actual, p_next, t_ac, t_nx); } if (score > 0.0f) { docsnLize.put(doc_id, score); } } } } docsnLize.forEachEntry((int doc_id, float score) -> ret.add(new SimpleResult(doc_id, score))); Collections.sort(ret); return ret; }