depends on document size, but > 0.01 should be a good threshold

@return a score that reflects if needle subsumes haystack
760239
public static float subsumes(String haystack, final String needle) {

        if (needle == null || needle.length() < 0 || haystack == null
                || haystack.length() < 0)
            return 0f;

        try {
            // index the cleaned text
            RAMDirectory idx = new RAMDirectory();
            IndexWriterConfig iwc = new IndexWriterConfig(LUCENE_41, anal);
            IndexWriter writer = new IndexWriter(idx, iwc);

            // index
            Document doc = new Document();
            doc.add(new TextField(CONTENT_FIELD, haystack, Store.YES));
            writer.addDocument(doc);
            writer.close();

            // search
            IndexReader reader = open(idx);
            Query query = parser.parse(getNGram(needle, 3));
            TopDocs results = new IndexSearcher(reader).search(query, 1);
            float score = 0;
            for (ScoreDoc hit : results.scoreDocs) {
                score += hit.score;
            }
            reader.close();
            idx.close();
            return score;

        } catch (Exception e) {
            LOG.warn("could not computeSimilarity for " + needle, e);
        }
        return 0f;
    }
356248
private int binaryFirstSearch() {

        int low     = 0;
        int high    = count;
        int mid     = 0;
        int compare = 0;
        int found   = count;

        while (low < high) {
            mid     = (low + high) / 2;
            compare = compare(mid);

            if (compare < 0) {
                high = mid;
            } else if (compare > 0) {
                low = mid + 1;
            } else {
                high  = mid;
                found = mid;
            }
        }

        return found == count ? -1
                              : found;
    }
275939
public Integer getMtomThreshold()
   {
      if (childNode.getTextValueForPatternName("mtom-threshold") != null && !childNode.getTextValueForPatternName("mtom-threshold").equals("null")) {
         return Integer.valueOf(childNode.getTextValueForPatternName("mtom-threshold"));
      }
      return null;
   }
1123537
@Override
    protected double scoreImpl(List<Word> words1, List<Word> words2) {
        if(words1.isEmpty() && words2.isEmpty()){
            return 1.0;
        }
        //转变为不重复的集合
        Set<Word> words1Set = new HashSet<>(words1);
        Set<Word> words2Set = new HashSet<>(words2);
        // 两个集合的大小
        int set1Size = words1Set.size();
        int set2Size = words2Set.size();

        // 求交集（去重），计算交集的不重复词的个数
        words1Set.retainAll(words2Set);
        int intersectionSize = words1Set.size();

        //相似度分值
        double score = 2*intersectionSize / (double)(set1Size+set2Size);
        if(LOGGER.isDebugEnabled()) {
            LOGGER.debug("集合1：" + words1);
            LOGGER.debug("集合2：" + words2);
            LOGGER.debug("集合1的大小：" + set1Size);
            LOGGER.debug("集合2的大小：" + set2Size);
            LOGGER.debug("交集的大小：" + intersectionSize);
            LOGGER.debug("相似度分值=2*" + intersectionSize + "/(double)(" + set1Size + "+" + set2Size + ")=" + score);
        }
        return score;
    }
368048
private int sizePenalty() {
        long numClauses = (long) this.stats.clausesIrredundant / this.config.sizepen;
        int logres = 0;
        while (numClauses != 0 && logres < this.config.sizemaxpen) {
            numClauses >>= 1;
            logres++;
        }
        return 1 << logres;
    }
454060
@Override protected double score1(Chunk[] chks, double weight, double offset, double[/*nclass*/] fs, int row) {
    return score1static(chks, idx_tree(0), offset, fs, row, new Distribution(_parms), _nclass);
  }
434382
private int getLeastScore(Collection<String> ids)
	{
		int s = Integer.MAX_VALUE;

		for (String id : ids)
		{
			if (score.get(id) < s) s = score.get(id);
		}

		return s;
	}
1250305
private float getWordScore(DependencyTree t1, DependencyTree t2){
		float score=0;
		if(wg!=null){
			if(wg.isSym(t1.word, t2.word))
				score = 1;
			else if(wg.isAntonym(t1.word, t2.word))
				score = -1;
		}else if(t1.word.equals(t2.word))
			score = 1;
		return score;
	}
1147642
@Override protected double[] score0(double[] data, double[] preds, double offset, int ntrees) {
    super.score0(data, preds, offset, ntrees);
    if (ntrees >= 1) preds[1] = preds[0] / ntrees;
    preds[0] = normalizePathLength(preds[0]);
    return preds;
  }
705675
private double calculatePartitionQuality (ArrayList<Instance>[] docs,
			HashSparseVector[] centroid) {
		double quality = 0.0;

		for (int i = 0; i < docs.length; ++i) {
			quality += this.calculateClusterQuality(docs[i], centroid[i]);
		}
		return quality;
	}
