use of de.catma.project.Project in project catma by forTEXT.
the class ProjectView method initResourceContent.
/**
* initialize the resource part
* @return
*/
private Component initResourceContent() {
HorizontalFlexLayout resourceContent = new HorizontalFlexLayout();
documentGrid = TreeGridFactory.createDefaultTreeGrid();
documentGrid.addStyleNames(// $NON-NLS-1$
"flat-undecorated-icon-buttonrenderer");
documentGrid.setHeaderVisible(false);
documentGrid.setRowHeight(45);
documentGrid.addColumn(resource -> resource.getIcon(), new HtmlRenderer()).setWidth(100);
Function<Resource, String> buildNameFunction = (resource) -> {
StringBuilder sb = new StringBuilder().append(// $NON-NLS-1$
"<div class='documentsgrid__doc'> ").append(// $NON-NLS-1$
"<div class='documentsgrid__doc__title'> ").append(resource.getName()).append(// $NON-NLS-1$
"</div>");
if (resource.hasDetail()) {
sb.append(// $NON-NLS-1$
"<span class='documentsgrid__doc__author'> ").append(resource.getDetail()).append(// $NON-NLS-1$
"</span>");
}
// $NON-NLS-1$
sb.append("</div>");
return sb.toString();
};
documentGrid.addColumn(resource -> buildNameFunction.apply(resource), new HtmlRenderer()).setCaption("Name").setId(DocumentGridColumn.NAME.name()).setWidth(300);
documentGrid.addColumn(res -> res.getPermissionIcon(), new HtmlRenderer()).setCaption("Permission").setExpandRatio(1);
Label documentsAnnotations = new Label("Documents & Annotations");
documentGridComponent = new ActionGridComponent<TreeGrid<Resource>>(documentsAnnotations, documentGrid);
// $NON-NLS-1$
documentGridComponent.addStyleName("project-view-action-grid");
resourceContent.addComponent(documentGridComponent);
tagsetGrid = new Grid<>();
tagsetGrid.setHeaderVisible(false);
// $NON-NLS-1$
tagsetGrid.setWidth("400px");
tagsetGrid.addColumn(tagset -> VaadinIcons.TAGS.getHtml(), new HtmlRenderer()).setWidth(100);
tagsetGrid.addColumn(tagset -> tagset.getName()).setId(TagsetGridColumn.NAME.name()).setCaption("Name").setWidth(300);
Label tagsetsAnnotations = new Label("Tagsets");
tagsetGridComponent = new ActionGridComponent<Grid<TagsetDefinition>>(tagsetsAnnotations, tagsetGrid);
// $NON-NLS-1$
tagsetGridComponent.addStyleName("project-view-action-grid");
resourceContent.addComponent(tagsetGridComponent);
return resourceContent;
}
use of de.catma.project.Project in project catma by forTEXT.
the class TagsetXMLExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
Project project = projectSupplier.get();
if (tagsets != null && !tagsets.isEmpty()) {
TeiDocumentFactory teiDocumentFactory = new TeiDocumentFactory();
try {
final TeiDocument teiDocument = teiDocumentFactory.createEmptyDocument(null);
final TeiTagLibrarySerializer teiTagSerializer = new TeiTagLibrarySerializer(teiDocument);
final TagManager tagManager = new TagManager(new TagLibrary());
tagsets.forEach(tagset -> tagManager.addTagsetDefinition(tagset));
final ContentInfoSet contentInfoSet = new ContentInfoSet(project.getUser().toString(), project.getDescription(), project.getUser().toString(), project.getName());
teiDocument.getTeiHeader().setValues(contentInfoSet);
teiTagSerializer.serialize(tagManager.getTagLibrary());
File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
teiDocument.printXmlDocument(fos);
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
}
}
return null;
}
use of de.catma.project.Project in project catma by forTEXT.
the class CollectionXMLExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
final Project project = projectSupplier.get();
final Corpus corpus = new Corpus();
final Collection<SourceDocument> documents = documentSupplier.get();
final Collection<AnnotationCollectionReference> collectionReferences = collectionReferenceSupplier.get();
try {
Set<String> documentIds = documents.stream().map(doc -> doc.getUuid()).collect(Collectors.toSet());
collectionReferences.stream().forEach(ref -> documentIds.add(ref.getSourceDocumentId()));
for (String documentId : documentIds) {
corpus.addSourceDocument(project.getSourceDocument(documentId));
}
if (corpus.getSourceDocuments().size() == 0) {
return null;
}
collectionReferences.forEach(ref -> corpus.addUserMarkupCollectionReference(ref));
File tempFile = File.createTempFile(new IDGenerator().generate() + "_AnnotationCollection_Export", "tgz");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
new CorpusExporter(project, true).export(project.getName(), corpus, fos);
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Documents and Collections!", e);
}
return null;
}
use of de.catma.project.Project in project catma by forTEXT.
the class TagDiffQuery method execute.
@Override
protected QueryResult execute() throws Exception {
QueryOptions queryOptions = getQueryOptions();
Project repository = queryOptions.getRepository();
Indexer indexer = queryOptions.getIndexer();
List<String> relevantUserMarkupCollIDs = queryOptions.getRelevantUserMarkupCollIDs();
if (relevantUserMarkupCollIDs.isEmpty() && !queryOptions.getRelevantSourceDocumentIDs().isEmpty()) {
relevantUserMarkupCollIDs = new ArrayList<String>();
for (String sourceDocumentId : queryOptions.getRelevantSourceDocumentIDs()) {
for (AnnotationCollectionReference umcRef : repository.getSourceDocument(sourceDocumentId).getUserMarkupCollectionRefs()) {
relevantUserMarkupCollIDs.add(umcRef.getId());
}
}
if (relevantUserMarkupCollIDs.isEmpty()) {
return new QueryResultRowArray();
}
}
QueryResult result = indexer.searchTagDiff(queryOptions.getQueryId(), relevantUserMarkupCollIDs, propertyName, tagPhrase);
for (QueryResultRow row : result) {
SourceDocument sd = repository.getSourceDocument(row.getSourceDocumentId());
TagQueryResultRow tRow = (TagQueryResultRow) row;
if (tRow.getRanges().size() > 1) {
StringBuilder builder = new StringBuilder();
String conc = "";
for (Range range : tRow.getRanges()) {
builder.append(conc);
builder.append(sd.getContent(range));
conc = "[...]";
}
row.setPhrase(builder.toString());
} else {
row.setPhrase(sd.getContent(row.getRange()));
}
}
return result;
}
use of de.catma.project.Project in project catma by forTEXT.
the class WildcardQuery method execute.
@Override
protected QueryResult execute() throws Exception {
QueryOptions queryOptions = getQueryOptions();
WildcardTermExtractor termExtractor = new WildcardTermExtractor(wildcardPhrase, queryOptions.getUnseparableCharacterSequences(), queryOptions.getUserDefinedSeparatingCharacters(), queryOptions.getLocale());
List<String> termList = termExtractor.getOrderedTerms();
Indexer indexer = queryOptions.getIndexer();
QueryResult result = indexer.searchWildcardPhrase(queryOptions.getQueryId(), queryOptions.getRelevantSourceDocumentIDs(), termList, queryOptions.getLimit());
Project repository = queryOptions.getRepository();
for (QueryResultRow row : result) {
SourceDocument sd = repository.getSourceDocument(row.getSourceDocumentId());
row.setPhrase(sd.getContent(row.getRange()));
}
return result;
}
Aggregations