1 | package org.greenstone.atlas.server;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 |
|
---|
6 | import org.greenstone.atlas.client.Place;
|
---|
7 | import org.greenstone.atlas.server.ServerPlace;
|
---|
8 |
|
---|
9 | public class ScanResultSet
|
---|
10 | {
|
---|
11 | HashMap<String, ServerPlace> _resultSet = new HashMap<String, ServerPlace>();
|
---|
12 | String _name = null;
|
---|
13 |
|
---|
14 | /*
|
---|
15 | public ScanResultSet(String name, ArrayList<ServerPlace> results, Object nothing)
|
---|
16 | {
|
---|
17 | _name = name;
|
---|
18 | for(ServerPlace p : results)
|
---|
19 | {
|
---|
20 | if(_resultSet.containsKey(p.getName()))
|
---|
21 | {
|
---|
22 | ServerPlace old = _resultSet.get(p.getName());
|
---|
23 | if (p.getScore() > old.getScore())
|
---|
24 | {
|
---|
25 | _resultSet.put(p.getName(), p);
|
---|
26 | }
|
---|
27 | }
|
---|
28 | else
|
---|
29 | {
|
---|
30 | _resultSet.put(p.getName(), p);
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
34 | */
|
---|
35 | public ScanResultSet(String name, ArrayList<Place> results)
|
---|
36 | {
|
---|
37 | _name = name;
|
---|
38 | for(Place p : results)
|
---|
39 | {
|
---|
40 | if(_resultSet.containsKey(p.getName()))
|
---|
41 | {
|
---|
42 | ServerPlace old = _resultSet.get(p.getName());
|
---|
43 | if (p.getScore() > old.getScore())
|
---|
44 | {
|
---|
45 | _resultSet.put(p.getName(), ServerPlace.convert(p));
|
---|
46 | }
|
---|
47 | else if(p.getScore() == old.getScore())
|
---|
48 | {
|
---|
49 | if(p.getPopulation() > old.getPopulation())
|
---|
50 | {
|
---|
51 | _resultSet.put(p.getName(), ServerPlace.convert(p));
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 | else
|
---|
56 | {
|
---|
57 | _resultSet.put(p.getName(), ServerPlace.convert(p));
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public ScanResultSet(String name, Long[] ids)
|
---|
63 | {
|
---|
64 | _name = name;
|
---|
65 | for(int i = 0; i < ids.length; i++)
|
---|
66 | {
|
---|
67 | // if(i >= ids.length)
|
---|
68 | // {
|
---|
69 | // return;
|
---|
70 | // }
|
---|
71 |
|
---|
72 | ServerPlace p = ServerPlace.createPlaceFromId(ids[i]);
|
---|
73 |
|
---|
74 | if(PlaceInformation.getPlaces(p.getName()).size() > 1)
|
---|
75 | {
|
---|
76 | _resultSet.put(p.getName(), p);
|
---|
77 | }
|
---|
78 | //_resultSet.put(p.getName(), p);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public int[] compareResults (ScanResultSet otherResults)
|
---|
83 | {
|
---|
84 | if(otherResults == null)
|
---|
85 | {
|
---|
86 | return null;
|
---|
87 | }
|
---|
88 |
|
---|
89 | int count = 0;
|
---|
90 | int total = 0;
|
---|
91 | for(String s : _resultSet.keySet())
|
---|
92 | {
|
---|
93 | if(otherResults.getResult(s) != null && otherResults.getResult(s).equals(_resultSet.get(s)))
|
---|
94 | {
|
---|
95 | count++;
|
---|
96 | }
|
---|
97 | else
|
---|
98 | {
|
---|
99 | if(otherResults.getResult(s) != null)
|
---|
100 | {
|
---|
101 | //System.out.println(_resultSet.get(s).getName() + ", " + _resultSet.get(s).getParentPlaceName() + " (" + _resultSet.get(s).getScore() + ") != " + otherResults.getResult(s).getName() + ", " + otherResults.getResult(s).getParentPlaceName() + " (" + otherResults.getResult(s).getScore() + ")");
|
---|
102 | }
|
---|
103 | else
|
---|
104 | {
|
---|
105 | //System.out.println(_resultSet.get(s).getName() + ", " + _resultSet.get(s).getParentPlaceName() + " != " + otherResults.getResult(s));
|
---|
106 | }
|
---|
107 | }
|
---|
108 | total++;
|
---|
109 | }
|
---|
110 |
|
---|
111 | System.out.println("Result = " + count + "/" + total);
|
---|
112 |
|
---|
113 | return new int[]{count, total};
|
---|
114 | }
|
---|
115 |
|
---|
116 | public ServerPlace getResult(String key)
|
---|
117 | {
|
---|
118 | return _resultSet.get(key);
|
---|
119 | }
|
---|
120 |
|
---|
121 | public String getName()
|
---|
122 | {
|
---|
123 | return _name;
|
---|
124 | }
|
---|
125 |
|
---|
126 | public void updateScores(ArrayList<Place> places)
|
---|
127 | {
|
---|
128 | for(String s : _resultSet.keySet())
|
---|
129 | {
|
---|
130 | for(int i = 0; i < places.size(); i++)
|
---|
131 | {
|
---|
132 | if(_resultSet.get(s).equals(places.get(i)) && _resultSet.get(s).getScore() < places.get(i).getScore())
|
---|
133 | {
|
---|
134 | _resultSet.get(s).setScore(places.get(i).getScore());
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|