Revision 2930

tmp/org.txm.tigersearch.rcp/groovy/org/txm/macro/tiger/exploit/TIGERSVOSummaryMacro.groovy (revision 2930)
102 102
	return
103 103
}
104 104
while (reader.readRecord()) {
105
	if (reader.get("mesure").length() > 0 && reader.get("valeur").length() > 0 && reader.get("requête").length() > 0) {
105 106
	test_queries << [
106 107
		reader.get("mesure"),
107 108
		reader.get("valeur"),
108 109
		reader.get("requête")
109 110
	]
111
	}
110 112
}
111 113

  
112 114
if (test_queries.size() == 0) {
......
114 116
	return null;
115 117
}
116 118

  
117
ConsoleProgressBar cpb = new ConsoleProgressBar(selection.size())
119
ConsoleProgressBar cpb = new ConsoleProgressBar(selection.size()*SVO_queries.size()*test_queries.size())
120
println "Resolving ${test_queries.size()*SVO_queries.size()} queries for ${selection.size()} corpus."
121
println "selection=$selection"
122
println "test_queries=$test_queries"
123
println "SVO_queries=$SVO_queries"
118 124

  
119 125
TIGERSearchEngine tse = SearchEnginesManager.getTIGERSearchEngine()
120 126
def results = new LinkedHashMap()
121 127
for (def corpus : selection) {
122
	cpb.tick()
123 128
	
124 129
	writer.newTable(corpus.getName())
125 130
	
......
153 158
			
154 159
			if (debug > 0) println svo_query
155 160
			
161
			cpb.tick()
162
			
156 163
			def test_result = tcorpus.manager.processQuery(svo_query, based_sentences_min_max[0], based_sentences_min_max[1], 9999999);
157 164
			if (print_queries) lineToWrite << svo_query
158 165
			if (count_sub_matches) {
tmp/org.txm.libs.office/src/org/txm/libs/office/ReadODS.java (revision 2930)
7 7

  
8 8
import org.odftoolkit.odfdom.dom.element.table.TableTableRowElement;
9 9
import org.odftoolkit.simple.SpreadsheetDocument;
10
import org.odftoolkit.simple.table.Cell;
10 11
import org.odftoolkit.simple.table.Row;
11 12
import org.odftoolkit.simple.table.Table;
12 13
import org.w3c.dom.NodeList;
......
19 20
	
20 21
	String[] headers;
21 22
	
23
	HashMap<String, String> record = null;
24
	
25
	int iRow = 0;
26
	
27
	int nRows, nCols;
28
	
22 29
	public ReadODS(File tableFile, String sheetname) throws Exception {
23 30
		spreadsheet = SpreadsheetDocument.loadDocument(tableFile);
24 31
		
......
35 42
		if (table == null) {
36 43
			table = spreadsheet.getSheetByIndex(0);
37 44
		}
45
		nRows = table.getRowCount();
46
		nCols = table.getColumnCount();
38 47
		
39 48
		// table.getRowByIndex(0);
40 49
	}
......
61 70
			}
62 71
		}
63 72
		
73
		if (iRow == 0) iRow = 1; // skip first line
64 74
		return headers.length > 0;
65 75
	}
66 76
	
......
69 79
	}
70 80
	
71 81
	public boolean readRecord() {
72
		return false;
82
		if (iRow < nRows) {
83
			_getRecord();
84
			iRow++; // for next
85
			return true;
86
		}
87
		else { // end of file
88
			record = null;
89
			return false;
90
		}
73 91
	}
74 92
	
93
	protected void _getRecord() {
94
		record = new HashMap<>();
95
		Row row = table.getRowByIndex(iRow);
96
		
97
		for (int colIndex = 0; colIndex < headers.length; colIndex++) {
98
			String col = headers[colIndex];
99
			Cell cell = row.getCellByIndex(colIndex);
100
			if (cell != null) {
101
				String value = cell.getStringValue();
102
				if (value == null) {
103
					record.put(col, "");
104
				}
105
				else {
106
					record.put(col, value);
107
				}
108
			}
109
			else {
110
				record.put(col, "");
111
			}
112
		}
113
		
114
		for (String k : record.keySet())
115
			if (record.get(k) == null) System.out.println("ERROR null value with " + k);
116
	}
117
	
75 118
	public HashMap<String, String> getRecord() {
76
		return null;
119
		return record;
77 120
	}
78 121
	
79 122
	public static ArrayList<HashMap<String, String>> toHashMap(File inputFile, String sheetname) throws Exception {
......
187 230
	}
188 231
	
