Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for partial dependencies #441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.algorithm_types;

import de.metanome.algorithm_integration.Algorithm;
import de.metanome.algorithm_integration.result_receiver.PartialFunctionalDependencyResultReceiver;

/**
* An {@link Algorithm} that discovers partial functional dependencies.
*
*/
public interface PartialFunctionalDependencyAlgorithm extends Algorithm {

/**
* Sets a {@link PartialFunctionalDependencyResultReceiver} to send the results to.
*
* @param resultReceiver the result receiver the algorithm sents found {@link
* de.metanome.algorithm_integration.results.PartialFunctionalDependency}s to.
*/
void setResultReceiver(PartialFunctionalDependencyResultReceiver resultReceiver);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.algorithm_types;

import de.metanome.algorithm_integration.Algorithm;
import de.metanome.algorithm_integration.result_receiver.PartialInclusionDependencyResultReceiver;

/**
* An {@link Algorithm} that discovers partial inclusion dependencies.
*
*/
public interface PartialInclusionDependencyAlgorithm extends Algorithm {

/**
* Sets a {@link PartialInclusionDependencyResultReceiver} to send the results to.
*
* @param resultReceiver the result receiver the algorithm sents found {@link
* de.metanome.algorithm_integration.results.PartialInclusionDependency}s to.
*/
void setResultReceiver(PartialInclusionDependencyResultReceiver resultReceiver);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.algorithm_types;

import de.metanome.algorithm_integration.Algorithm;
import de.metanome.algorithm_integration.result_receiver.PartialUniqueColumnCombinationResultReceiver;

/**
* An {@link de.metanome.algorithm_integration.Algorithm} that discovers partial unique {@link
* de.metanome.algorithm_integration.ColumnCombination}s.
*
*/
public interface PartialUniqueColumnCombinationAlgorithm extends Algorithm {

/**
* Sets a {@link de.metanome.algorithm_integration.result_receiver.PartialUniqueColumnCombinationResultReceiver}
* to send the results to.
*
* @param resultReceiver the result receiver for {@link de.metanome.algorithm_integration.results.PartialUniqueColumnCombination}s
*/
void setResultReceiver(PartialUniqueColumnCombinationResultReceiver resultReceiver);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014-2017 by Metanome Project
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,9 @@ public interface OmniscientResultReceiver extends
ConditionalUniqueColumnCombinationResultReceiver,
OrderDependencyResultReceiver,
MultivaluedDependencyResultReceiver,
DenialConstraintResultReceiver {
DenialConstraintResultReceiver,
PartialFunctionalDependencyResultReceiver,
PartialInclusionDependencyResultReceiver,
PartialUniqueColumnCombinationResultReceiver{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.result_receiver;

import de.metanome.algorithm_integration.algorithm_types.PartialFunctionalDependencyAlgorithm;
import de.metanome.algorithm_integration.results.PartialFunctionalDependency;

/**
* Receives the results of a {@link PartialFunctionalDependencyAlgorithm}.
*/
public interface PartialFunctionalDependencyResultReceiver {

/**
* Receives a {@link PartialFunctionalDependency} from a {@link PartialFunctionalDependencyAlgorithm}.
*
* @param partialFunctionalDependency a found {@link PartialFunctionalDependency}
* @throws CouldNotReceiveResultException if no result could be received
* @throws ColumnNameMismatchException if the column names of the result does not match the column names of the input
*/
void receiveResult(PartialFunctionalDependency partialFunctionalDependency)
throws CouldNotReceiveResultException, ColumnNameMismatchException;

/**
* Check if the table/column names of the given result are equal to those in the input.
*
* @param result the result
* @return true, if the names are accepted, false otherwise
*/
Boolean acceptedResult(PartialFunctionalDependency result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.result_receiver;

import de.metanome.algorithm_integration.algorithm_types.PartialInclusionDependencyAlgorithm;
import de.metanome.algorithm_integration.results.PartialInclusionDependency;

/**
* Receives the results of a {@link PartialInclusionDependencyAlgorithm}.
*/
public interface PartialInclusionDependencyResultReceiver {

/**
* Receives a {@link PartialInclusionDependency} from a {@link PartialInclusionDependencyAlgorithm}.
*
* @param partialDependency a found {@link de.metanome.algorithm_integration.results.PartialInclusionDependency}
* @throws de.metanome.algorithm_integration.result_receiver.CouldNotReceiveResultException if no result could be received
* @throws ColumnNameMismatchException if the column names of the result does not match the column names of the input
*/
void receiveResult(PartialInclusionDependency partialDependency)
throws CouldNotReceiveResultException, ColumnNameMismatchException;

/**
* Check if the table/column names of the given result are equal to those in the input.
*
* @param result the result
* @return true, if the names are accepted, false otherwise
*/
Boolean acceptedResult(PartialInclusionDependency result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.result_receiver;

import de.metanome.algorithm_integration.results.PartialUniqueColumnCombination;

/**
* Receives the results of a {@link de.metanome.algorithm_integration.algorithm_types.PartialUniqueColumnCombinationAlgorithm}.
*/
public interface PartialUniqueColumnCombinationResultReceiver {

/**
* Receives a {@link de.metanome.algorithm_integration.results.PartialUniqueColumnCombination}
* from a {@link de.metanome.algorithm_integration.algorithm_types.PartialUniqueColumnCombinationAlgorithm}.
*
* @param partialUniqueColumnCombination a found {@link de.metanome.algorithm_integration.results.UniqueColumnCombination}
* @throws CouldNotReceiveResultException if the unique column combination could not be received
* @throws ColumnNameMismatchException if the column names of the result does not match the column names of the input
*/
void receiveResult(PartialUniqueColumnCombination partialUniqueColumnCombination)
throws CouldNotReceiveResultException, ColumnNameMismatchException;

/**
* Check if the table/column names of the given result are equal to those in the input.
*
* @param result the result
* @return true, if the names are accepted, false otherwise
*/
Boolean acceptedResult(PartialUniqueColumnCombination result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Copyright 2014-2025 by Metanome Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.metanome.algorithm_integration.results;

import com.fasterxml.jackson.annotation.JsonTypeName;
import de.metanome.algorithm_integration.ColumnCombination;
import de.metanome.algorithm_integration.ColumnIdentifier;
import de.metanome.algorithm_integration.result_receiver.ColumnNameMismatchException;
import de.metanome.algorithm_integration.result_receiver.CouldNotReceiveResultException;
import de.metanome.algorithm_integration.result_receiver.OmniscientResultReceiver;

import javax.xml.bind.annotation.XmlTransient;
import java.util.Map;
import java.util.Objects;

@JsonTypeName("PartialFunctionalDependency")
public class PartialFunctionalDependency extends FunctionalDependency {

public static final String TABLEAU_SEPARATOR = "#";
private static final long serialVersionUID = 7625466610666776666L;
protected Double measure;

public PartialFunctionalDependency() {
super();
this.measure = 1d;
}

public PartialFunctionalDependency(ColumnCombination determinant,
ColumnIdentifier dependant,
Double measure) {
super(determinant, dependant);
this.measure = measure;
}

public Double getMeasure() {
return measure;
}

public void setMeasure(Double measure) {
this.measure = measure;
}

@Override
@XmlTransient
public void sendResultTo(OmniscientResultReceiver resultReceiver)
throws CouldNotReceiveResultException, ColumnNameMismatchException {
resultReceiver.receiveResult(this);
}

@Override
public String toString() {
return determinant.toString() + FD_SEPARATOR + dependant.toString() + TABLEAU_SEPARATOR + measure;
}

/**
* Encodes the partial functional dependency as string with the given mappings.
* @param tableMapping the table mapping
* @param columnMapping the column mapping
* @return the string
*/
public String toString(Map<String, String> tableMapping, Map<String, String> columnMapping) {
return determinant.toString(tableMapping, columnMapping) + FD_SEPARATOR +
dependant.toString(tableMapping, columnMapping) + TABLEAU_SEPARATOR + measure;
}

/**
* Creates a partial functional dependency from the given string using the given mapping.
* @param tableMapping the table mapping
* @param columnMapping the column mapping
* @param str the string
* @return a functional dependency
*/
public static PartialFunctionalDependency fromString(Map<String, String> tableMapping, Map<String, String> columnMapping, String str)
throws NullPointerException, IndexOutOfBoundsException {
String[] parts = str.split(FD_SEPARATOR);
ColumnCombination determinant = ColumnCombination.fromString(tableMapping, columnMapping, parts[0]);
parts = parts[1].split(TABLEAU_SEPARATOR);
ColumnIdentifier dependant = ColumnIdentifier.fromString(tableMapping, columnMapping, parts[0]);
Double measure = Double.valueOf(parts[1]);

return new PartialFunctionalDependency(determinant, dependant, measure);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PartialFunctionalDependency that = (PartialFunctionalDependency) o;

if (!Objects.equals(determinant, that.determinant)) return false;
if (!Objects.equals(dependant, that.dependant)) return false;
return Objects.equals(measure, that.measure);
}

@Override
public int hashCode() {
int result = determinant != null ? determinant.hashCode() : 0;
result = 31 * result + (dependant != null ? dependant.hashCode() : 0);
result = 31 * result + (measure != null ? measure.hashCode() : 0);
return result;
}
}
Loading