svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src-test / org / gvsig / geocoding / dataaccess / TestDataAccessTest.java @ 32479
History | View | Annotate | Download (7.32 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L vsanjaime programador
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.dataaccess; |
29 |
|
30 |
import junit.framework.TestCase; |
31 |
|
32 |
import org.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
|
36 |
/**
|
37 |
* Test
|
38 |
*
|
39 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
40 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
41 |
*/
|
42 |
public class TestDataAccessTest extends TestCase { |
43 |
|
44 |
private static final Logger log = LoggerFactory |
45 |
.getLogger(TestDataAccessTest.class); |
46 |
//
|
47 |
// File dbfFile = new File(
|
48 |
// "src-test/org/gvsig/geocoding/geocoding/dataaccess/067.dbf");
|
49 |
//
|
50 |
// EditableAdapter source = new EditableAdapter();
|
51 |
// DBFDriver driver = null;
|
52 |
// FileDataSource fiDatSource = null;
|
53 |
// SelectableDataSource selDaSource = null;
|
54 |
//
|
55 |
// int umbral = 70;
|
56 |
// int max = 5;
|
57 |
//
|
58 |
// public void setUp() {
|
59 |
//
|
60 |
// try {
|
61 |
//
|
62 |
// driver = new DBFDriver();
|
63 |
// driver.open(dbfFile);
|
64 |
//
|
65 |
// fiDatSource = FileDataSourceFactory.newInstance();
|
66 |
// fiDatSource.setDriver(driver);
|
67 |
// FileSourceInfo fsi = new FileSourceInfo();
|
68 |
// fsi.file = dbfFile.getAbsolutePath();
|
69 |
// fsi.name = dbfFile.getName();
|
70 |
// fiDatSource.setSourceInfo(fsi);
|
71 |
//
|
72 |
// SelectableDataSource selDaSource = new SelectableDataSource(
|
73 |
// fiDatSource);
|
74 |
//
|
75 |
// source.setOriginalDataSource(selDaSource);
|
76 |
// source.startEdition(EditionEvent.GRAPHIC);
|
77 |
//
|
78 |
// } catch (Exception e) {
|
79 |
// log.error("Reading the driver", e);
|
80 |
// }
|
81 |
//
|
82 |
// }
|
83 |
//
|
84 |
// // public void testDataAccess() {
|
85 |
// //
|
86 |
// // String sample = "brahams";
|
87 |
// //
|
88 |
// // ArrayList<Integer> registro = new ArrayList<Integer>();
|
89 |
// // ArrayList<Integer> distancia = new ArrayList<Integer>();
|
90 |
// //
|
91 |
// // Value[] values = null;
|
92 |
// //
|
93 |
// // try {
|
94 |
// // int num = (int) source.getRowCount();
|
95 |
// // int dis;
|
96 |
// // for (int i = 0; i < num; i++) {
|
97 |
// //
|
98 |
// // values = source.getRow(i).getAttributes();
|
99 |
// // String strTemp = values[1].toString();
|
100 |
// //
|
101 |
// // if (strTemp.indexOf(sample) > 0) {
|
102 |
// // dis = LevenshteinDistance.computeLevenshteinDistance(
|
103 |
// // strTemp, sample);
|
104 |
// // registro.add(Integer.valueOf(i));
|
105 |
// // distancia.add(Integer.valueOf(dis));
|
106 |
// // }
|
107 |
// //
|
108 |
// // }
|
109 |
// // } catch (Exception e) {
|
110 |
// // log.error("Reading driver", e);
|
111 |
// // }
|
112 |
// //
|
113 |
// // System.out.println("Number: " + registro.size());
|
114 |
// // for (int i = 0; i < registro.size(); i++) {
|
115 |
// // System.out.println("Registro n?: " + registro.get(i)
|
116 |
// // + " Distancia: " + distancia.get(i));
|
117 |
// // }
|
118 |
// // System.out.println("FIN");
|
119 |
// //
|
120 |
// // }
|
121 |
//
|
122 |
// public void testDataAccess() {
|
123 |
//
|
124 |
// ArrayList<Integer> campos = new ArrayList<Integer>();
|
125 |
// campos.add(1);
|
126 |
// campos.add(2);
|
127 |
// campos.add(7);
|
128 |
// campos.add(8);
|
129 |
// campos.add(14);
|
130 |
// campos.add(17);
|
131 |
//
|
132 |
// ArrayList<String> cad1 = new ArrayList<String>();
|
133 |
// cad1.add("Bradford");
|
134 |
// cad1.add("brad");
|
135 |
// cad1.add("lk");
|
136 |
// cad1.add("ca");
|
137 |
// cad1.add("0");
|
138 |
// cad1.add("montreal");
|
139 |
// ArrayList<String> cad2 = new ArrayList<String>();
|
140 |
// cad2.add("lake");
|
141 |
// cad2.add("lake");
|
142 |
// cad2.add("lk");
|
143 |
// cad2.add("ca");
|
144 |
// cad2.add("0");
|
145 |
// cad2.add("white");
|
146 |
// ArrayList<String> cad3 = new ArrayList<String>();
|
147 |
// cad3.add("indian");
|
148 |
// cad3.add("indi");
|
149 |
// cad3.add("pt");
|
150 |
// cad3.add("ca");
|
151 |
// cad3.add("0");
|
152 |
// cad3.add("johns");
|
153 |
// ArrayList<String> cad4 = new ArrayList<String>();
|
154 |
// cad4.add("sanders");
|
155 |
// cad4.add("sanders");
|
156 |
// cad4.add("stm");
|
157 |
// cad4.add("ca");
|
158 |
// cad4.add("0");
|
159 |
// cad4.add("winni");
|
160 |
// ArrayList<String> cad5 = new ArrayList<String>();
|
161 |
// cad5.add("triple");
|
162 |
// cad5.add("triple");
|
163 |
// cad5.add("lk");
|
164 |
// cad5.add("ca");
|
165 |
// cad5.add("0");
|
166 |
// cad5.add("toronto");
|
167 |
//
|
168 |
// ArrayList<ArrayList<String>> cadenas = new
|
169 |
// ArrayList<ArrayList<String>>();
|
170 |
// cadenas.add(cad1);
|
171 |
// cadenas.add(cad2);
|
172 |
// cadenas.add(cad3);
|
173 |
// cadenas.add(cad4);
|
174 |
// cadenas.add(cad5);
|
175 |
//
|
176 |
// ArrayList<ResultSearch> res = goSearch(source, cad1, campos, umbral,
|
177 |
// max);
|
178 |
//
|
179 |
// // ----------------
|
180 |
// if (res != null) {
|
181 |
// System.out.println("Number: " + res.size());
|
182 |
// for (int i = 0; i < res.size(); i++) {
|
183 |
// System.out.println("Registro n?: " + res.get(i).getNRow());
|
184 |
// }
|
185 |
// }
|
186 |
//
|
187 |
// System.out.println("FIN");
|
188 |
//
|
189 |
// }
|
190 |
//
|
191 |
// public void tearDown() {
|
192 |
// try {
|
193 |
// driver.close();
|
194 |
// } catch (CloseDriverException e) {
|
195 |
// e.printStackTrace();
|
196 |
// }
|
197 |
// }
|
198 |
//
|
199 |
// /*------------------------------------------------------- */
|
200 |
//
|
201 |
// private ArrayList<ResultSearch> goSearch(IEditableSource source,
|
202 |
// ArrayList<String> cadenas, ArrayList<Integer> campos, int umbral,
|
203 |
// int max) {
|
204 |
//
|
205 |
// ArrayList<ResultSearch> results = new ArrayList<ResultSearch>();
|
206 |
//
|
207 |
// Value[] values = null;
|
208 |
// ResultSearch reg = null;
|
209 |
//
|
210 |
// int i = 0;
|
211 |
// try {
|
212 |
// for (i = 0; i < (int) source.getRowCount(); i++) {
|
213 |
// if (i == 6280) {
|
214 |
// System.out.println("");
|
215 |
// }
|
216 |
// values = source.getRow(i).getAttributes();
|
217 |
// reg = searchInRow(i, values, cadenas, campos, umbral);
|
218 |
// if (reg != null) {
|
219 |
// results.add(reg);
|
220 |
// }
|
221 |
// }
|
222 |
// } catch (Exception e) {
|
223 |
// log.error("Error in file: " + i);
|
224 |
// log.error("Reading driver", e);
|
225 |
// }
|
226 |
//
|
227 |
// return results;
|
228 |
// }
|
229 |
//
|
230 |
// private ResultSearch searchInRow(int nRow, Value[] vals,
|
231 |
// ArrayList<String> strs, ArrayList<Integer> fields, int threshold) {
|
232 |
//
|
233 |
// String original;
|
234 |
// String temp;
|
235 |
//
|
236 |
// ResultSearch result = new ResultSearch(nRow, strs.size());
|
237 |
//
|
238 |
// for (int i = 0; i < strs.size(); i++) {
|
239 |
//
|
240 |
// original = strs.get(i).toUpperCase().trim();
|
241 |
// temp = vals[(fields.get(i)).intValue()].toString().toUpperCase()
|
242 |
// .trim();
|
243 |
//
|
244 |
// int distance = searchInElement(original, temp);
|
245 |
// result.setNRow(nRow);
|
246 |
// result.getPairs().put(fields.get(i), distance);
|
247 |
// if (distance == -1) {
|
248 |
// result.lessMath();
|
249 |
// }
|
250 |
// }
|
251 |
// if (result.getMatch() > threshold) {
|
252 |
// return result;
|
253 |
// }
|
254 |
// return null;
|
255 |
// }
|
256 |
//
|
257 |
// private int searchInElement(String oriStr, String str) {
|
258 |
// int distance = -1;
|
259 |
//
|
260 |
// if (oriStr.indexOf(str) > 0 || oriStr.matches(str)
|
261 |
// || oriStr.startsWith(str) || oriStr.endsWith(str)) {
|
262 |
// // exists value in field
|
263 |
// // calculate distance between strings
|
264 |
// distance = LevenshteinDistance.getLevenshteinDistance(
|
265 |
// oriStr.trim(), str.trim());
|
266 |
// }
|
267 |
// return distance;
|
268 |
// }
|
269 |
|
270 |
} |