示例#1
0
 /**
  * Gets the persistent IDs of the documents in this corpus.
  *
  * @return a {@link List} of Objects representing the persistent IDs of the documents in this
  *     corpus.
  */
 public List<Object> getDocumentPersistentIDs() {
   List<Object> docsIDs = new ArrayList<Object>();
   if (docDataList == null) return docsIDs;
   Iterator<DocumentData> iter = docDataList.iterator();
   while (iter.hasNext()) {
     DocumentData data = iter.next();
     docsIDs.add(data.getPersistentID());
   }
   return docsIDs;
 }
示例#2
0
  /** Called by a datastore when a resource has been deleted */
  @Override
  public void resourceDeleted(DatastoreEvent evt) {
    DataStore ds = (DataStore) evt.getSource();
    // 1. check whether this datastore fired the event. If not, return.
    if (!ds.equals(this.dataStore)) return;

    Object docID = evt.getResourceID();
    if (docID == null) return;

    if (DEBUG) Out.prln("Resource deleted called for: " + docID);
    // first check if it is this corpus that's been deleted, it must be
    // unloaded immediately
    if (docID.equals(this.getLRPersistenceId())) {
      Factory.deleteResource(this);
      return;
    } // if

    boolean isDirty = false;
    // the problem here is that I only have the doc persistent ID
    // and nothing else, so I need to determine the index of the doc
    // first
    for (int i = 0; i < docDataList.size(); i++) {
      DocumentData docData = docDataList.get(i);
      // we've found the correct document
      // don't break the loop, because it might appear more than once
      if (docID.equals(docData.getPersistentID())) {
        if (evt.getResource() == null) {
          // instead of calling remove() which tries to load the
          // document
          // remove it from the documents and docDataList
          documentRemoved(docDataList.get(i).persistentID.toString());
          docDataList.remove(i);
          documents.remove(i);
          isDirty = true;
          i--;
          continue;
        }

        remove(i);
        isDirty = true;
      } // if
    } // for loop through the doc data

    if (isDirty)
      try {
        this.dataStore.sync(this);
      } catch (PersistenceException ex) {
        throw new GateRuntimeException("SerialCorpusImpl: " + ex.getMessage());
      } catch (SecurityException sex) {
        throw new GateRuntimeException("SerialCorpusImpl: " + sex.getMessage());
      }
  } // resourceDeleted
示例#3
0
  public int findDocument(Document doc) {
    boolean found = false;
    DocumentData docData = null;

    // first try finding the document in memory
    int index = documents.indexOf(doc);
    if (index > -1 && index < docDataList.size()) return index;

    // else try finding a document with the same name and persistent ID
    Iterator<DocumentData> iter = docDataList.iterator();
    for (index = 0; iter.hasNext(); index++) {
      docData = iter.next();
      if (docData.getDocumentName().equals(doc.getName())
          && docData.getPersistentID().equals(doc.getLRPersistenceId())
          && docData.getClassType().equals(doc.getClass().getName())) {
        found = true;
        break;
      }
    }
    if (found && index < docDataList.size()) return index;
    else return -1;
  } // findDocument