1 | package com.vividsolutions.jcs.conflate.polygonmatch;
|
---|
2 |
|
---|
3 | import com.vividsolutions.jts.util.Assert;
|
---|
4 | import com.vividsolutions.jump.feature.Feature;
|
---|
5 | import com.vividsolutions.jump.task.TaskMonitor;
|
---|
6 | import java.util.Iterator;
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.SortedSet;
|
---|
9 | import java.util.TreeSet;
|
---|
10 |
|
---|
11 | class DisambiguationMatch implements Comparable {
|
---|
12 | private Feature target;
|
---|
13 | private Feature candidate;
|
---|
14 | private double score;
|
---|
15 | public double getScore() {
|
---|
16 | return score;
|
---|
17 | }
|
---|
18 |
|
---|
19 | public Feature getCandidate() {
|
---|
20 | return candidate;
|
---|
21 | }
|
---|
22 |
|
---|
23 | public Feature getTarget() {
|
---|
24 | return target;
|
---|
25 | }
|
---|
26 |
|
---|
27 | public DisambiguationMatch(Feature target, Feature candidate, double score) {
|
---|
28 | this.target = target;
|
---|
29 | this.candidate = candidate;
|
---|
30 | this.score = score;
|
---|
31 | }
|
---|
32 | @Override
|
---|
33 | public int compareTo(Object o) {
|
---|
34 | DisambiguationMatch other = (DisambiguationMatch) o;
|
---|
35 | //Highest scores first. [Jon Aquino]
|
---|
36 | if (score > other.score) { return -1; }
|
---|
37 | if (score < other.score) { return 1; }
|
---|
38 | if (target.compareTo(other.target) != 0) { return target.compareTo(other.target); }
|
---|
39 | if (candidate.compareTo(other.candidate) != 0) { return candidate.compareTo(other.candidate); }
|
---|
40 | Assert.shouldNeverReachHere("Unexpected duplicate match?");
|
---|
41 | return -1;
|
---|
42 | }
|
---|
43 | public static SortedSet createDisambiguationMatches(Map targetToMatchesMap, TaskMonitor monitor) {
|
---|
44 | TreeSet set = new TreeSet();
|
---|
45 | monitor.report("Sorting scores");
|
---|
46 | int k = 0;
|
---|
47 | for (Iterator i = targetToMatchesMap.keySet().iterator(); i.hasNext();) {
|
---|
48 | Feature target = (Feature) i.next();
|
---|
49 | Matches matches = (Matches) targetToMatchesMap.get(target);
|
---|
50 | monitor.report(++k, targetToMatchesMap.keySet().size(), "features");
|
---|
51 | for (int j = 0; j < matches.size(); j++) {
|
---|
52 | set.add(new DisambiguationMatch(target, matches.getFeature(j), matches.getScore(j)));
|
---|
53 | }
|
---|
54 | }
|
---|
55 | return set;
|
---|
56 | }
|
---|
57 | }
|
---|