Java Code Examples for org.apache.lucene.util.OpenBitSet#cardinality()

The following examples show how to use org.apache.lucene.util.OpenBitSet#cardinality() . 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: HyFD.java    From winter with Apache License 2.0 6 votes vote down vote up
protected int specializePositiveCover(FDTree posCoverTree, OpenBitSet lhs, int rhs) {
	int newFDs = 0;
	List<OpenBitSet> specLhss = posCoverTree.getFdAndGeneralizations(lhs, rhs);
	for (OpenBitSet specLhs : specLhss) {
		posCoverTree.removeFunctionalDependency(specLhs, rhs);
		
		if (specLhs.cardinality() == posCoverTree.getMaxDepth())
			continue;
		
		for (int attr = this.numAttributes - 1; attr >= 0; attr--) { // TODO: Is iterating backwards a good or bad idea?
			if (!lhs.get(attr) && (attr != rhs)) {
				specLhs.set(attr);
				if (!posCoverTree.containsFdOrGeneralization(specLhs, rhs)) {
					posCoverTree.addFunctionalDependency(specLhs, rhs);
					newFDs++;					
				}
				specLhs.clear(attr);
			}
		}
	}
	return newFDs;
}
 
Example 2
Source File: LhsTrie.java    From winter with Apache License 2.0 6 votes vote down vote up
public void removeLhs(OpenBitSet lhs) {
	LhsTrieElement[] path = new LhsTrieElement[(int)lhs.cardinality()];
	int currentPathIndex = 0;
	
	LhsTrieElement currentNode = this;
	path[currentPathIndex] = currentNode;
	currentPathIndex++;
	
	for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) {
		currentNode = currentNode.getChildren()[i];
		path[currentPathIndex] = currentNode;
		currentPathIndex++;
	}
	
	for (int i = path.length - 1; i >= 0; i --) {
		path[i].removeChild(i);
		if (path[i].getChildren() != null)
			break;
	}
}
 
Example 3
Source File: Inductor.java    From winter with Apache License 2.0 5 votes vote down vote up
protected int specializePositiveCover(OpenBitSet lhs, int rhs, FDList nonFds) {
	int numAttributes = this.posCover.getChildren().length;
	int newFDs = 0;
	List<OpenBitSet> specLhss;
	
	if (!(specLhss = this.posCover.getFdAndGeneralizations(lhs, rhs)).isEmpty()) { // TODO: May be "while" instead of "if"?
		for (OpenBitSet specLhs : specLhss) {
			this.posCover.removeFunctionalDependency(specLhs, rhs);
			
			if ((this.posCover.getMaxDepth() > 0) && (specLhs.cardinality() >= this.posCover.getMaxDepth()))
				continue;
			
			for (int attr = numAttributes - 1; attr >= 0; attr--) { // TODO: Is iterating backwards a good or bad idea?
				if (!lhs.get(attr) && (attr != rhs)) {
					specLhs.set(attr);
					if (!this.posCover.containsFdOrGeneralization(specLhs, rhs)) {
						this.posCover.addFunctionalDependency(specLhs, rhs);
						newFDs++;
						
						// If dynamic memory management is enabled, frequently check the memory consumption and trim the positive cover if it does not fit anymore
						this.memoryGuardian.memoryChanged(1);
						this.memoryGuardian.match(this.negCover, this.posCover, nonFds);
					}
					specLhs.clear(attr);
				}
			}
		}
	}
	return newFDs;
}
 
Example 4
Source File: FDList.java    From winter with Apache License 2.0 5 votes vote down vote up
public boolean add(OpenBitSet fd) {
	int length = (int) fd.cardinality();
	
	if ((this.maxDepth > 0) && (length > this.maxDepth))
		return false;
	
	this.depth = Math.max(this.depth, length);
	return this.fdLevels.get(length).add(fd);
}
 
Example 5
Source File: FDSet.java    From winter with Apache License 2.0 5 votes vote down vote up
public boolean add(OpenBitSet fd) {
	int length = (int) fd.cardinality();
	
	if ((this.maxDepth > 0) && (length > this.maxDepth))
		return false;
	
	this.depth = Math.max(this.depth, length);
	return this.fdLevels.get(length).add(fd);
}
 
Example 6
Source File: FDSet.java    From winter with Apache License 2.0 5 votes vote down vote up
public boolean contains(OpenBitSet fd) {
	int length = (int) fd.cardinality();
	
	if ((this.maxDepth > 0) && (length > this.maxDepth))
		return false;
	
	return this.fdLevels.get(length).contains(fd);
}
 
Example 7
Source File: FDTreeElement.java    From winter with Apache License 2.0 5 votes vote down vote up
public void addFunctionalDependenciesInto(List<FunctionalDependency> functionalDependencies, OpenBitSet lhs, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) {
	for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) {
		ColumnIdentifier[] columns = new ColumnIdentifier[(int) lhs.cardinality()];
		int j = 0;
		for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) {
			int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting
			columns[j++] = columnIdentifiers.get(columnId); 
		}
		
		ColumnCombination colCombination = new ColumnCombination(columns);
		int rhsId = plis.get(rhs).getAttribute(); // Here we translate the column rhs back to the real column rhs before the sorting
		FunctionalDependency fdResult = new FunctionalDependency(colCombination, columnIdentifiers.get(rhsId));
		functionalDependencies.add(fdResult);
	}

	if (this.getChildren() == null)
		return;
		
	for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) {
		FDTreeElement element = this.getChildren()[childAttr];
		if (element != null) {
			lhs.set(childAttr);
			element.addFunctionalDependenciesInto(functionalDependencies, lhs, columnIdentifiers, plis);
			lhs.clear(childAttr);
		}
	}
}
 
