Search in sources :

Example 1 with ScoreMatrix

use of org.activityinfo.geoadmin.match.ScoreMatrix in project activityinfo by bedatadriven.

the class KeyFieldPairSet method matchKeys.

/**
 * Constructs a {@code KeyFieldPairSet} from a source and target form by matching columns with similar
 * sets of values.
 */
public static KeyFieldPairSet matchKeys(FormProfile source, FormProfile target) {
    ScoreMatrix scoreMatrix = new FieldScoreMatrix(source.getFields(), target.getFields());
    dumpScoreMatrix(source, target, scoreMatrix);
    MatchGraph matchGraph = new MatchGraph(scoreMatrix);
    matchGraph.build();
    BiMap<FieldProfile, FieldProfile> targetToSource = HashBiMap.create();
    for (int sourceColumnIndex = 0; sourceColumnIndex != scoreMatrix.getRowCount(); ++sourceColumnIndex) {
        int targetColumnIndex = matchGraph.getBestMatchForSource(sourceColumnIndex);
        if (targetColumnIndex != -1) {
            FieldProfile sourceColumn = source.getFields().get(sourceColumnIndex);
            FieldProfile targetColumn = target.getFields().get(targetColumnIndex);
            targetToSource.put(targetColumn, sourceColumn);
            System.out.println("Matching FIELD " + sourceColumn.getLabel() + " => " + targetColumn.getLabel());
        }
    }
    return new KeyFieldPairSet(source, target, targetToSource);
}
Also used : ScoreMatrix(org.activityinfo.geoadmin.match.ScoreMatrix) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)

Aggregations

ScoreMatrix (org.activityinfo.geoadmin.match.ScoreMatrix)1 FieldProfile (org.activityinfo.geoadmin.merge2.view.profile.FieldProfile)1