249505
@Override
    protected double scoreImpl(List<Word> words1, List<Word> words2){
        double score = super.scoreImpl(words1, words2);

        score += (scalingFactor * commonPrefixLength() * (1.0 - score));

        return score;
    }
1282488
public double score(StringWrapper s, StringWrapper t) {
	String S = s.unwrap(),
	  T =t.unwrap();
    totalScore = 0.0;
    if (S.equals(T)) {
      matched = S.length();
      return 1.0;
    }
    else {
      sSize = S.length();
      tSize = T.length();
      // let S be the largest token
      if (sSize < tSize) {
        String tmp1 = S;
        S = T;
        T = tmp1;
        double tmp2 = sSize;
        sSize = tSize;
        tSize = tmp2;
        tokenT = T;
      }
      tokenT = S;
      ArrayList candidateList = algorithm1(S, T);
      sortList(candidateList);
      totalScore = getScore(candidateList);
      totalScore = (totalScore / ( (double) sSize) + totalScore / ( (double) tSize)) / 2.0;
      return winkler(totalScore, S, T);
    }
  }
687514
private double naiveQueryDense(NumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands) {
    double len = 0.; // Length of query object, for final normalization
    for(int dim = 0, max = obj.getDimensionality(); dim < max; dim++) {
      final double val = obj.doubleValue(dim);
      if(val == 0. || val != val) {
        continue;
      }
      len += val * val;
      // No matching documents in index:
      if(dim >= index.size()) {
        continue;
      }
      ModifiableDoubleDBIDList column = index.get(dim);
      for(DoubleDBIDListIter n = column.iter(); n.valid(); n.advance()) {
        scores.increment(n, n.doubleValue() * val);
        cands.add(n);
      }
    }
    return FastMath.sqrt(len);
  }
244962
private float getDepScore(DependencyTree t1, DependencyTree t2, int depth){
		float score = 0.0f;
		float modify = getDepthModify(depth);
		if(modify == 0)
			return score;
		
		double sScore = getWordScore(t1, t2);
        if (sScore != 0)
            score += modify * sScore;
        else
            score += factor * modify * getTagScore(t1, t2);
		
		for(int i = 0; i < t1.leftChilds.size(); i++)
			for(int j = 0; j < t2.leftChilds.size(); j++)
				score += getDepScore(t1.leftChilds.get(i), t2.leftChilds.get(j), depth+1);
		
//		for(int i = 0; i < t1.leftChilds.size(); i++)
//			for(int j = 0; j < t2.rightChilds.size(); j++)
//				score += getDepScore(t1.leftChilds.get(i), t2.rightChilds.get(j), depth+1);
//		
//		for(int i = 0; i < t1.rightChilds.size(); i++)
//			for(int j = 0; j < t2.leftChilds.size(); j++)
//				score += getDepScore(t1.rightChilds.get(i), t2.leftChilds.get(j), depth+1);
		
		for(int i = 0; i < t1.rightChilds.size(); i++)
			for(int j = 0; j < t2.rightChilds.size(); j++)
				score += getDepScore(t1.rightChilds.get(i), t2.rightChilds.get(j), depth+1);
		
		return score;
	}
282120
public String[] getBestLabels(double[] scores, float ratioOfBest) {
		if (ratioOfBest > 1 | ratioOfBest <= 0)
			throw new RuntimeException(
					"ratioOfBest shoudl be > 0 and <= 1 but got " + ratioOfBest);
		TreeMap<Double, String> sortedMap = new TreeMap<Double, String>();
		double max = -Double.MAX_VALUE;
		double min = Double.MAX_VALUE;
		for (int d = 0; d < scores.length; d++) {
			if (scores[d] > max) {
				max = scores[d];
			}
			if (scores[d] < min) {
				min = scores[d];
			}
		}

		double scaleFactor = max - min;
		for (int x = 0; x < scores.length; x++) {
			double newScore = ((scores[x] - min) / scaleFactor);
			sortedMap.put(newScore, this.lexicon.getLabel(x));
		}

		// find cutoffpoint -> we know that the best label will have a value of 1
		double threshold = ratioOfBest;

		List<String> labelsKept = new ArrayList<String>();
		Iterator<Entry<Double, String>> pairs = sortedMap.entrySet().iterator();
		while (pairs.hasNext()) {
			Entry<Double, String> pair = pairs.next();
			if (pair.getKey() >= threshold)
				labelsKept.add(pair.getValue());
		}
		return (String[]) labelsKept.toArray(new String[labelsKept.size()]);
	}
