39 |
39 |
import java.util.UUID;
|
40 |
40 |
|
41 |
41 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
42 |
import org.eclipse.osgi.util.NLS;
|
42 |
43 |
import org.txm.Toolbox;
|
43 |
44 |
import org.txm.core.messages.TXMCoreMessages;
|
44 |
45 |
import org.txm.core.results.TXMParameters;
|
... | ... | |
80 |
81 |
public MainCorpus(Project project) throws InvalidCqpIdException, CqiClientException {
|
81 |
82 |
super(project);
|
82 |
83 |
this.internalPersistable = true;
|
83 |
|
|
|
84 |
|
84 |
85 |
this.dataDirectory = new File(getProjectDirectory(), "data/"+getID());
|
85 |
86 |
this.registryFile = new File(getProjectDirectory(), "registry/"+getID().toLowerCase());
|
86 |
87 |
}
|
... | ... | |
110 |
111 |
*/
|
111 |
112 |
public MainCorpus(String parametersNodePath) throws InvalidCqpIdException, CqiClientException {
|
112 |
113 |
super(parametersNodePath);
|
113 |
|
|
|
114 |
|
114 |
115 |
this.internalPersistable = true;
|
115 |
|
|
|
116 |
|
116 |
117 |
this.dataDirectory = new File(getProjectDirectory(), "data/"+getID());
|
117 |
118 |
this.registryFile = new File(getProjectDirectory(), "registry/"+getID().toLowerCase());
|
118 |
119 |
}
|
... | ... | |
194 |
195 |
@Override
|
195 |
196 |
public int getSize() throws CqiClientException {
|
196 |
197 |
if (!hasBeenComputedOnce) return 0;
|
197 |
|
|
|
198 |
|
198 |
199 |
if (this.size == -1) {
|
199 |
200 |
try {
|
200 |
201 |
this.size = CorpusManager.getCorpusManager().getCqiClient()
|
... | ... | |
448 |
449 |
}
|
449 |
450 |
return textids;
|
450 |
451 |
}
|
451 |
|
|
|
452 |
|
452 |
453 |
/**
|
453 |
454 |
*
|
454 |
455 |
* @return the text_id values of the CQP corpus ordered by position
|
... | ... | |
457 |
458 |
* @throws CqiServerError
|
458 |
459 |
*/
|
459 |
460 |
public String[] getCorpusTextIdsList() throws CqiClientException, IOException, CqiServerError {
|
460 |
|
|
|
461 |
|
461 |
462 |
int nbtext = getNbTexts();
|
462 |
463 |
int[] structs = new int[nbtext];
|
463 |
464 |
for(int i = 0 ; i < nbtext ; i++)
|
... | ... | |
465 |
466 |
|
466 |
467 |
StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$
|
467 |
468 |
StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$
|
468 |
|
|
|
469 |
|
469 |
470 |
return CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs);
|
470 |
471 |
}
|
471 |
472 |
|
... | ... | |
566 |
567 |
}
|
567 |
568 |
|
568 |
569 |
protected boolean modified = false;
|
|
570 |
/**
|
|
571 |
* list of loaded/computed corpus
|
|
572 |
*/
|
|
573 |
private static HashMap<String, MainCorpus> corpora = new HashMap<String, MainCorpus>();
|
569 |
574 |
public boolean isModified() { return modified; }
|
570 |
575 |
public void setIsModified(boolean b) { modified = b; }
|
571 |
576 |
|
... | ... | |
583 |
588 |
@Override
|
584 |
589 |
public void clean() {
|
585 |
590 |
super.clean();
|
586 |
|
|
|
591 |
|
|
592 |
if (corpora.get(this.pID) == this) { // un register the MainCorpus
|
|
593 |
corpora.remove(this.pID);
|
|
594 |
}
|
|
595 |
|
587 |
596 |
try {
|
588 |
597 |
if (CQPSearchEngine.isInitialized()) {
|
589 |
598 |
CQPSearchEngine.getCqiClient().dropCorpus(getID());
|
... | ... | |
594 |
603 |
|
595 |
604 |
DeleteDir.deleteDirectory(dataDirectory);
|
596 |
605 |
registryFile.delete();
|
597 |
|
|
|
606 |
|
598 |
607 |
Toolbox.notifyEngines(this, "clean");
|
599 |
608 |
}
|
600 |
609 |
|
... | ... | |
630 |
639 |
|
631 |
640 |
@Override
|
632 |
641 |
protected boolean _compute() throws Exception {
|
|
642 |
if (corpora.get(this.pID) != null && corpora.get(this.pID) != this) {
|
|
643 |
System.out.println(NLS.bind("Warning: duplicated \"{0}\" CQP corpus in \"{1}\"", this.pID, this.getProjectDirectory()));
|
|
644 |
return false;
|
|
645 |
}
|
|
646 |
|
|
647 |
if (CQPSearchEngine.isInitialized()) {
|
|
648 |
try {
|
|
649 |
CQPSearchEngine.getCqiClient().corpusCharset(this.pID);
|
|
650 |
corpora.put(this.pID, this); // register the corpus
|
|
651 |
} catch(Exception e) {
|
|
652 |
if (corpora.get(this.pID) == this) {
|
|
653 |
corpora.remove(this.pID); // unregister the broken corpus
|
|
654 |
}
|
|
655 |
return false;
|
|
656 |
}
|
|
657 |
}
|
633 |
658 |
return true;
|
634 |
659 |
}
|
635 |
660 |
|
... | ... | |
638 |
663 |
return "Corpus";
|
639 |
664 |
}
|
640 |
665 |
|
641 |
|
public void setID(String id) {
|
|
666 |
protected void setID(String id) {
|
642 |
667 |
this.pID = id;
|
643 |
668 |
}
|
644 |
669 |
}
|