Révision 2409
| tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Partition.java (revision 2409) | ||
|---|---|---|
| 66 | 66 |
/** |
| 67 | 67 |
* A partition on a corpus. The partition is composed of {@link Part}s
|
| 68 | 68 |
* |
| 69 |
* The parts order depends on the Partition creation method used.
|
|
| 69 |
* The parts order depends on the Partition creation method used. |
|
| 70 | 70 |
* |
| 71 | 71 |
* @author mdecorde |
| 72 |
* @author sjacquot
|
|
| 72 |
* @author sjacquot |
|
| 73 | 73 |
* @author Jean-Philippe Magué |
| 74 | 74 |
* |
| 75 | 75 |
*/ |
| 76 | 76 |
public class Partition extends org.txm.objects.Partition {
|
| 77 |
|
|
| 78 |
/** sum of parts size, stored for efficiency reasons**/ |
|
| 77 |
|
|
| 78 |
/** sum of parts size, stored for efficiency reasons **/
|
|
| 79 | 79 |
int totalsize = -1; |
| 80 |
|
|
| 80 |
|
|
| 81 | 81 |
/** The property, if not null the partition will forge its own queries */ |
| 82 |
@Parameter(key=TXMPreferences.STRUCTURAL_UNIT_PROPERTY)
|
|
| 82 |
@Parameter(key = TXMPreferences.STRUCTURAL_UNIT_PROPERTY)
|
|
| 83 | 83 |
protected StructuralUnitProperty pProperty; |
| 84 |
|
|
| 84 |
|
|
| 85 | 85 |
/** |
| 86 | 86 |
* The parts property values to use, may be null. |
| 87 | 87 |
*/ |
| 88 |
@Parameter(key=TXMPreferences.VALUES)
|
|
| 88 |
@Parameter(key = TXMPreferences.VALUES)
|
|
| 89 | 89 |
protected List<String> pValues; |
| 90 |
|
|
| 90 |
|
|
| 91 | 91 |
/** |
| 92 | 92 |
* The parts queries |
| 93 | 93 |
*/ |
| 94 |
@Parameter(key=TXMPreferences.QUERIES)
|
|
| 94 |
@Parameter(key = TXMPreferences.QUERIES)
|
|
| 95 | 95 |
protected List<String> pQueries; |
| 96 |
|
|
| 96 |
|
|
| 97 | 97 |
/** |
| 98 | 98 |
* The parts names -> do the parts order |
| 99 | 99 |
*/ |
| 100 |
@Parameter(key=CQPPreferences.PART_NAMES)
|
|
| 100 |
@Parameter(key = CQPPreferences.PART_NAMES)
|
|
| 101 | 101 |
protected List<String> pPartNames; |
| 102 |
|
|
| 103 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 | 104 |
/** |
| 105 | 105 |
* |
| 106 | 106 |
* @param parent |
| 107 |
* @throws NullPointerException
|
|
| 107 |
* @throws NullPointerException |
|
| 108 | 108 |
*/ |
| 109 |
public Partition(CQPCorpus parent) throws NullPointerException {
|
|
| 109 |
public Partition(CQPCorpus parent) throws NullPointerException {
|
|
| 110 | 110 |
super(parent); |
| 111 | 111 |
} |
| 112 |
|
|
| 112 |
|
|
| 113 | 113 |
/** |
| 114 | 114 |
* |
| 115 | 115 |
* @param parametersNodePath |
| 116 | 116 |
*/ |
| 117 |
public Partition(String parametersNodePath) {
|
|
| 117 |
public Partition(String parametersNodePath) {
|
|
| 118 | 118 |
super(parametersNodePath); |
| 119 | 119 |
} |
| 120 |
|
|
| 121 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 | 122 |
/** |
| 123 | 123 |
* Instantiates a new partition. |
| 124 | 124 |
* |
| ... | ... | |
| 126 | 126 |
* @param name the name |
| 127 | 127 |
* @param queries the queries |
| 128 | 128 |
* @param partnames the partnames |
| 129 |
* @throws Exception
|
|
| 129 |
* @throws Exception |
|
| 130 | 130 |
*/ |
| 131 | 131 |
public boolean _compute_with_lists() throws Exception {
|
| 132 |
|
|
| 132 |
|
|
| 133 | 133 |
if (this.userName == null || this.userName.length() == 0) {
|
| 134 | 134 |
this.userName = "no_name"; |
| 135 | 135 |
} |
| 136 |
|
|
| 136 |
|
|
| 137 | 137 |
Log.fine(NLS.bind(SearchEngineCoreMessages.info_creatingNewPartition, this.getParent(), this.userName)); |
| 138 | 138 |
long start = System.currentTimeMillis(); |
| 139 | 139 |
|
| ... | ... | |
| 141 | 141 |
|
| 142 | 142 |
for (int i = 0; i < pQueries.size(); i++) {
|
| 143 | 143 |
String queryS = pQueries.get(i); |
| 144 |
|
|
| 144 |
|
|
| 145 | 145 |
String partName = String.valueOf(i); |
| 146 |
if (pPartNames != null && i < pPartNames.size()) {
|
|
| 146 |
if (pPartNames != null && i < pPartNames.size()) {
|
|
| 147 | 147 |
partName = pPartNames.get(i); |
| 148 | 148 |
} |
| 149 | 149 |
if (partName.trim().length() == 0) {
|
| ... | ... | |
| 154 | 154 |
} |
| 155 | 155 |
long end = System.currentTimeMillis(); |
| 156 | 156 |
Log.fine(NLS.bind(SearchEngineCoreMessages.info_partitionCreatedInXMs, this.userName, (end - start))); |
| 157 |
|
|
| 157 |
|
|
| 158 | 158 |
return pQueries.size() > 0; |
| 159 | 159 |
} |
| 160 |
|
|
| 160 |
|
|
| 161 | 161 |
/** |
| 162 | 162 |
* Creates a new partition on a corpus given a structure, a property of this |
| 163 | 163 |
* structure and a list of values this property can take |
| ... | ... | |
| 170 | 170 |
* @param structure the structure |
| 171 | 171 |
* @param property the property |
| 172 | 172 |
* @param values the values, raw values special chars will be backslashed |
| 173 |
* @throws Exception
|
|
| 173 |
* @throws Exception |
|
| 174 | 174 |
*/ |
| 175 |
|
|
| 176 |
protected boolean _compute_with_property() throws Exception {
|
|
| 177 |
|
|
| 175 |
|
|
| 176 |
protected boolean _compute_with_property() throws Exception {
|
|
| 177 |
|
|
| 178 | 178 |
CQPCorpus corpus = this.getParent(); |
| 179 | 179 |
if (this.userName == null || this.userName.length() == 0) {
|
| 180 | 180 |
this.userName = corpus.getName() + "_" + pProperty.getFullName(); //$NON-NLS-1$ |
| 181 | 181 |
} |
| 182 |
|
|
| 182 |
|
|
| 183 | 183 |
if (pValues == null) {
|
| 184 | 184 |
pValues = pProperty.getValues(corpus); |
| 185 | 185 |
} |
| 186 |
|
|
| 186 |
|
|
| 187 | 187 |
// sort parts |
| 188 | 188 |
HashMap<String, String> infos = this.getParent().getSAttributesInfos().get(pProperty.getFullName()); |
| 189 |
|
|
| 189 |
|
|
| 190 | 190 |
String type = "String"; //$NON-NLS-1$ |
| 191 | 191 |
if (infos != null) {
|
| 192 | 192 |
type = infos.get("type"); //$NON-NLS-1$
|
| ... | ... | |
| 196 | 196 |
} |
| 197 | 197 |
else if (type.equals("Integer")) { //$NON-NLS-1$
|
| 198 | 198 |
Collections.sort(pValues, new Comparator<String>() {
|
| 199 |
|
|
| 199 | 200 |
@Override |
| 200 | 201 |
public int compare(String arg0, String arg1) {
|
| 201 | 202 |
int i0 = Integer.parseInt(arg0); |
| 202 | 203 |
int i1 = Integer.parseInt(arg1); |
| 203 | 204 |
return i0 - i1; |
| 204 | 205 |
} |
| 205 |
});
|
|
| 206 |
}); |
|
| 206 | 207 |
} |
| 207 | 208 |
else if (type.equals("Date")) { //$NON-NLS-1$
|
| 208 | 209 |
String format = infos.get("inputFormat"); //$NON-NLS-1$
|
| 209 | 210 |
final DateFormat formater = new SimpleDateFormat(format); |
| 210 | 211 |
Collections.sort(pValues, new Comparator<String>() {
|
| 212 |
|
|
| 211 | 213 |
@Override |
| 212 | 214 |
public int compare(String arg0, String arg1) {
|
| 213 | 215 |
try {
|
| 214 | 216 |
Date i0 = formater.parse(arg0); |
| 215 | 217 |
Date i1 = formater.parse(arg1); |
| 216 | 218 |
return i0.compareTo(i1); |
| 217 |
} catch (ParseException e) {
|
|
| 219 |
} |
|
| 220 |
catch (ParseException e) {
|
|
| 218 | 221 |
return arg0.compareTo(arg1); |
| 219 | 222 |
} |
| 220 | 223 |
} |
| 221 |
});
|
|
| 224 |
}); |
|
| 222 | 225 |
} |
| 223 |
else if (type.contains("|")){ //$NON-NLS-1$
|
|
| 226 |
else if (type.contains("|")) { //$NON-NLS-1$
|
|
| 224 | 227 |
final List<String> sortedValues = Arrays.asList(type.split("\\|")); //$NON-NLS-1$
|
| 225 | 228 |
Collections.sort(pValues, new Comparator<String>() {
|
| 229 |
|
|
| 226 | 230 |
@Override |
| 227 | 231 |
public int compare(String arg0, String arg1) {
|
| 228 | 232 |
int i0 = sortedValues.indexOf(arg0); |
| 229 | 233 |
int i1 = sortedValues.indexOf(arg1); |
| 230 |
return i0-i1;
|
|
| 234 |
return i0 - i1;
|
|
| 231 | 235 |
} |
| 232 |
});
|
|
| 236 |
}); |
|
| 233 | 237 |
} |
| 234 |
|
|
| 238 |
|
|
| 235 | 239 |
pQueries = new ArrayList<>(); |
| 236 | 240 |
pPartNames = new ArrayList<>(); |
| 237 | 241 |
for (String value : pValues) {
|
| 238 |
String partName = value.replace("\\",""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 242 |
String partName = value.replace("\\", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 239 | 243 |
pPartNames.add(partName); |
| 240 | 244 |
CQLQuery query = new QueryPart(pProperty.getStructuralUnit(), pProperty, CQLQuery.addBackSlash(value)); // second option is faster |
| 241 | 245 |
|
| 242 | 246 |
pQueries.add(query.getQueryString()); |
| 243 | 247 |
} |
| 244 |
|
|
| 248 |
|
|
| 245 | 249 |
return _compute_with_lists(); |
| 246 | 250 |
} |
| 247 |
|
|
| 248 |
|
|
| 251 |
|
|
| 252 |
|
|
| 249 | 253 |
@Override |
| 250 | 254 |
protected boolean _compute() throws Exception {
|
| 251 |
|
|
| 255 |
|
|
| 252 | 256 |
// Parts already created |
| 253 | 257 |
if (this.getParts().size() > 0) {
|
| 254 | 258 |
|
| 255 | 259 |
if (monitor != null) monitor.beginTask("Building parts...", this.getParts().size());
|
| 256 |
//FIXME: temporary fix, compute all the children parts |
|
| 257 |
List<Part> parts = (List<Part>)getChildren(Part.class); |
|
| 260 |
// FIXME: temporary fix, compute all the children parts
|
|
| 261 |
List<Part> parts = (List<Part>) getChildren(Part.class);
|
|
| 258 | 262 |
for (int i = 0; i < parts.size(); i++) {
|
| 259 | 263 |
parts.get(i).compute(); |
| 260 | 264 |
if (monitor != null) monitor.worked(1); |
| ... | ... | |
| 262 | 266 |
} |
| 263 | 267 |
else {
|
| 264 | 268 |
Log.finest(NLS.bind(SearchEngineCoreMessages.info_creatingNewPartition, this.getParent(), this.userName)); |
| 265 |
|
|
| 269 |
|
|
| 266 | 270 |
if (this.pProperty != null) {
|
| 267 | 271 |
_compute_with_property(); |
| 268 | 272 |
} |
| ... | ... | |
| 273 | 277 |
totalsize = -1; // refresh total size at next call of getTotalSize |
| 274 | 278 |
return true; |
| 275 | 279 |
} |
| 276 |
|
|
| 277 |
/* (non-Javadoc) |
|
| 280 |
|
|
| 281 |
/* |
|
| 282 |
* (non-Javadoc) |
|
| 278 | 283 |
* @see org.txm.objects.TxmObject#load() |
| 279 | 284 |
*/ |
| 280 | 285 |
protected boolean _load(Element e) {
|
| 281 |
|
|
| 286 |
|
|
| 282 | 287 |
// partition already computed |
| 283 | 288 |
if (this.hasBeenComputedOnce) {
|
| 284 | 289 |
return true; |
| 285 | 290 |
} |
| 286 |
|
|
| 291 |
|
|
| 287 | 292 |
if (e != null && this.getParent() != null) {
|
| 288 | 293 |
NodeList partList = e.getChildNodes(); |
| 289 | 294 |
for (int i = 0; i < partList.getLength(); i++) {
|
| ... | ... | |
| 302 | 307 |
} |
| 303 | 308 |
} |
| 304 | 309 |
} |
| 305 |
//this.loadMetadata(); |
|
| 310 |
// this.loadMetadata();
|
|
| 306 | 311 |
return true; |
| 307 | 312 |
} |
| 308 |
|
|
| 313 |
|
|
| 309 | 314 |
return false; |
| 310 | 315 |
} |
| 311 |
|
|
| 316 |
|
|
| 312 | 317 |
@Override |
| 313 | 318 |
public boolean canCompute() {
|
| 314 | 319 |
return this.getParent() != null && (this.pProperty != null || (this.pQueries != null && this.pQueries.size() > 0)); |
| 315 | 320 |
} |
| 316 |
|
|
| 321 |
|
|
| 317 | 322 |
@Override |
| 318 | 323 |
public void clean() {
|
| 319 | 324 |
// TODO Auto-generated method stub |
| 320 | 325 |
} |
| 321 |
|
|
| 326 |
|
|
| 322 | 327 |
@Override |
| 323 | 328 |
public int compareTo(TXMResult o) {
|
| 324 | 329 |
// Compare node weights |
| 325 | 330 |
int output = super.compareTo(o); |
| 326 | 331 |
// Compare simple names if weights are equal |
| 327 |
if (output == 0) {
|
|
| 332 |
if (output == 0) {
|
|
| 328 | 333 |
output = this.getSimpleName().compareToIgnoreCase(o.getSimpleName()); |
| 329 | 334 |
} |
| 330 | 335 |
return output; |
| 331 | 336 |
} |
| 332 |
|
|
| 333 |
// /**
|
|
| 334 |
// * TODO Part should be create lazily
|
|
| 335 |
// *
|
|
| 336 |
// * Create a part with a raw query.
|
|
| 337 |
// *
|
|
| 338 |
// * @param partitionName the partition name
|
|
| 339 |
// * @param partName the part name
|
|
| 340 |
// * @param query the query
|
|
| 341 |
// * @return the part
|
|
| 342 |
// * @throws CqiClientException the cqi client exception
|
|
| 343 |
// *
|
|
| 344 |
// * @author Sylvain Loiseau, mdecorde
|
|
| 345 |
// */
|
|
| 346 |
// public Part createPart(String partitionName, String partName, String query) throws CqiClientException {
|
|
| 347 |
// Part part;
|
|
| 348 |
// String partCqpId = CqpObject.partNamePrefix + CQPCorpus.getNextSubcorpusCounter();
|
|
| 349 |
// Log.finest(NLS.bind(TXMCoreMessages.CREATING_PART, partName, query));
|
|
| 350 |
// long start = System.currentTimeMillis();
|
|
| 351 |
// try {
|
|
| 352 |
// CorpusManager.getCorpusManager().getCqiClient().cqpQuery(this.getParent().getQualifiedCqpId(), partCqpId, query);
|
|
| 353 |
// part = new Part(this);
|
|
| 354 |
// part.setParameters(partCqpId, partName, new CQLQuery(query));
|
|
| 355 |
// part.compute();
|
|
| 356 |
// // FIXME: persistence tests: define the UUID as the concatenation of all part CQP id
|
|
| 357 |
//// this.uniqueID += partCqpId;
|
|
| 337 |
|
|
| 338 |
// /**
|
|
| 339 |
// * TODO Part should be create lazily |
|
| 340 |
// *
|
|
| 341 |
// * Create a part with a raw query. |
|
| 342 |
// * |
|
| 343 |
// * @param partitionName the partition name |
|
| 344 |
// * @param partName the part name |
|
| 345 |
// * @param query the query |
|
| 346 |
// * @return the part |
|
| 347 |
// * @throws CqiClientException the cqi client exception |
|
| 348 |
// *
|
|
| 349 |
// * @author Sylvain Loiseau, mdecorde |
|
| 350 |
// */ |
|
| 351 |
// public Part createPart(String partitionName, String partName, String query) throws CqiClientException {
|
|
| 352 |
// Part part;
|
|
| 353 |
// String partCqpId = CqpObject.partNamePrefix + CQPCorpus.getNextSubcorpusCounter();
|
|
| 354 |
// Log.finest(NLS.bind(TXMCoreMessages.CREATING_PART, partName, query));
|
|
| 355 |
// long start = System.currentTimeMillis();
|
|
| 356 |
// try {
|
|
| 357 |
// CorpusManager.getCorpusManager().getCqiClient().cqpQuery(this.getParent().getQualifiedCqpId(), partCqpId, query);
|
|
| 358 |
// part = new Part(this);
|
|
| 359 |
// part.setParameters(partCqpId, partName, new CQLQuery(query));
|
|
| 360 |
// part.compute();
|
|
| 361 |
// // FIXME: persistence tests: define the UUID as the concatenation of all part CQP id
|
|
| 362 |
//// this.uniqueID += partCqpId;
|
|
| 358 | 363 |
// |
| 359 |
// } catch (Exception e) {
|
|
| 360 |
// try {
|
|
| 361 |
// throw new CqiClientException(TXMCoreMessages.failedToCreatePartColon + partitionName + "_" + partName + e + " last error: " + CQPSearchEngine.getCqiClient().getLastCQPError()); //$NON-NLS-1$ //$NON-NLS-2$ |
|
| 362 |
// } catch (Exception e1) {
|
|
| 363 |
// Log.severe(TXMCoreMessages.failedToGetLastCQPErrorColon + e1); |
|
| 364 |
// org.txm.utils.logger.Log.printStackTrace(e1); |
|
| 365 |
// return null; |
|
| 366 |
// } |
|
| 367 |
// } |
|
| 368 |
// long end = System.currentTimeMillis(); |
|
| 369 |
// Log.finest(NLS.bind(TXMCoreMessages.info_partCreatedInXMs, partitionName + "_" + partName, (end - start))); //$NON-NLS-1 |
|
| 364 |
// } catch (Exception e) {
|
|
| 365 |
// try {
|
|
| 366 |
// throw new CqiClientException(TXMCoreMessages.failedToCreatePartColon + partitionName + "_" + partName + e + " last error: " + CQPSearchEngine.getCqiClient().getLastCQPError()); //$NON-NLS-1$ |
|
| 367 |
// //$NON-NLS-2$ |
|
| 368 |
// } catch (Exception e1) {
|
|
| 369 |
// Log.severe(TXMCoreMessages.failedToGetLastCQPErrorColon + e1); |
|
| 370 |
// org.txm.utils.logger.Log.printStackTrace(e1); |
|
| 371 |
// return null; |
|
| 372 |
// } |
|
| 373 |
// } |
|
| 374 |
// long end = System.currentTimeMillis(); |
|
| 375 |
// Log.finest(NLS.bind(TXMCoreMessages.info_partCreatedInXMs, partitionName + "_" + partName, (end - start))); //$NON-NLS-1 |
|
| 370 | 376 |
// |
| 371 |
// return part;
|
|
| 372 |
// }
|
|
| 373 |
|
|
| 374 |
|
|
| 377 |
// return part;
|
|
| 378 |
// }
|
|
| 379 |
|
|
| 380 |
|
|
| 375 | 381 |
@Override |
| 376 | 382 |
public String getDetails() {
|
| 377 | 383 |
return this.getName(); |
| 378 | 384 |
} |
| 379 |
|
|
| 385 |
|
|
| 380 | 386 |
@Override |
| 381 | 387 |
public String getSimpleName() {
|
| 382 | 388 |
return this.userName; |
| 383 | 389 |
} |
| 384 |
|
|
| 390 |
|
|
| 385 | 391 |
@Override |
| 386 | 392 |
public String getName() {
|
| 387 | 393 |
String name = this.userName; |
| 388 | 394 |
int partsCount = this.getPartsCount(); |
| 389 | 395 |
|
| 390 |
if(partsCount > 0) {
|
|
| 396 |
if (partsCount > 0) {
|
|
| 391 | 397 |
name += NLS.bind(" ({0})", partsCount);
|
| 392 | 398 |
} |
| 393 | 399 |
|
| ... | ... | |
| 398 | 404 |
public String getComputingStartMessage() {
|
| 399 | 405 |
return TXMCoreMessages.bind("Création de la partition {0} dans le corpus {1}...", this.getSimpleName(), this.getCorpus().getName());
|
| 400 | 406 |
} |
| 401 |
|
|
| 402 | 407 |
|
| 408 |
|
|
| 403 | 409 |
@Override |
| 404 | 410 |
public String getComputingDoneMessage() {
|
| 405 | 411 |
return TXMCoreMessages.bind(TXMCoreMessages.P0BuiltParts, this.getPartsCount()); |
| ... | ... | |
| 413 | 419 |
public int getPartsCount() {
|
| 414 | 420 |
return this.getParts().size(); |
| 415 | 421 |
} |
| 416 |
|
|
| 422 |
|
|
| 417 | 423 |
/** |
| 418 | 424 |
* Gets the name of the parts. |
| 419 | 425 |
* |
| ... | ... | |
| 422 | 428 |
public List<String> getPartNames() {
|
| 423 | 429 |
if (this.hasBeenComputedOnce()) {
|
| 424 | 430 |
List<Part> parts = this.getParts(); |
| 425 |
List<String> partNames = new ArrayList<String>(parts.size());
|
|
| 431 |
List<String> partNames = new ArrayList<>(parts.size()); |
|
| 426 | 432 |
for (Subcorpus part : this.getParts()) {
|
| 427 | 433 |
partNames.add(part.getName()); |
| 428 | 434 |
} |
| 429 | 435 |
return partNames; |
| 430 |
} else {
|
|
| 436 |
} |
|
| 437 |
else {
|
|
| 431 | 438 |
return this.pPartNames; |
| 432 | 439 |
} |
| 433 | 440 |
} |
| 434 |
|
|
| 441 |
|
|
| 435 | 442 |
/** |
| 436 | 443 |
* Gets the children parts. |
| 437 | 444 |
* |
| ... | ... | |
| 441 | 448 |
public List<Part> getParts() {
|
| 442 | 449 |
return (List<Part>) this.getChildren(Part.class); |
| 443 | 450 |
} |
| 444 |
|
|
| 451 |
|
|
| 445 | 452 |
/** |
| 446 | 453 |
* Gets the part sizes as int array. |
| 447 | 454 |
* |
| ... | ... | |
| 452 | 459 |
*/ |
| 453 | 460 |
public int[] getPartSizes() throws CqiClientException {
|
| 454 | 461 |
int[] partSizes = new int[this.getParts().size()]; |
| 455 |
for (int i = 0 ; i < getParts().size() ; i++) {
|
|
| 462 |
for (int i = 0; i < getParts().size(); i++) {
|
|
| 456 | 463 |
Part p = this.getParts().get(i); |
| 457 | 464 |
partSizes[i] = p.getSize(); |
| 458 | 465 |
} |
| 459 | 466 |
return partSizes; |
| 460 | 467 |
} |
| 461 |
|
|
| 468 |
|
|
| 462 | 469 |
/** |
| 463 | 470 |
* Gets the property. |
| 464 | 471 |
* |
| ... | ... | |
| 467 | 474 |
public Property getProperty() {
|
| 468 | 475 |
return pProperty; |
| 469 | 476 |
} |
| 470 |
|
|
| 477 |
|
|
| 471 | 478 |
/** |
| 472 | 479 |
* Gets the structure. |
| 473 | 480 |
* |
| ... | ... | |
| 477 | 484 |
if (pProperty == null) return null; |
| 478 | 485 |
return pProperty.getStructuralUnit(); |
| 479 | 486 |
} |
| 480 |
|
|
| 487 |
|
|
| 481 | 488 |
/** |
| 482 | 489 |
* Gets the total of all part sizes. |
| 490 |
* |
|
| 483 | 491 |
* @return |
| 484 | 492 |
* @throws CqiClientException |
| 485 | 493 |
*/ |
| 486 | 494 |
public int getTotalSize() throws CqiClientException {
|
| 487 |
|
|
| 495 |
|
|
| 488 | 496 |
if (totalsize == -1) {
|
| 489 | 497 |
totalsize = 0; |
| 490 | 498 |
for (Part p : getParts()) {
|
| ... | ... | |
| 493 | 501 |
} |
| 494 | 502 |
return totalsize; |
| 495 | 503 |
} |
| 496 |
|
|
| 497 |
|
|
| 504 |
|
|
| 505 |
|
|
| 498 | 506 |
/** |
| 499 | 507 |
* Run a query on all the parts of this partition. |
| 500 | 508 |
* |
| ... | ... | |
| 511 | 519 |
public List<QueryResult> query(CQLQuery query, String name) throws CqiClientException {
|
| 512 | 520 |
Log.finest(TXMCoreMessages.queryingPartitionP0 + this.userName); |
| 513 | 521 |
List<Part> parts = getParts(); |
| 514 |
List<QueryResult> results = new ArrayList<QueryResult>(parts.size());
|
|
| 522 |
List<QueryResult> results = new ArrayList<>(parts.size()); |
|
| 515 | 523 |
for (Subcorpus part : parts) {
|
| 516 | 524 |
results.add(part.query(query, part.getName() + "_" + name, false)); //$NON-NLS-1$ |
| 517 | 525 |
} |
| 518 | 526 |
return results; |
| 519 | 527 |
} |
| 520 |
|
|
| 521 |
// /**
|
|
| 522 |
// * Register to parent.
|
|
| 523 |
// */
|
|
| 524 |
// public void registerToParent() {
|
|
| 525 |
// //registerToParent(this.name);
|
|
| 526 |
// }
|
|
| 528 |
|
|
| 529 |
// /**
|
|
| 530 |
// * Register to parent. |
|
| 531 |
// */ |
|
| 532 |
// public void registerToParent() {
|
|
| 533 |
// //registerToParent(this.name);
|
|
| 534 |
// }
|
|
| 527 | 535 |
// |
| 528 |
// /** |
|
| 529 |
// * Register to parent. |
|
| 530 |
// * |
|
| 531 |
// * @param partitionName the partition name |
|
| 532 |
// */ |
|
| 533 |
// private void registerToParent(String partitionName) {
|
|
| 534 |
//// if (this.getSelfElement() == null && this.getParent() != null) |
|
| 535 |
//// try {
|
|
| 536 |
//// Element parentElem = (Element) this.getParent().getSelfElement(); |
|
| 537 |
//// if (parentElem == null) return; |
|
| 538 |
//// Document doc = parentElem.getOwnerDocument(); |
|
| 539 |
//// Element corporaElem; |
|
| 540 |
//// if (this.getParent() instanceof MainCorpus) {
|
|
| 541 |
//// NodeList corporaList = parentElem.getElementsByTagName("preBuild"); //$NON-NLS-1$
|
|
| 542 |
//// corporaElem = (Element) corporaList.item(0); |
|
| 543 |
//// } else {
|
|
| 544 |
//// corporaElem = parentElem; |
|
| 545 |
//// } |
|
| 546 |
//// Element partitionElem = doc.createElement("partition"); //$NON-NLS-1$
|
|
| 547 |
//// partitionElem.setAttribute("name", partitionName); //$NON-NLS-1$
|
|
| 548 |
//// corporaElem.appendChild(partitionElem); |
|
| 549 |
//// this.setSelfElement(partitionElem); |
|
| 550 |
//// for (Part p : getParts()) {
|
|
| 551 |
//// Element partElem = doc.createElement("part"); //$NON-NLS-1$
|
|
| 552 |
//// partElem.setAttribute("name", p.getName()); //$NON-NLS-1$
|
|
| 553 |
//// partElem.setAttribute("shortname", p.getShortName()); //$NON-NLS-1$
|
|
| 554 |
//// partElem.setAttribute("query", p.getQuery().getQueryString()); //$NON-NLS-1$
|
|
| 555 |
//// partitionElem.appendChild(partElem); |
|
| 556 |
//// } |
|
| 557 |
//// } catch (Exception e) {
|
|
| 558 |
//// System.out.println(TXMCoreMessages.Partition_21+e); |
|
| 559 |
//// } |
|
| 560 |
//// this._load(); |
|
| 561 |
// } |
|
| 562 |
|
|
| 563 |
// public TxmObject removeChildren(TxmObject children) {
|
|
| 564 |
// if (children instanceof Part) {
|
|
| 565 |
// if (children.getSelfElement() != null && children.getSelfElement().getParentNode() == getSelfElement()) |
|
| 566 |
// getSelfElement().removeChild(children.getSelfElement()); |
|
| 567 |
// return children; |
|
| 568 |
// } |
|
| 569 |
// return null; |
|
| 570 |
// } |
|
| 571 |
|
|
| 536 |
// /** |
|
| 537 |
// * Register to parent. |
|
| 538 |
// * |
|
| 539 |
// * @param partitionName the partition name |
|
| 540 |
// */ |
|
| 541 |
// private void registerToParent(String partitionName) {
|
|
| 542 |
//// if (this.getSelfElement() == null && this.getParent() != null) |
|
| 543 |
//// try {
|
|
| 544 |
//// Element parentElem = (Element) this.getParent().getSelfElement(); |
|
| 545 |
//// if (parentElem == null) return; |
|
| 546 |
//// Document doc = parentElem.getOwnerDocument(); |
|
| 547 |
//// Element corporaElem; |
|
| 548 |
//// if (this.getParent() instanceof MainCorpus) {
|
|
| 549 |
//// NodeList corporaList = parentElem.getElementsByTagName("preBuild"); //$NON-NLS-1$
|
|
| 550 |
//// corporaElem = (Element) corporaList.item(0); |
|
| 551 |
//// } else {
|
|
| 552 |
//// corporaElem = parentElem; |
|
| 553 |
//// } |
|
| 554 |
//// Element partitionElem = doc.createElement("partition"); //$NON-NLS-1$
|
|
| 555 |
//// partitionElem.setAttribute("name", partitionName); //$NON-NLS-1$
|
|
| 556 |
//// corporaElem.appendChild(partitionElem); |
|
| 557 |
//// this.setSelfElement(partitionElem); |
|
| 558 |
//// for (Part p : getParts()) {
|
|
| 559 |
//// Element partElem = doc.createElement("part"); //$NON-NLS-1$
|
|
| 560 |
//// partElem.setAttribute("name", p.getName()); //$NON-NLS-1$
|
|
| 561 |
//// partElem.setAttribute("shortname", p.getShortName()); //$NON-NLS-1$
|
|
| 562 |
//// partElem.setAttribute("query", p.getQuery().getQueryString()); //$NON-NLS-1$
|
|
| 563 |
//// partitionElem.appendChild(partElem); |
|
| 564 |
//// } |
|
| 565 |
//// } catch (Exception e) {
|
|
| 566 |
//// System.out.println(TXMCoreMessages.Partition_21+e); |
|
| 567 |
//// } |
|
| 568 |
//// this._load(); |
|
| 569 |
// } |
|
| 570 |
|
|
| 571 |
// public TxmObject removeChildren(TxmObject children) {
|
|
| 572 |
// if (children instanceof Part) {
|
|
| 573 |
// if (children.getSelfElement() != null && children.getSelfElement().getParentNode() == getSelfElement()) |
|
| 574 |
// getSelfElement().removeChild(children.getSelfElement()); |
|
| 575 |
// return children; |
|
| 576 |
// } |
|
| 577 |
// return null; |
|
| 578 |
// } |
|
| 579 |
|
|
| 580 |
@Override |
|
| 572 | 581 |
public CQPCorpus getParent() {
|
| 573 | 582 |
return (CQPCorpus) super.getParent(); |
| 574 | 583 |
} |
| 575 |
|
|
| 584 |
|
|
| 576 | 585 |
/** |
| 577 | 586 |
* Remove the specified <code>Part</code> from the partition. |
| 587 |
* |
|
| 578 | 588 |
* @param p |
| 579 | 589 |
* @throws CqiClientException |
| 580 | 590 |
*/ |
| 581 | 591 |
public void removePart(Part p) throws CqiClientException {
|
| 582 | 592 |
p.delete(); |
| 583 | 593 |
} |
| 584 |
|
|
| 585 |
|
|
| 594 |
|
|
| 595 |
|
|
| 586 | 596 |
@Override |
| 587 | 597 |
public String toString() {
|
| 588 | 598 |
if (!this.userName.isEmpty()) {
|
| ... | ... | |
| 590 | 600 |
} |
| 591 | 601 |
return super.toString(); |
| 592 | 602 |
} |
| 593 |
|
|
| 594 |
|
|
| 603 |
|
|
| 604 |
|
|
| 595 | 605 |
@Override |
| 596 | 606 |
public boolean toTxt(File output, String encoding, String colseparator, String txtseparator) throws Exception {
|
| 597 | 607 |
IOUtils.write(output, this.dumpPreferences()); |
| 598 | 608 |
return output.exists(); |
| 599 | 609 |
} |
| 600 |
|
|
| 610 |
|
|
| 601 | 611 |
public boolean setParameters(String name, StructuralUnitProperty property, List<String> values) {
|
| 602 | 612 |
this.pProperty = property; |
| 603 | 613 |
this.pValues = values; |
| ... | ... | |
| 606 | 616 |
this.pPartNames = null; |
| 607 | 617 |
return true; |
| 608 | 618 |
} |
| 609 |
|
|
| 619 |
|
|
| 610 | 620 |
public boolean setParameters(String name, List<String> queries, List<String> names) {
|
| 611 | 621 |
this.pProperty = null; |
| 612 | 622 |
this.pValues = null; |
| ... | ... | |
| 615 | 625 |
this.pPartNames = names; |
| 616 | 626 |
return true; |
| 617 | 627 |
} |
| 618 |
|
|
| 628 |
|
|
| 619 | 629 |
@Override |
| 620 | 630 |
public boolean setParameters(TXMParameters parameters) {
|
| 621 | 631 |
this.userName = parameters.getString(TXMPreferences.USER_NAME); |
| 622 | 632 |
String tmp = parameters.getString(CQPPreferences.PART_NAMES); |
| 623 | 633 |
if (tmp != null) {
|
| 624 | 634 |
this.pPartNames = Arrays.asList(tmp.split("\t"));
|
| 625 |
} else {
|
|
| 635 |
} |
|
| 636 |
else {
|
|
| 626 | 637 |
this.pPartNames = null; |
| 627 | 638 |
} |
| 628 |
|
|
| 639 |
|
|
| 629 | 640 |
try {
|
| 630 | 641 |
this.pProperty = StructuralUnitProperty.stringToStructuralUnitProperty(getParent(), parameters.getString(TXMPreferences.STRUCTURAL_UNIT_PROPERTY)); |
| 631 |
} catch (CqiClientException e) {
|
|
| 642 |
} |
|
| 643 |
catch (CqiClientException e) {
|
|
| 632 | 644 |
// TODO Auto-generated catch block |
| 633 | 645 |
e.printStackTrace(); |
| 634 | 646 |
this.pProperty = null; |
| 635 | 647 |
} |
| 636 |
|
|
| 648 |
|
|
| 637 | 649 |
tmp = parameters.getString(CQPPreferences.QUERIES); |
| 638 | 650 |
if (tmp != null) {
|
| 639 | 651 |
this.pQueries = Arrays.asList(tmp.split("\t"));
|
| 640 |
} else {
|
|
| 652 |
} |
|
| 653 |
else {
|
|
| 641 | 654 |
this.pQueries = null; |
| 642 | 655 |
} |
| 643 |
|
|
| 656 |
|
|
| 644 | 657 |
tmp = parameters.getString(CQPPreferences.VALUES); |
| 645 | 658 |
if (tmp != null) {
|
| 646 | 659 |
this.pValues = Arrays.asList(tmp.split("\t"));
|
| 647 |
} else {
|
|
| 660 |
} |
|
| 661 |
else {
|
|
| 648 | 662 |
this.pValues = null; |
| 649 | 663 |
} |
| 650 | 664 |
return true; |
| 651 | 665 |
} |
| 652 |
|
|
| 666 |
|
|
| 653 | 667 |
@Override |
| 654 | 668 |
public boolean loadParameters() {
|
| 655 | 669 |
String tmp = null; |
| 656 | 670 |
try {
|
| 657 | 671 |
tmp = this.getStringParameterValue(TBXPreferences.STRUCTURAL_UNIT_PROPERTY); |
| 658 |
if (!tmp.isEmpty()) {
|
|
| 672 |
if (!tmp.isEmpty()) {
|
|
| 659 | 673 |
this.pProperty = StructuralUnitProperty.stringToStructuralUnitProperty(this.getParent(), tmp); |
| 660 | 674 |
} |
| 661 |
} catch (CqiClientException e) {
|
|
| 675 |
} |
|
| 676 |
catch (CqiClientException e) {
|
|
| 662 | 677 |
// TODO Auto-generated catch block |
| 663 | 678 |
e.printStackTrace(); |
| 664 | 679 |
} |
| 665 |
|
|
| 680 |
|
|
| 666 | 681 |
tmp = this.getStringParameterValue(CQPPreferences.PART_NAMES); |
| 667 | 682 |
if (tmp != null) {
|
| 668 | 683 |
this.pPartNames = Arrays.asList(tmp.split("\t"));
|
| 669 |
} else {
|
|
| 684 |
} |
|
| 685 |
else {
|
|
| 670 | 686 |
this.pPartNames = null; |
| 671 | 687 |
} |
| 672 |
|
|
| 688 |
|
|
| 673 | 689 |
tmp = this.getStringParameterValue(TXMPreferences.QUERIES); |
| 674 | 690 |
if (tmp != null) {
|
| 675 | 691 |
this.pQueries = Arrays.asList(tmp.split("\t"));
|
| 676 |
} else {
|
|
| 692 |
} |
|
| 693 |
else {
|
|
| 677 | 694 |
this.pQueries = null; |
| 678 | 695 |
} |
| 679 |
|
|
| 696 |
|
|
| 680 | 697 |
tmp = this.getStringParameterValue(TXMPreferences.VALUES); |
| 681 | 698 |
if (tmp != null) {
|
| 682 | 699 |
this.pValues = Arrays.asList(tmp.split("\t"));
|
| 683 |
} else {
|
|
| 700 |
} |
|
| 701 |
else {
|
|
| 684 | 702 |
this.pValues = null; |
| 685 | 703 |
} |
| 686 | 704 |
return true; |
| 687 | 705 |
} |
| 688 |
|
|
| 706 |
|
|
| 689 | 707 |
@Override |
| 690 | 708 |
public boolean saveParameters() {
|
| 691 |
|
|
| 692 |
if (this.pProperty != null) {
|
|
| 709 |
|
|
| 710 |
if (this.pProperty != null) {
|
|
| 693 | 711 |
this.saveParameter(TXMPreferences.STRUCTURAL_UNIT_PROPERTY, this.pProperty.getName()); |
| 694 | 712 |
} |
| 695 |
|
|
| 696 |
if (this.pPartNames != null) {
|
|
| 713 |
|
|
| 714 |
if (this.pPartNames != null) {
|
|
| 697 | 715 |
this.saveParameter(CQPPreferences.PART_NAMES, StringUtils.join(pPartNames, "\t")); |
| 698 | 716 |
} |
| 699 |
|
|
| 700 |
if (this.pQueries != null) {
|
|
| 717 |
|
|
| 718 |
if (this.pQueries != null) {
|
|
| 701 | 719 |
this.saveParameter(TXMPreferences.QUERIES, StringUtils.join(pQueries, "\t")); |
| 702 | 720 |
} |
| 703 |
|
|
| 704 |
if (this.pValues != null) {
|
|
| 721 |
|
|
| 722 |
if (this.pValues != null) {
|
|
| 705 | 723 |
this.saveParameter(TBXPreferences.VALUES, StringUtils.join(pValues, "\t")); |
| 706 | 724 |
} |
| 707 |
|
|
| 725 |
|
|
| 708 | 726 |
return true; |
| 709 | 727 |
} |
| 710 |
|
|
| 728 |
|
|
| 711 | 729 |
/** |
| 712 | 730 |
* Get the safe values (special char regexp safe). |
| 713 | 731 |
* |
| ... | ... | |
| 716 | 734 |
* @return the safe values |
| 717 | 735 |
* @throws CqiClientException the cqi client exception |
| 718 | 736 |
*/ |
| 719 |
private static List<String> getSafeValues(StructuralUnitProperty property, CQPCorpus corpus) throws CqiClientException {
|
|
| 737 |
private static List<String> getSafeValues(StructuralUnitProperty property, CQPCorpus corpus) throws CqiClientException {
|
|
| 720 | 738 |
List<String> values = property.getValues(corpus); |
| 721 |
for (int i = 0 ; i < values.size() ; i++) {
|
|
| 739 |
for (int i = 0; i < values.size(); i++) {
|
|
| 722 | 740 |
values.set(i, CQLQuery.addBackSlash(values.get(i))); |
| 723 | 741 |
} |
| 724 | 742 |
return values; |
| 725 | 743 |
} |
| 726 |
|
|
| 744 |
|
|
| 727 | 745 |
@Override |
| 728 | 746 |
public String getResultType() {
|
| 729 | 747 |
return "Partition"; |
| 730 | 748 |
} |
| 731 |
|
|
| 749 |
|
|
| 732 | 750 |
/** |
| 733 | 751 |
* Gets the parent Partition of the specified result if exists. |
| 752 |
* |
|
| 734 | 753 |
* @param result |
| 735 | 754 |
* @return the parent Partition if exists otherwise null |
| 736 | 755 |
*/ |
| 737 | 756 |
synchronized public static Partition getFirstParentPartition(TXMResult result) {
|
| 738 | 757 |
return (Partition) result.getFirstParent(Partition.class); |
| 739 | 758 |
} |
| 740 |
|
|
| 741 |
|
|
| 759 |
|
|
| 760 |
|
|
| 742 | 761 |
@Override |
| 743 | 762 |
public CQPCorpus getCorpus() {
|
| 744 | 763 |
return (CQPCorpus) parent; |
| 745 | 764 |
} |
| 746 |
|
|
| 747 |
} |
|
| 765 |
|
|
| 766 |
} |
|
Formats disponibles : Unified diff