Java Code Examples for com.googlecode.javaewah.EWAHCompressedBitmap#orCardinality()

The following examples show how to use com.googlecode.javaewah.EWAHCompressedBitmap#orCardinality() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public AttributePairScores getPairwiseSimilarity(OWLClass c, OWLClass d)
		throws UnknownOWLClassException {
	AttributePairScores s = new AttributePairScores(c,d);
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(c);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(d);

	s.simjScore =  bmc.andCardinality(bmd) / (double) bmc.orCardinality(bmd);
	s.asymmetricSimjScore =  bmc.andCardinality(bmd) / (double) bmd.cardinality();
	s.inverseAsymmetricSimjScore =  bmc.andCardinality(bmd) / (double) bmc.cardinality();

	ScoreAttributeSetPair sap = getLowestCommonSubsumerWithIC(c, d);
	s.lcsIC = sap.score;
	s.lcsSet = sap.attributeClassSet;
	return s;
}
 
Example 2
Source File: KeywordJaccard.java    From StreamingRec with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the Jaccard similarity of two items in terms of their keywords
 * @param itemKeywords Keywords of the first item
 * @param anotherItemsKeywords Keywords of the other item 
 * @return the Jaccard similarity
 */
protected double similarity(EWAHCompressedBitmap itemKeywords, EWAHCompressedBitmap anotherItemsKeywords) {
	int intersection = itemKeywords.andCardinality(anotherItemsKeywords);
	if (intersection == 0) {
		// if the intersection is 0 -> return 0
		return 0;
	}
	// otherwise calculate the jaccard
	int union = itemKeywords.orCardinality(anotherItemsKeywords);
	return intersection * 1d / union * 1d;
}
 
Example 3
Source File: ItemItemCF.java    From StreamingRec with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the Jaccard similarity of two items in terms of the sets of users 
 * that clicked on them respectively
 * @param itemClicks Users that clicked on the first item
 * @param anotherItemsClicks Users that clicked on the other item 
 * @return the Jaccard similarity
 */
protected double similarity(EWAHCompressedBitmap itemClicks, EWAHCompressedBitmap anotherItemsClicks) {
	int intersection = itemClicks.andCardinality(anotherItemsClicks);
	if (intersection == 0) {
		// if the intersection is 0 -> return 0
		return 0;
	}
	// otherwise calculate the jaccard
	int union = itemClicks.orCardinality(anotherItemsClicks);
	return intersection * 1d / union * 1d;
}
 
Example 4
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public double getAttributeJaccardSimilarity(OWLClass c, OWLClass d) throws UnknownOWLClassException {
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(c);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(d);

	return bmc.andCardinality(bmd) / (double) bmc.orCardinality(bmd);
}
 
Example 5
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int getAttributeJaccardSimilarityAsPercent(OWLClass c,
		OWLClass d) throws UnknownOWLClassException {
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(c);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(d);

	return (bmc.andCardinality(bmd) * 100) / bmc.orCardinality(bmd);
}
 
Example 6
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public double getElementJaccardSimilarity(OWLNamedIndividual i,
		OWLNamedIndividual j) throws UnknownOWLClassException {
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(i);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(j);

	return bmc.andCardinality(bmd) / (double) bmc.orCardinality(bmd);
}
 
Example 7
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int getElementJaccardSimilarityAsPercent(OWLNamedIndividual i,
		OWLNamedIndividual j) throws UnknownOWLClassException {
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(i);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(j);

	return (bmc.andCardinality(bmd) * 100) / bmc.orCardinality(bmd);
}
 
Example 8
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private double computeSimJwithBM(EWAHCompressedBitmap iAttsBM, EWAHCompressedBitmap jAttsBM) {
	int cadSize = iAttsBM.andCardinality(jAttsBM);
	int cudSize = iAttsBM.orCardinality(jAttsBM);
	double simJPct = 0;
	if (cudSize != 0) {
		simJPct = (cadSize * 100) / cudSize;
	}
	return simJPct;
}
 
Example 9
Source File: SimSpeedTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private double jaccardBitmap(OWLClass c, OWLClass d) {
	EWAHCompressedBitmap bmc = ancsBitmapCachedModifiable(c);
	EWAHCompressedBitmap bmd = ancsBitmapCachedModifiable(d);

	return bmc.andCardinality(bmd) / (double) bmc.orCardinality(bmd);
}