Search in sources :

Example 11 with TrainingDocument

use of de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument in project webanno by webanno.

the class ExportUtil method exportTrainingDocuments.

/**
 * Export {@link TrainingDocument}
 */
public static void exportTrainingDocuments(AutomationService automationService, ProjectExportRequest model, Project aProject, File aCopyDir) throws IOException, ProjectExportException {
    File trainDocumentDir = new File(aCopyDir + TRAIN_FOLDER);
    FileUtils.forceMkdir(trainDocumentDir);
    // Get all the training documents from the project
    List<TrainingDocument> documents = automationService.listTrainingDocuments(aProject);
    int i = 1;
    for (TrainingDocument trainingDocument : documents) {
        try {
            FileUtils.copyFileToDirectory(automationService.getTrainingDocumentFile(trainingDocument), trainDocumentDir);
            model.progress = (int) Math.ceil(((double) i) / documents.size() * 10.0);
            i++;
            LOG.info("Imported content for training document [" + trainingDocument.getId() + "] in project [" + aProject.getName() + "] with id [" + aProject.getId() + "]");
        } catch (FileNotFoundException e) {
            // error(e.getMessage());
            StringBuilder errorMessage = new StringBuilder();
            errorMessage.append("Source file '");
            errorMessage.append(trainingDocument.getName());
            errorMessage.append("' related to project couldn't be located in repository");
            LOG.error(errorMessage.toString(), ExceptionUtils.getRootCause(e));
            model.messages.add(errorMessage.toString());
            throw new ProjectExportException("Couldn't find some source file(s) related to project");
        // continue;
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) TrainingDocument(de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument)

Aggregations

TrainingDocument (de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument)11 File (java.io.File)7 ArrayList (java.util.ArrayList)5 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)4 AutomationTypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.AutomationTypeAdapter)3 AutomationStatus (de.tudarmstadt.ukp.clarin.webanno.automation.model.AutomationStatus)3 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)3 BufferedWriter (java.io.BufferedWriter)3 FileReader (java.io.FileReader)3 FileWriter (java.io.FileWriter)3 StringTokenizer (java.util.StringTokenizer)3 LineIterator (org.apache.commons.io.LineIterator)3 JCas (org.apache.uima.jcas.JCas)3 MiraTemplate (de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)2 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)2 Mira (edu.lium.mira.Mira)2 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1