Example 8
Source File: FDTreeElement.java    From winter with Apache License 2.0 5 votes vote down vote up
public int addFunctionalDependenciesInto(FunctionalDependencyResultReceiver resultReceiver, OpenBitSet lhs, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) throws CouldNotReceiveResultException, ColumnNameMismatchException {
	int numFDs = 0;
	for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) {
		ColumnIdentifier[] columns = new ColumnIdentifier[(int) lhs.cardinality()];
		int j = 0;
		for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) {
			int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting
			columns[j++] = columnIdentifiers.get(columnId); 
		}
		
		ColumnCombination colCombination = new ColumnCombination(columns);
		int rhsId = plis.get(rhs).getAttribute(); // Here we translate the column rhs back to the real column rhs before the sorting
		FunctionalDependency fdResult = new FunctionalDependency(colCombination, columnIdentifiers.get(rhsId));
		resultReceiver.receiveResult(fdResult);
		numFDs++;
	}

	if (this.getChildren() == null)
		return numFDs;
		
	for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) {
		FDTreeElement element = this.getChildren()[childAttr];
		if (element != null) {
			lhs.set(childAttr);
			numFDs += element.addFunctionalDependenciesInto(resultReceiver, lhs, columnIdentifiers, plis);
			lhs.clear(childAttr);
		}
	}
	return numFDs;
}
 
Example 9
Source File: FDTreeElement.java    From winter with Apache License 2.0 5 votes vote down vote up
public void grow(OpenBitSet lhs, FDTree fdTree) {
	// Add specializations of all nodes an mark them as isFD, but if specialization exists, then it is invalid and should not be marked; only add specializations of nodes not marked as isFD!
	OpenBitSet rhs = this.rhsAttributes;
	
	OpenBitSet invalidRhs = rhs.clone();
	invalidRhs.remove(this.rhsFds);
	
	// Add specializations that are not invalid
	if (invalidRhs.cardinality() > 0) {
		for (int extensionAttr = 0; extensionAttr < this.numAttributes; extensionAttr++) {
			if (lhs.get(extensionAttr) || rhs.get(extensionAttr))
				continue;
			
			lhs.set(extensionAttr);
			fdTree.addFunctionalDependencyIfNotInvalid(lhs, invalidRhs);
			lhs.clear(extensionAttr);
		}
	}
	
	// Traverse children and let them add their specializations
	if (this.children != null) {
		for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) {
			FDTreeElement element = this.children[childAttr];
			if (element != null) {
				lhs.set(childAttr);
				element.grow(lhs, fdTree);
				lhs.clear(childAttr);
			}
		}
	}
}
 
Example 10
Source File: Validator.java    From winter with Apache License 2.0 4 votes vote down vote up
public ValidationResult call() throws Exception {
	ValidationResult result = new ValidationResult();
	
	FDTreeElement element = this.elementLhsPair.getElement();
	OpenBitSet lhs = this.elementLhsPair.getLhs();
	OpenBitSet rhs = element.getFds();
	
	int rhsSize = (int) rhs.cardinality();
	if (rhsSize == 0)
		return result;
	result.validations = result.validations + rhsSize;
	
	if (Validator.this.level == 0) {
		// Check if rhs is unique
		for (int rhsAttr = rhs.nextSetBit(0); rhsAttr >= 0; rhsAttr = rhs.nextSetBit(rhsAttr + 1)) {
			if (!Validator.this.plis.get(rhsAttr).isConstant(Validator.this.numRecords)) {
				element.removeFd(rhsAttr);
				result.invalidFDs.add(new FD(lhs, rhsAttr));
			}
			result.intersections++;
		}
	}
	else if (Validator.this.level == 1) {
		// Check if lhs from plis refines rhs
		int lhsAttribute = lhs.nextSetBit(0);
		for (int rhsAttr = rhs.nextSetBit(0); rhsAttr >= 0; rhsAttr = rhs.nextSetBit(rhsAttr + 1)) {
			if (!Validator.this.plis.get(lhsAttribute).refines(Validator.this.compressedRecords, rhsAttr)) {
				element.removeFd(rhsAttr);
				result.invalidFDs.add(new FD(lhs, rhsAttr));
			}
			result.intersections++;
		}
	}
	else {
		// Check if lhs from plis plus remaining inverted plis refines rhs
		int firstLhsAttr = lhs.nextSetBit(0);
		
		lhs.clear(firstLhsAttr);
		OpenBitSet validRhs = Validator.this.plis.get(firstLhsAttr).refines(Validator.this.compressedRecords, lhs, rhs, result.comparisonSuggestions);
		lhs.set(firstLhsAttr);
		
		result.intersections++;
		
		rhs.andNot(validRhs); // Now contains all invalid FDs
		element.setFds(validRhs); // Sets the valid FDs in the FD tree
		
		for (int rhsAttr = rhs.nextSetBit(0); rhsAttr >= 0; rhsAttr = rhs.nextSetBit(rhsAttr + 1))
			result.invalidFDs.add(new FD(lhs, rhsAttr));
	}
	return result;
}