44 |
44 |
* Current page.
|
45 |
45 |
*/
|
46 |
46 |
@Parameter(key=InternalViewPreferences.CURRENT_PAGE)
|
47 |
|
protected int currentPage;
|
|
47 |
protected int pCurrentPage;
|
48 |
48 |
|
49 |
49 |
/**
|
50 |
50 |
* Structural unit to explore.
|
51 |
51 |
*/
|
52 |
52 |
@Parameter(key=TXMPreferences.STRUCTURAL_UNIT)
|
53 |
|
protected StructuralUnit structuralUnit;
|
|
53 |
protected StructuralUnit pStructuralUnit;
|
54 |
54 |
|
55 |
55 |
/**
|
56 |
56 |
* Word properties to display.
|
57 |
57 |
*/
|
58 |
58 |
@Parameter(key=TXMPreferences.UNIT_PROPERTIES)
|
59 |
|
protected List<WordProperty> wordProperties;
|
|
59 |
protected List<WordProperty> pWordProperties;
|
60 |
60 |
|
61 |
61 |
/**
|
62 |
62 |
* Structural units to display.
|
63 |
63 |
*/
|
64 |
64 |
@Parameter(key=TXMPreferences.STRUCTURAL_UNIT_PROPERTIES)
|
65 |
|
protected List<StructuralUnitProperty> structuralUnitsProperties;
|
|
65 |
protected List<StructuralUnitProperty> pStructuralUnitsProperties;
|
66 |
66 |
|
67 |
67 |
|
68 |
68 |
/**
|
... | ... | |
86 |
86 |
@Override
|
87 |
87 |
public boolean loadParameters() throws Exception {
|
88 |
88 |
try {
|
89 |
|
this.structuralUnit = this.getCorpus().getStructuralUnit(this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT));
|
90 |
|
this.wordProperties = (List<WordProperty>) Property.stringToProperties(this.getCorpus(), this.getStringParameterValue(TXMPreferences.UNIT_PROPERTIES));
|
91 |
|
this.structuralUnitsProperties = StructuralUnitProperty.stringToProperties(this.getCorpus(), this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT_PROPERTIES));
|
|
89 |
String str = this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT);
|
|
90 |
this.pStructuralUnit = this.getCorpus().getStructuralUnit(str);
|
|
91 |
str = this.getStringParameterValue(TXMPreferences.UNIT_PROPERTIES);
|
|
92 |
this.pWordProperties = (List<WordProperty>) Property.stringToProperties(this.getCorpus(), str);
|
|
93 |
str = this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT_PROPERTIES);
|
|
94 |
this.pStructuralUnitsProperties = StructuralUnitProperty.stringToProperties(this.getCorpus(), str);
|
92 |
95 |
} catch (CqiClientException e) {
|
93 |
96 |
Log.printStackTrace(e);
|
94 |
97 |
return false;
|
... | ... | |
101 |
104 |
protected boolean _compute() throws Exception {
|
102 |
105 |
|
103 |
106 |
if(this.hasParameterChanged(InternalViewPreferences.STRUCTURAL_UNIT)) {
|
104 |
|
this.currentPage = 0;
|
|
107 |
this.pCurrentPage = 0;
|
105 |
108 |
//find struct start-end
|
106 |
|
Query query = new Query("<" + structuralUnit.getName() + "> [] expand to " + structuralUnit); //$NON-NLS-1$ //$NON-NLS-2$
|
|
109 |
Query query = new Query("<" + pStructuralUnit.getName() + "> [] expand to " + pStructuralUnit); //$NON-NLS-1$ //$NON-NLS-2$
|
107 |
110 |
//System.out.println(query);
|
108 |
111 |
QueryResult result = getCorpus().query(query, "test", false); //$NON-NLS-1$
|
109 |
112 |
nmatches = result.getNMatch();
|
... | ... | |
125 |
128 |
@Override
|
126 |
129 |
public boolean canCompute() {
|
127 |
130 |
return getCorpus() != null &&
|
128 |
|
structuralUnit != null &&
|
129 |
|
wordProperties != null &&
|
130 |
|
wordProperties.size() > 0 &&
|
131 |
|
structuralUnitsProperties != null &&
|
132 |
|
structuralUnitsProperties.size() > 0;
|
|
131 |
pStructuralUnit != null &&
|
|
132 |
pWordProperties != null &&
|
|
133 |
pWordProperties.size() > 0 &&
|
|
134 |
pStructuralUnitsProperties != null &&
|
|
135 |
pStructuralUnitsProperties.size() > 0;
|
133 |
136 |
}
|
134 |
137 |
|
135 |
138 |
/**
|
... | ... | |
150 |
153 |
for(int v : positions) {
|
151 |
154 |
p[c++] = v;
|
152 |
155 |
}
|
153 |
|
for (Property prop : wordProperties) {
|
|
156 |
for (Property prop : pWordProperties) {
|
154 |
157 |
rez.put(prop, Match.getValuesForProperty(prop, p));
|
155 |
158 |
}
|
156 |
|
currentPage = i;
|
|
159 |
pCurrentPage = i;
|
157 |
160 |
}
|
158 |
161 |
return rez;
|
159 |
162 |
}
|
... | ... | |
165 |
168 |
* @throws CqiClientException
|
166 |
169 |
*/
|
167 |
170 |
public HashMap<Property, List<String>> getCurrentPageContent() throws CqiClientException {
|
168 |
|
HashMap<Property, List<String>> current = this.getPageContent(currentPage);
|
|
171 |
HashMap<Property, List<String>> current = this.getPageContent(pCurrentPage);
|
169 |
172 |
return current;
|
170 |
173 |
}
|
171 |
174 |
|
... | ... | |
177 |
180 |
* @return the current page number
|
178 |
181 |
*/
|
179 |
182 |
public int getCurrentPage() {
|
180 |
|
return currentPage;
|
|
183 |
return pCurrentPage;
|
181 |
184 |
}
|
182 |
185 |
|
183 |
|
|
184 |
|
|
185 |
186 |
@Override
|
186 |
187 |
public boolean saveParameters() {
|
187 |
|
if (structuralUnit != null) {
|
188 |
|
this.saveParameter(InternalViewPreferences.STRUCTURAL_UNIT, structuralUnit.getName());
|
|
188 |
if (pStructuralUnit != null) {
|
|
189 |
this.saveParameter(InternalViewPreferences.STRUCTURAL_UNIT, pStructuralUnit.getName());
|
189 |
190 |
}
|
190 |
|
if (structuralUnitsProperties != null) {
|
191 |
|
this.saveParameter(InternalViewPreferences.STRUCTURAL_UNIT_PROPERTIES, StructuralUnitProperty.propertiesToString(structuralUnitsProperties));
|
|
191 |
if (pStructuralUnitsProperties != null) {
|
|
192 |
String str = StructuralUnitProperty.propertiesToString(pStructuralUnitsProperties);
|
|
193 |
this.saveParameter(InternalViewPreferences.STRUCTURAL_UNIT_PROPERTIES, str);
|
192 |
194 |
}
|
193 |
|
if (wordProperties != null) {
|
194 |
|
this.saveParameter(InternalViewPreferences.UNIT_PROPERTIES, WordProperty.propertiesToString(wordProperties));
|
|
195 |
if (pWordProperties != null) {
|
|
196 |
this.saveParameter(InternalViewPreferences.UNIT_PROPERTIES, WordProperty.propertiesToString(pWordProperties));
|
195 |
197 |
}
|
196 |
198 |
|
197 |
199 |
return true;
|
... | ... | |
214 |
216 |
|
215 |
217 |
@Override
|
216 |
218 |
public String getDetails() {
|
217 |
|
return getCorpus().getName()+" "+structuralUnit.getName()+" "+(currentPage+1); //$NON-NLS-1$ //$NON-NLS-2$
|
|
219 |
return getCorpus().getName()+" "+pStructuralUnit.getName()+" "+(pCurrentPage+1); //$NON-NLS-1$ //$NON-NLS-2$
|
218 |
220 |
}
|
219 |
221 |
|
220 |
222 |
|
... | ... | |
226 |
228 |
|
227 |
229 |
@Override
|
228 |
230 |
public String getName() {
|
229 |
|
if (structuralUnit != null) {
|
230 |
|
return structuralUnit.getName( ) + " (" + (this.currentPage + 1) + " / " + this.nmatches + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
231 |
if (pStructuralUnit != null) {
|
|
232 |
return pStructuralUnit.getName( ) + " (" + (this.pCurrentPage + 1) + " / " + this.nmatches + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
231 |
233 |
}
|
232 |
234 |
return getCorpus().getName();
|
233 |
235 |
}
|
... | ... | |
247 |
249 |
* @return
|
248 |
250 |
*/
|
249 |
251 |
public List<WordProperty> getProperties() {
|
250 |
|
return wordProperties;
|
|
252 |
return pWordProperties;
|
251 |
253 |
}
|
252 |
254 |
|
253 |
255 |
/**
|
... | ... | |
258 |
260 |
if (matches.size() == 0) {
|
259 |
261 |
return 0;
|
260 |
262 |
}
|
261 |
|
if (matches.size() < currentPage) {
|
|
263 |
if (matches.size() < pCurrentPage) {
|
262 |
264 |
return 0;
|
263 |
265 |
}
|
264 |
266 |
|
265 |
|
Match m = matches.get(currentPage);
|
|
267 |
Match m = matches.get(pCurrentPage);
|
266 |
268 |
return m.size();
|
267 |
269 |
}
|
268 |
270 |
|
... | ... | |
273 |
275 |
public String getStructInfos() {
|
274 |
276 |
|
275 |
277 |
try {
|
276 |
|
if (structuralUnitsProperties.size() > 0) {
|
|
278 |
if (pStructuralUnitsProperties.size() > 0) {
|
277 |
279 |
String str = InternalViewCoreMessages.InternalView_3;
|
278 |
|
for (Property sup : structuralUnitsProperties) {
|
|
280 |
for (Property sup : pStructuralUnitsProperties) {
|
279 |
281 |
int[] array = {getCurrentPage()};
|
280 |
282 |
str += " "+sup.getName()+"="+CQPSearchEngine.getCqiClient().struc2Str(sup.getQualifiedName(), array)[0]; //$NON-NLS-1$ //$NON-NLS-2$
|
281 |
283 |
}
|
... | ... | |
293 |
295 |
* @return
|
294 |
296 |
*/
|
295 |
297 |
public StructuralUnit getStructuralUnit() {
|
296 |
|
return structuralUnit;
|
|
298 |
return pStructuralUnit;
|
297 |
299 |
}
|
298 |
300 |
|
299 |
301 |
|
... | ... | |
318 |
320 |
|
319 |
321 |
|
320 |
322 |
public void setParameters(List<WordProperty> properties, StructuralUnit struct, List<StructuralUnitProperty> structProperties, Integer currentStructure) {
|
321 |
|
if (properties != null) this.wordProperties = properties;
|
322 |
|
if (struct != null) this.structuralUnit = struct;
|
323 |
|
if (structProperties != null) this.structuralUnitsProperties = structProperties;
|
324 |
|
if (currentStructure != null) this.currentPage = currentStructure;
|
|
323 |
if (properties != null) this.pWordProperties = properties;
|
|
324 |
if (struct != null) this.pStructuralUnit = struct;
|
|
325 |
if (structProperties != null) this.pStructuralUnitsProperties = structProperties;
|
|
326 |
if (currentStructure != null) this.pCurrentPage = currentStructure;
|
325 |
327 |
|
326 |
328 |
dirty = true;
|
327 |
329 |
}
|
... | ... | |
342 |
344 |
PrintWriter writer = IOUtils.getWriter(outfile, encoding);
|
343 |
345 |
for (int ipage = 0 ; ipage < nmatches ; ipage++) { // run through all pages
|
344 |
346 |
LinkedHashMap<Property, List<String>> page = getPageContent(ipage);
|
345 |
|
for (Property p : wordProperties) {
|
|
347 |
for (Property p : pWordProperties) {
|
346 |
348 |
writer.println(StringUtils.join(page.get(p), colseparator));
|
347 |
349 |
}
|
348 |
350 |
writer.println("\n\n");
|
... | ... | |
357 |
359 |
* @param structuralUnit
|
358 |
360 |
*/
|
359 |
361 |
public void setStructuralUnit(StructuralUnit structuralUnit) {
|
360 |
|
this.structuralUnit = structuralUnit;
|
|
362 |
this.pStructuralUnit = structuralUnit;
|
361 |
363 |
}
|
362 |
364 |
|
363 |
365 |
|
... | ... | |
366 |
368 |
* @param properties
|
367 |
369 |
*/
|
368 |
370 |
public void setWordProperties(List<WordProperty> properties) {
|
369 |
|
this.wordProperties = properties;
|
|
371 |
this.pWordProperties = properties;
|
370 |
372 |
}
|
371 |
373 |
|
372 |
374 |
/**
|
... | ... | |
374 |
376 |
* @param structuralUnitProperties
|
375 |
377 |
*/
|
376 |
378 |
public void setStructuralUnitProperties(List<StructuralUnitProperty> structuralUnitProperties) {
|
377 |
|
this.structuralUnitsProperties = structuralUnitProperties;
|
|
379 |
this.pStructuralUnitsProperties = structuralUnitProperties;
|
378 |
380 |
}
|
379 |
381 |
|
380 |
382 |
|
... | ... | |
383 |
385 |
* @param currentPage the currentPage to set
|
384 |
386 |
*/
|
385 |
387 |
public void setCurrentPage(int currentPage) {
|
386 |
|
this.currentPage = currentPage;
|
|
388 |
this.pCurrentPage = currentPage;
|
387 |
389 |
|
388 |
|
if(this.currentPage < 0 || this.currentPage > (this.nmatches - 1)) {
|
389 |
|
System.err.println("InternalView.canCompute(): current page (" + this.currentPage + ") is outside matches range (" + this.nmatches + ").");
|
390 |
|
this.currentPage = 0;
|
|
390 |
if(this.pCurrentPage < 0 || this.pCurrentPage > (this.nmatches - 1)) {
|
|
391 |
System.err.println("InternalView.canCompute(): current page (" + this.pCurrentPage + ") is outside matches range (" + this.nmatches + ").");
|
|
392 |
this.pCurrentPage = 0;
|
391 |
393 |
}
|
392 |
394 |
}
|
393 |
395 |
|