下面列出了com.google.common.util.concurrent.AtomicDouble#doubleValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public double dotProduct(SparseVector vec) {
AtomicDouble sum= new AtomicDouble(0);
if (this.getNumberNonZeroEntries()<vec.getNumberNonZeroEntries()){
this.nonZeroEntries().forEach(entry ->{
Vector outerVector = vec.getVectorByPosition(entry.getKey());
if (outerVector!=null)
sum.addAndGet(outerVector.dotProduct(entry.getValue()));
});
}else{
vec.nonZeroEntries().forEach(entry ->{
Vector localVector = this.getVectorByPosition(entry.getKey());
if (localVector!=null)
sum.addAndGet(localVector.dotProduct(entry.getValue()));
});
}
return sum.doubleValue();
}
public double getProjectionScore(TerminologyService referenceTerminology) {
AtomicDouble sum = new AtomicDouble(0);
AtomicDouble total = new AtomicDouble(0);
List<Term> top100 = topN(100).collect(toList());
for(Term docTerm :top100) {
total.addAndGet(docTerm.getSpecificity());
int baseRank = getBaseRankInRefTermino(referenceTerminology, docTerm);
if(baseRank > 0 && baseRank < 500)
sum.addAndGet(docTerm.getSpecificity());
}
return sum.doubleValue() / total.doubleValue();
}
/**
* Build a chart for the sentence using the specified supertagger beam. If the chart exceeds the maximum size, beta
* is doubled and the parser will re-try. When the function returns, beta will contain the value of the beam used
* for the returned chart.
*
*/
CompressedChart parseSentence(final List<String> sentence, final AtomicDouble beta,
final Collection<Category> rootCategories) {
final CompressedChart compressed;
final List<Collection<Category>> categories = new ArrayList<>();
final List<List<ScoredCategory>> tagsForSentence = tagger.tag(InputWord.listOf(sentence));
for (final List<ScoredCategory> tagsForWord : tagsForSentence) {
final List<Category> tagsForWord2 = new ArrayList<>();
final double threshold = beta.doubleValue() * Math.exp(tagsForWord.get(0).getScore());
for (final ScoredCategory leaf : tagsForWord) {
if (Math.exp(leaf.getScore()) < threshold) {
break;
}
tagsForWord2.add(leaf.getCategory());
}
categories.add(tagsForWord2);
}
// Find set of all parses
final ChartCell[][] chart = parser.parse(sentence, categories);
if (chart == null) {
if (beta.doubleValue() * 2 < 0.1 && backoff) {
beta.set(beta.doubleValue() * 2);
return parseSentence(sentence, beta, rootCategories);
} else {
return null;
}
}
if (chart[0][chart.length - 1] == null || chart[0][chart.length - 1].getEntries().size() == 0) {
return null;
}
compressed = CompressedChart.make(InputWord.listOf(sentence), chart, cutoffsDictionary, unaryRules,
rootCategories);
return compressed;
}