use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class DocumentServiceImpl method createOrGetAnnotationDocument.
@Override
@Transactional(noRollbackFor = NoResultException.class)
public AnnotationDocument createOrGetAnnotationDocument(SourceDocument aDocument, User aUser) {
// Check if there is an annotation document entry in the database. If there is none,
// create one.
AnnotationDocument annotationDocument = null;
if (!existsAnnotationDocument(aDocument, aUser)) {
annotationDocument = new AnnotationDocument();
annotationDocument.setDocument(aDocument);
annotationDocument.setName(aDocument.getName());
annotationDocument.setUser(aUser.getUsername());
annotationDocument.setProject(aDocument.getProject());
createAnnotationDocument(annotationDocument);
} else {
annotationDocument = getAnnotationDocument(aDocument, aUser);
}
return annotationDocument;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class DocumentServiceImpl method removeSourceDocument.
@Override
@Transactional
public void removeSourceDocument(SourceDocument aDocument) throws IOException {
// BeforeDocumentRemovedEvent is triggered first, since methods that rely
// on it might need to have access to the associated annotation documents
applicationEventPublisher.publishEvent(new BeforeDocumentRemovedEvent(this, aDocument));
for (AnnotationDocument annotationDocument : listAllAnnotationDocuments(aDocument)) {
removeAnnotationDocument(annotationDocument);
}
entityManager.remove(entityManager.contains(aDocument) ? aDocument : entityManager.merge(aDocument));
String path = dir.getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aDocument.getProject().getId() + "/" + DOCUMENT_FOLDER + "/" + aDocument.getId();
// remove from file both source and related annotation file
if (new File(path).exists()) {
FileUtils.forceDelete(new File(path));
}
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
Project project = aDocument.getProject();
log.info("Removed source document [{}]({}) from project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class RemoteApiController2 method annotationsDelete.
@ApiOperation(value = "Delete a user's annotations of one document from a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + ANNOTATIONS + "/{" + PARAM_ANNOTATOR_ID + "}", method = RequestMethod.DELETE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<Void>> annotationsDelete(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId, @PathVariable(PARAM_ANNOTATOR_ID) String aAnnotatorId) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
SourceDocument doc = getDocument(project, aDocumentId);
AnnotationDocument anno = getAnnotation(doc, aAnnotatorId, false);
documentService.removeAnnotationDocument(anno);
documentService.deleteAnnotationCas(anno);
return ResponseEntity.ok(new RResponse<>(INFO, "Annotations of user [" + aAnnotatorId + "] on document [" + aDocumentId + "] deleted from project [" + aProjectId + "]."));
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class RemoteApiController2 method annotationsCreate.
@ApiOperation(value = "Create annotations for a document in a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + ANNOTATIONS + "/{" + PARAM_ANNOTATOR_ID + "}", method = RequestMethod.POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RAnnotation>> annotationsCreate(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId, @PathVariable(PARAM_ANNOTATOR_ID) String aAnnotatorId, @RequestParam(value = PARAM_CONTENT) MultipartFile aFile, @RequestParam(value = PARAM_FORMAT) Optional<String> aFormat, @RequestParam(value = PARAM_STATE) Optional<String> aState, UriComponentsBuilder aUcb) throws Exception {
User annotator = getUser(aAnnotatorId);
Project project = getProject(aProjectId);
SourceDocument document = getDocument(project, aDocumentId);
AnnotationDocument anno = getAnnotation(document, aAnnotatorId, true);
JCas annotationCas = createCompatibleCas(aProjectId, aDocumentId, aFile, aFormat);
// If they are compatible, then we can store the new annotations
documentService.writeAnnotationCas(annotationCas, document, annotator, false);
// Set state if one was provided
if (aState.isPresent()) {
anno.setState(parseAnnotationDocumentState(aState.get()));
documentService.createAnnotationDocument(anno);
}
RResponse<RAnnotation> response = new RResponse<>(new RAnnotation(anno));
if (aState.isPresent()) {
response.addMessage(INFO, "State of annotations of user [" + aAnnotatorId + "] on document [" + document.getId() + "] set to [" + aState.get() + "]");
}
return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{pid}/" + DOCUMENTS + "/{did}/" + ANNOTATIONS + "/{aid}").buildAndExpand(project.getId(), document.getId(), annotator.getUsername()).toUri()).body(response);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class AutomationUtil method generatePredictDocument.
// TODO: rename to predictDocument
public static void generatePredictDocument(MiraTemplate aTemplate, DocumentService aRepository, CorrectionDocumentService aCorrectionDocumentService, AnnotationSchemaService aAnnotationService, AutomationService aAutomationService, UserDao aUserDao) throws IOException, UIMAException, ClassNotFoundException {
File miraDir = aAutomationService.getMiraDir(aTemplate.getTrainFeature());
if (!miraDir.exists()) {
FileUtils.forceMkdir(miraDir);
}
User user = aUserDao.getCurrentUser();
AnnotationFeature feature = aTemplate.getTrainFeature();
AutomationTypeAdapter adapter = (AutomationTypeAdapter) aAnnotationService.getAdapter(feature.getLayer());
for (SourceDocument document : aRepository.listSourceDocuments(feature.getProject())) {
File predFile = new File(miraDir, document.getId() + ".pred.ft");
BufferedWriter predOut = new BufferedWriter(new FileWriter(predFile));
JCas jCas;
try {
jCas = aCorrectionDocumentService.readCorrectionCas(document);
} catch (Exception e) {
AnnotationDocument annoDoc = aRepository.createOrGetAnnotationDocument(document, user);
jCas = aRepository.readAnnotationCas(annoDoc);
}
for (Sentence sentence : select(jCas, Sentence.class)) {
predOut.append(getMiraLine(sentence, null, adapter).toString()).append("\n");
}
predOut.close();
}
}
Aggregations