Search in sources :

Example 1 with CorpusEvent

use of gate.event.CorpusEvent in project gate-core by GateNLP.

the class SerialCorpusImpl method add.

@Override
public void add(int index, Document o) {
    if (o == null)
        return;
    Document doc = o;
    DocumentData docData = new DocumentData(doc.getName(), doc.getLRPersistenceId(), doc.getClass().getName());
    docDataList.add(index, docData);
    documents.add(index, doc);
    documentAdded(doc);
    fireDocumentAdded(new CorpusEvent(SerialCorpusImpl.this, doc, index, doc.getLRPersistenceId(), CorpusEvent.DOCUMENT_ADDED));
}
Also used : CorpusEvent(gate.event.CorpusEvent) Document(gate.Document)

Example 2 with CorpusEvent

use of gate.event.CorpusEvent in project gate-core by GateNLP.

the class SerialCorpusImpl method remove.

@Override
public boolean remove(Object o) {
    if (DEBUG)
        Out.prln("SerialCorpus:Remove object called");
    if (!(o instanceof Document))
        return false;
    Document doc = (Document) o;
    // see if we can find it first. If not, then judt return
    int index = findDocument(doc);
    if (index == -1)
        return false;
    if (index < docDataList.size()) {
        // we found it, so remove it
        // by Andrey Shafirin: this part of code can produce an exception
        // if
        // document wasn't loaded
        String docName = docDataList.get(index).getDocumentName();
        Object docPersistentID = getDocumentPersistentID(index);
        docDataList.remove(index);
        // Document oldDoc = (Document) documents.remove(index);
        documents.remove(index);
        // + " are " + documents);
        if (DEBUG)
            Out.prln("documents after remove of " + docName + " are " + documents);
        // documentRemoved(oldDoc.getLRPersistenceId().toString());
        if (docPersistentID != null)
            documentRemoved(docPersistentID.toString());
        // fireDocumentRemoved(new CorpusEvent(SerialCorpusImpl.this,
        // oldDoc,
        // index,
        // CorpusEvent.DOCUMENT_REMOVED));
        fireDocumentRemoved(new CorpusEvent(SerialCorpusImpl.this, (Document) o, index, docPersistentID, CorpusEvent.DOCUMENT_REMOVED));
    }
    return true;
}
Also used : CorpusEvent(gate.event.CorpusEvent) Document(gate.Document)

Example 3 with CorpusEvent

use of gate.event.CorpusEvent in project gate-core by GateNLP.

the class SerialCorpusImpl method add.

@Override
public boolean add(Document o) {
    if (o == null)
        return false;
    Document doc = o;
    // make it accept only docs from its own datastore
    if (doc.getDataStore() != null && !this.dataStore.equals(doc.getDataStore())) {
        Err.prln("Error: Persistent corpus can only accept documents " + "from its own datastore!");
        return false;
    }
    // if
    // add the document with its index in the docDataList
    // in this case, since it's going to be added to the end
    // the index will be the size of the docDataList before
    // the addition
    DocumentData docData = new DocumentData(doc.getName(), doc.getLRPersistenceId(), doc.getClass().getName());
    boolean result = docDataList.add(docData);
    documents.add(doc);
    documentAdded(doc);
    fireDocumentAdded(new CorpusEvent(SerialCorpusImpl.this, doc, docDataList.size() - 1, doc.getLRPersistenceId(), CorpusEvent.DOCUMENT_ADDED));
    return result;
}
Also used : CorpusEvent(gate.event.CorpusEvent) Document(gate.Document)

Example 4 with CorpusEvent

use of gate.event.CorpusEvent in project gate-core by GateNLP.

the class SerialCorpusImpl method remove.

@Override
public Document remove(int index) {
    if (DEBUG)
        Out.prln("Remove index called");
    // try to get the actual document if it was loaded
    Document res = isDocumentLoaded(index) ? get(index) : null;
    Object docLRID = docDataList.get(index).persistentID;
    if (docLRID != null)
        documentRemoved(docLRID.toString());
    docDataList.remove(index);
    documents.remove(index);
    fireDocumentRemoved(new CorpusEvent(SerialCorpusImpl.this, res, index, docLRID, CorpusEvent.DOCUMENT_REMOVED));
    return res;
}
Also used : CorpusEvent(gate.event.CorpusEvent) Document(gate.Document)

Aggregations

Document (gate.Document)4 CorpusEvent (gate.event.CorpusEvent)4