Search in sources :

Example 1 with InstanceMatch

use of org.activityinfo.geoadmin.merge2.model.InstanceMatch in project activityinfo by bedatadriven.

the class MatchTableTest method resolveMatch.

@Test
public void resolveMatch() {
    // Amoron'i mania
    ResourceId sourceId = ResourceId.valueOf("MDG_adm2.7");
    // Amoron i Mania
    ResourceId targetId = ResourceId.valueOf("z0000041751");
    assertThat(waitFor(matchTable.getUnresolvedCount()), equalTo(2));
    model.getInstanceMatchSet().add(new InstanceMatch(sourceId, targetId));
    assertThat(matchTable.getUnresolvedCount().get(), equalTo(1));
    dump(matchTable);
}
Also used : InstanceMatch(org.activityinfo.geoadmin.merge2.model.InstanceMatch) ResourceId(org.activityinfo.model.resource.ResourceId) Test(org.junit.Test)

Example 2 with InstanceMatch

use of org.activityinfo.geoadmin.merge2.model.InstanceMatch in project activityinfo by bedatadriven.

the class SelectDialog method updateMatch.

private void updateMatch(int matchedIndex) {
    ResourceId fromId = keyFields.getForm(fromSide).getRowId(fromIndex);
    ResourceId toId = keyFields.getForm(fromSide.opposite()).getRowId(matchedIndex);
    InstanceMatch newMatch;
    if (fromSide == MatchSide.SOURCE) {
        newMatch = new InstanceMatch(fromId, toId);
    } else {
        newMatch = new InstanceMatch(toId, fromId);
    }
    viewModel.getModel().getInstanceMatchSet().add(newMatch);
    setVisible(false);
}
Also used : InstanceMatch(org.activityinfo.geoadmin.merge2.model.InstanceMatch) ResourceId(org.activityinfo.model.resource.ResourceId)

Example 3 with InstanceMatch

use of org.activityinfo.geoadmin.merge2.model.InstanceMatch in project activityinfo by bedatadriven.

the class SelectDialog method unmatch.

private void unmatch() {
    ResourceId resourceId = keyFields.getForm(fromSide).getRowId(fromIndex);
    InstanceMatch explicitMatch;
    if (fromSide == MatchSide.TARGET) {
        explicitMatch = new InstanceMatch(Optional.<ResourceId>absent(), Optional.of(resourceId));
    } else {
        explicitMatch = new InstanceMatch(Optional.of(resourceId), Optional.<ResourceId>absent());
    }
    viewModel.getModel().getInstanceMatchSet().add(explicitMatch);
}
Also used : InstanceMatch(org.activityinfo.geoadmin.merge2.model.InstanceMatch) ResourceId(org.activityinfo.model.resource.ResourceId)

Example 4 with InstanceMatch

use of org.activityinfo.geoadmin.merge2.model.InstanceMatch in project activityinfo by bedatadriven.

the class MatchTable method recompute.

private void recompute() {
    if (graph.isLoading() || matchSet.isLoading()) {
        return;
    }
    KeyFieldPairSet keyFields = graph.get().getKeyFields();
    MatchGraph graph = this.graph.get();
    List<MatchRow> rows = new ArrayList<>();
    Set<Integer> matchedSources = new HashSet<>();
    // Add a row for each target row
    for (int targetRow = 0; targetRow < keyFields.getTarget().getRowCount(); ++targetRow) {
        MatchRow row = new MatchRow(keyFields);
        row.setTargetRow(targetRow);
        ResourceId targetId = keyFields.getTarget().getRowId(targetRow);
        Optional<InstanceMatch> explicitMatch = matchSet.find(targetId);
        if (explicitMatch.isPresent()) {
            if (explicitMatch.get().getSourceId().isPresent()) {
                ResourceId sourceId = explicitMatch.get().getSourceId().get();
                int sourceRow = keyFields.getSource().indexOf(sourceId);
                row.setSourceRow(sourceRow);
                matchedSources.add(sourceRow);
            }
            row.setResolved(true);
            row.setInputRequired(true);
        } else {
            // Use the closest automatic match
            int sourceRow = graph.getBestMatchForTarget(targetRow);
            // another target
            if (sourceRow == MatchRow.UNMATCHED || sourceRowExplicitlyMatched(sourceRow)) {
                row.setResolved(false);
                row.setInputRequired(true);
            } else {
                row.setSourceRow(sourceRow);
                row.setResolved(true);
                matchedSources.add(sourceRow);
            }
        }
        rows.add(row);
    }
    // Add finally add an output row for each unmatched source
    for (int sourceRow = 0; sourceRow < keyFields.getSource().getRowCount(); ++sourceRow) {
        if (!matchedSources.contains(sourceRow)) {
            Optional<InstanceMatch> explicitMatch = matchSet.find(keyFields.getSource().getRowId(sourceRow));
            MatchRow row = new MatchRow(keyFields);
            row.setSourceRow(sourceRow);
            row.setInputRequired(true);
            row.setResolved(explicitMatch.isPresent());
            rows.add(row);
        }
    }
    this.rows = rows;
    fireRowsChanged();
}
Also used : InstanceMatch(org.activityinfo.geoadmin.merge2.model.InstanceMatch) ResourceId(org.activityinfo.model.resource.ResourceId) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashSet(java.util.HashSet)

Aggregations

InstanceMatch (org.activityinfo.geoadmin.merge2.model.InstanceMatch)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Test (org.junit.Test)1