189 232
	public static void main(String[] args) throws Exception {
190
		File file = new File("/home/mdecorde/xml/ruscorpora1m-test/metadata.ods");
191
		ArrayList<ArrayList<String>> table = toTable(file, "metadata");
233
		File file = new File("/home/mdecorde/Téléchargements/Requêtes_SVO-SOV.ods");
234
		ArrayList<ArrayList<String>> table = toTable(file, null);
192 235
		for (ArrayList<String> line : table) {
193
			System.out.print(line.get(0) + ", ");
236
			System.out.println(line);
194 237
		}
195 238
		// Metadatas m = new Metadatas(file, )
196 239
	}
tmp/org.txm.libs.msoffice/src/org/txm/libs/msoffice/ReadExcel.java (revision 2930)
72 72
		if (headers == null) return false;
73 73
		int colMax = headers.getLastCellNum();
74 74
		
75
		ArrayList<Integer> columnIdxToTest = new ArrayList<Integer>();
76
		ArrayList<String> columnsTest = new ArrayList<String>();
75
		ArrayList<Integer> columnIdxToTest = new ArrayList<>();
76
		ArrayList<String> columnsTest = new ArrayList<>();
77 77
		for (int colIndex = 0; colIndex < colMax; colIndex++) {
78 78
			Cell cell = headers.getCell(colIndex);
79 79
			if (cell != null) {
......
90 90
			return false;
91 91
		}
92 92
		
93
		ArrayList<Integer> removed = new ArrayList<Integer>();
93
		ArrayList<Integer> removed = new ArrayList<>();
94 94
		for (int rowIndex = 0; rowIndex < nRows; rowIndex++) {
95 95
			Row row = ws.getRow(rowIndex);
96 96
			if (row == null) continue;
......
155 155
		
156 156
		int colMax = headers.getLastCellNum();
157 157
		
158
		ArrayList<Integer> columnIdxToTest = new ArrayList<Integer>();
159
		ArrayList<Integer> columnIdxToWrite = new ArrayList<Integer>();
160
		ArrayList<String> columns = new ArrayList<String>();
161
		ArrayList<String> columnsTest = new ArrayList<String>();
158
		ArrayList<Integer> columnIdxToTest = new ArrayList<>();
159
		ArrayList<Integer> columnIdxToWrite = new ArrayList<>();
160
		ArrayList<String> columns = new ArrayList<>();
161
		ArrayList<String> columnsTest = new ArrayList<>();
162 162
		for (int colIndex = 0; colIndex < colMax; colIndex++) {
163 163
			Cell cell = headers.getCell(colIndex);
164 164
			if (cell != null) {
......
182 182
		
183 183
		if (columnIdxToWrite.size() != columnsSelection.size()) {
184 184
			System.out.println("Error: not all columns found=" + columnIdxToWrite + " of " + columnsSelection);
185
			ArrayList<String> notFound = new ArrayList<String>(columnsSelection);
185
			ArrayList<String> notFound = new ArrayList<>(columnsSelection);
186 186
			notFound.removeAll(columns);
187 187
			System.out.println("NOT FOUND: " + notFound);
188 188
			return false;
......
307 307
	}
308 308
	
309 309
	protected void _getRecord() {
310
		record = new HashMap<String, String>();
310
		record = new HashMap<>();
311 311
		Row row = ws.getRow(iRow);
312 312
		
313 313
		for (int colIndex = 0; colIndex < header.length; colIndex++) {
......
316 316
			if (cell != null) {
317 317
				String value = cellToString(cell).trim();
318 318
				if (value == null) {
319
					record.put(header[colIndex], "");
319
					record.put(col, "");
320 320
				}
321 321
				else {
322
					record.put(header[colIndex], value);
322
					record.put(col, value);
323 323
				}
324 324
			}
325 325
			else {
326
				record.put(header[colIndex], "");
326
				record.put(col, "");
327 327
			}
328 328
		}
329 329
		
......
343 343
	 */
344 344
	public static ArrayList<ArrayList<String>> toTable(File inputFile, String sheetName) {
345 345
		
346
		ArrayList<ArrayList<String>> data = new ArrayList<ArrayList<String>>();
346
		ArrayList<ArrayList<String>> data = new ArrayList<>();
347 347
		
348 348
		if (!inputFile.canRead()) {
349 349
			System.out.println("** Excel2XML: '" + inputFile.getName() + "' file not readable. Aborting.");
......
374 374
			Row firstRow = ws.getRow(0);
375 375
			int colMax = firstRow.getLastCellNum();
376 376
			
377
			ArrayList<String> headers = new ArrayList<String>();
377
			ArrayList<String> headers = new ArrayList<>();
378 378
			for (int it = 0; it < colMax; it++) {
379 379
				headers.add(firstRow.getCell(it).getStringCellValue());
380 380
			}
381 381
			
382 382
			for (int rowIndex = 0; rowIndex < nRows; rowIndex++) {
383 383
				Row row = ws.getRow(rowIndex);
384
				ArrayList<String> dataLine = new ArrayList<String>();
384
				ArrayList<String> dataLine = new ArrayList<>();
385 385
				data.add(dataLine);
386 386
				for (int colIndex = 0; colIndex < colMax; colIndex++) {
387 387
					Cell cell = row.getCell(colIndex);
......
438 438
		}
439 439
	}
440 440
	
441
	
441 442
	public static void main(String[] args) throws Exception {
443
		File tableFile = new File("/home/mdecorde/Téléchargements/Requêtes_SVO-SOV.xlsx");
444
		// ReadExcel excel = new ReadExcel(tableFile, null);
445
		ArrayList<ArrayList<String>> table = ReadExcel.toTable(tableFile, null);
446
		for (ArrayList<String> line : table) {
447
			System.out.println(line);
448
		}
449
	}
450
	
451
	public static void mainAF(String[] args) throws Exception {
442 452
		// ArrayList<ArrayList<String>> data = toTable(new File("/home/mdecorde/xml/ruscorpora1m-test/metadata.xlsx"), null);
443 453
		// if (data.size() == 0) {
444 454
		// System.out.println("no data.");
......
452 462
		System.out.println("open...");
453 463
		ReadExcel excel = new ReadExcel(tableFile, null);
454 464
		
455
		HashMap<String, String> lineRules = new HashMap<String, String>(); // line tests to select line to keep
465
		HashMap<String, String> lineRules = new HashMap<>(); // line tests to select line to keep
456 466
		List<String> columnsSelection; // list of columns to keep
457
		HashMap<String, String> columnsToCopy = new HashMap<String, String>();
458
		HashMap<String, String> columnsToRenameRules = new HashMap<String, String>();
459
		HashMap<String, String[]> searchAndReplaceRules = new HashMap<String, String[]>();
467
		HashMap<String, String> columnsToCopy = new HashMap<>();
468
		HashMap<String, String> columnsToRenameRules = new HashMap<>();
469
		HashMap<String, String[]> searchAndReplaceRules = new HashMap<>();
460 470
		// //emissions
461
//		 table2File = new File("/home/mdecorde/TEMP/ANTRACT/AF/emissions.xlsx");
462
//		 columnsSelection = Arrays.asList(
463
//		 "Identifiant de la notice", "Titre propre", "Notes du titre", "Date de diffusion", "Durée", "Nom fichier segmenté (info)", "antract_video",
464
//		 "antract_debut","antract_fin","antract_duree","antract_tc_type","antract_tc_date");
465
//		 lineRules.put("Type de notice", "Notice sommaire");
466
//		 columnsToRenameRules.put("Identifiant de la notice", "id");
467
//		 
468
//		 columnsToCopy.put("Notes du titre", "subtitle"); // not working yet
469
//		 columnsToCopy.put("Titre propre", "title"); // not working yet
470
//		 columnsToCopy.put("Date de diffusion", "textorder"); // not working yet
471
//		 searchAndReplaceRules.put("textorder", new String[] {"../../....", "$3$2$1"}); // not working yet
471
		// table2File = new File("/home/mdecorde/TEMP/ANTRACT/AF/emissions.xlsx");
472
		// columnsSelection = Arrays.asList(
473
		// "Identifiant de la notice", "Titre propre", "Notes du titre", "Date de diffusion", "Durée", "Nom fichier segmenté (info)", "antract_video",
474
		// "antract_debut","antract_fin","antract_duree","antract_tc_type","antract_tc_date");
475
		// lineRules.put("Type de notice", "Notice sommaire");
476
		// columnsToRenameRules.put("Identifiant de la notice", "id");
477
		//
478
		// columnsToCopy.put("Notes du titre", "subtitle"); // not working yet
479
		// columnsToCopy.put("Titre propre", "title"); // not working yet
480
		// columnsToCopy.put("Date de diffusion", "textorder"); // not working yet
481
		// searchAndReplaceRules.put("textorder", new String[] {"../../....", "$3$2$1"}); // not working yet
472 482
		
473 483
		// sujets
474 484
		table2File = new File("/home/mdecorde/TEMP/ANTRACT/AF/sujets.xlsx");
......
487 497
		}
488 498
		
489 499
		System.out.println("copying column: " + columnsToCopy.size());
490
		//excel2.copyColumns(columnsToCopy);
500
		// excel2.copyColumns(columnsToCopy);
491 501
		
492 502
		System.out.println("search&replace column: " + searchAndReplaceRules.size());
493
		//excel2.searchAndReplaceInLines(searchAndReplaceRules);
503
		// excel2.searchAndReplaceInLines(searchAndReplaceRules);
494 504
		
495 505
		System.out.println("renaming column: " + columnsToRenameRules.size());
496 506
		excel2.renameColumns(columnsToRenameRules);

Also available in: Unified diff