561835
private double initScore() {
        double score = 0;
        final int n = atoms.length;
        for (int i = 0; i < n; i++) {
            final Point2d p1 = atoms[i].getPoint2d();
            for (int j = i + 1; j < n; j++) {
                if (contribution[i][j] < 0) continue;
                final Point2d p2 = atoms[j].getPoint2d();
                final double x = p1.x - p2.x;
                final double y = p1.y - p2.y;
                final double len2 = x * x + y * y;
                score += contribution[j][i] = contribution[i][j] = 1 / Math.max(len2, MIN_SCORE);
            }
        }
        return score;
    }
798393
public void validate() {
        // AutoResetToZero
        if (niceMinValue > 0 || niceMaxValue < 0) {
            autoResetToZero = false;
        }

        // Threshold
        if (threshold < niceMinValue || threshold > niceMaxValue) {
            threshold = niceMaxValue;
        }

        // MinMeasuredValue
        if (minMeasuredValue < niceMinValue || minMeasuredValue > niceMaxValue) {
            minMeasuredValue = value;
        }

        // MaxMeasuredValue
        if (maxMeasuredValue > niceMaxValue || maxMeasuredValue < niceMinValue) {
            maxMeasuredValue = value;
        }

        // PeakValue
        if (peakValue < niceMinValue || peakValue > niceMaxValue) {
            peakValue = value;
        }

        // TrackStart
        if (Double.compare(trackStart, niceMinValue) <= 0 || Double.compare(trackStart, niceMaxValue) >= 0 || Double.compare(trackStart, trackStop) >= 0) {
            trackStart = niceMinValue;
        }

        // TrackStop
        if ((Double.compare(trackStop, niceMinValue)) <= 0 || Double.compare(trackStop, niceMaxValue) >= 0 || Double.compare(trackStop, trackStart) <= 0) {
            trackStop = niceMaxValue;
        }

        // TrackSection
        if (Double.compare(trackSection, niceMinValue) <= 0 || Double.compare(trackSection, niceMaxValue) >= 0 || Double.compare(trackSection, trackStart) <= 0 || Double.compare(trackSection, trackStop) >= 0) {
            trackSection = ((trackStart + (trackStop - trackStart) / 2.0));
        }

        // Areas
        for (Section area : areas) {
            if ((area.getStart() < niceMinValue) || Double.compare(area.getStart(), niceMaxValue) >= 0 || Double.compare(area.getStart(), area.getStop()) >= 0) {
                area.setStart(niceMinValue);
            }

            if (area.getStop() < niceMinValue || area.getStop() > niceMaxValue || Double.compare(area.getStop(), area.getStart()) <= 0) {
                area.setStop(niceMaxValue);
            }

            if (Double.compare(area.getStart(), minValue) == 0) {
                area.setStart(niceMinValue);
            }

            if (Double.compare(area.getStop(), maxValue) == 0) {
                area.setStop(niceMaxValue);
            }
        }

        // Sections
        for (Section section : sections) {
            if ((section.getStart() < niceMinValue) || Double.compare(section.getStart(), niceMaxValue) >= 0 || Double.compare(section.getStart(), section.getStop()) >= 0) {
                section.setStart(niceMinValue);
            }

            if (section.getStop() < niceMinValue || section.getStop() > niceMaxValue || Double.compare(section.getStop(), section.getStart()) <= 0) {
                section.setStop(niceMaxValue);
            }

            if (Double.compare(section.getStart(), minValue) == 0) {
                section.setStart(niceMinValue);
            }

            if (Double.compare(section.getStop(), maxValue) == 0) {
                section.setStop(niceMaxValue);
            }
        }

        // TickmarkSections
        for (Section tickmarkSection : tickmarkSections) {
            if ((tickmarkSection.getStart() < niceMinValue) || Double.compare(tickmarkSection.getStart(), niceMaxValue) >= 0 || Double.compare(tickmarkSection.getStart(), tickmarkSection.getStop()) >= 0) {
                tickmarkSection.setStart(niceMinValue);
            }

            if (tickmarkSection.getStop() < niceMinValue || tickmarkSection.getStop() > niceMaxValue || Double.compare(tickmarkSection.getStop(), tickmarkSection.getStart()) <= 0) {
                tickmarkSection.setStop(niceMaxValue);
            }

            if (Double.compare(tickmarkSection.getStart(), minValue) == 0) {
                tickmarkSection.setStart(niceMinValue);
            }

            if (Double.compare(tickmarkSection.getStop(), maxValue) == 0) {
                tickmarkSection.setStop(niceMaxValue);
            }
        }

        // Recalculate the redrawTolerance
        redrawFactor = redrawTolerance * getRange();

        // Correct the value (needed for init with negative minValue)
        value = value < niceMinValue ? niceMinValue : (value > niceMaxValue ? niceMaxValue : value);
    }