Skip to content

Commit

Permalink
Merge #777
Browse files Browse the repository at this point in the history
777: Allow to sort the metadata annotations by name in the corpus information r=thomaskrause a=thomaskrause

This resolves #500 

Co-authored-by: Thomas Krause <[email protected]>
  • Loading branch information
bors[bot] and thomaskrause authored Jun 3, 2022
2 parents b38c728 + f86f6c8 commit faa622d
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v2
- name: Set JAVA_HOME to included JDK 8
run: echo JAVA_HOME=$JAVA_HOME_8_X64 >> $GITHUB_ENV
- run: misc/download-annis-cli.sh 2.0.3
- run: misc/download-annis-cli.sh 2.2.0
env:
OS_NAME: linux
- run: misc/import-test-corpora.sh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
key: ${{ runner.os }}-corpora-${{ hashFiles('misc/import-test-corpora.sh') }}
- name: Set JAVA_HOME to included JDK 8
run: echo JAVA_HOME=$JAVA_HOME_8_X64 >> $GITHUB_ENV
- run: misc/download-annis-cli.sh 2.0.3
- run: misc/download-annis-cli.sh 2.2.0
env:
OS_NAME: linux
- run: misc/import-test-corpora.sh
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
key: ${{ runner.os }}-corpora-${{ hashFiles('misc/import-test-corpora.sh') }}
- name: Set JAVA_HOME to included JDK 11
run: echo JAVA_HOME=$JAVA_HOME_11_X64 >> $GITHUB_ENV
- run: misc/download-annis-cli.sh 2.0.3
- run: misc/download-annis-cli.sh 2.2.0
env:
OS_NAME: linux
- run: misc/import-test-corpora.sh
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Allow to change the displayed order of corpus metadata annotations using the
`corpus_annotation_order` configuration in the `corpus-config.toml`
file.(#500)

## [4.8.0] - 2022-05-31

### Fixed
Expand Down
19 changes: 19 additions & 0 deletions docs/user-guide/src/import-and-config/corpus-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ base_text_segmentation="SEGNAME"
For more details on segmentations, see the ANNIS Multiple Segmentation Corpora
Guide.

## Order of metadata annotations

In some views, like the corpus information window (accessible by clicking on the
info icon in the corpus list), metadata annotations are shown. Per default, they
are displayed in alphabetical order. Use the `corpus_annotation_order` parameter
of the `[view]` section to explicitly define the order.

```toml
[view]
corpus_annotation_order = ["full_name", "version"]
```

For the pcc2 corpus, this would change display of the metadata in the corpus
information view:

![](ordered-metadata.png)

All non-mentioned metadata annotations are listed behind the defined ones in
alphabetical order.

## Adding Example Queries

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion misc/download-annis-cli.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

GRAPHANNIS_VERSION=${1:-1.4.1}
GRAPHANNIS_VERSION=${1:-2.2.0}

install_graphannis_cli=false

Expand Down
2 changes: 1 addition & 1 deletion misc/import-test-corpora.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

curl -L -o pcc2.zip http://corpus-tools.org/corpora/pcc2_relANNIS.zip
curl -L -o pcc2.zip https://corpus-tools.org/corpora/pcc2_v7_graphml.zip
curl -L -o dialog.zip https://corpus-tools.org/corpora/dialog.demo_relANNIS.zip
curl -L -o aeschylus.zip https://corpus-tools.org/corpora/Aeschylus.Persae.L1-18_relAnnis.zip
curl -L -o shenoute.zip https://corpus-tools.org/corpora/shenoute.a22_ANNIS.zip
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<vaadin.version>8.14.3</vaadin.version>
<vaadin.productionMode>true</vaadin.productionMode>
<start-class>org.corpus_tools.annis.gui.AnnisUiApplication</start-class>
<graphannis.version>2.1.0</graphannis.version>
<graphannis.version>2.2.0</graphannis.version>
<antlr4.version>4.7.2</antlr4.version>
<spring.profiles.active>server</spring.profiles.active>
<swagger-core-version>1.5.24</swagger-core-version>
Expand Down Expand Up @@ -254,7 +254,7 @@
<configuration>
<url>https://github.com/korpling/graphANNIS/releases/download/v${graphannis.version}/graphannis-webservice</url>
<outputDirectory>${project.build.directory}/native/linux-x86-64/</outputDirectory>
<sha256>f133cdcd04e6b9521db431d0a560a05692f0211647d152abf2a4f66d40219e65</sha256>
<sha256>ed1841b529582f9d6819f18350af67c1027f1e1669b1434af0abfb6686ed94c0</sha256>
</configuration>
</execution>
<execution>
Expand All @@ -266,7 +266,7 @@
<configuration>
<url>https://github.com/korpling/graphANNIS/releases/download/v${graphannis.version}/graphannis-webservice.exe</url>
<outputDirectory>${project.build.directory}/native/win32-x86-64/</outputDirectory>
<sha256>58d8e62a0790b33e3f52bc5fd062fa164fc3e8470f2702563ef2266f10b0bf1b</sha256>
<sha256>e5bdbf5f12ef235af2cb51045ae0548cfdeee63a6c640976c77028c99e98496f</sha256>
</configuration>
</execution>
<execution>
Expand All @@ -278,7 +278,7 @@
<configuration>
<url>https://github.com/korpling/graphANNIS/releases/download/v${graphannis.version}/graphannis-webservice.osx</url>
<outputDirectory>${project.build.directory}/native/darwin/</outputDirectory>
<sha256>254f8646da13db732e2b9198c7a7f491e0a35d8f0b5cead07d18cd9d97ffefcd</sha256>
<sha256>0c277fad3d44cfe4dd3478567e0f1a66ede3b9d87f4e15c9e7ebe38a25b8b4d3</sha256>
</configuration>
</execution>
</executions>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/corpus_tools/annis/gui/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ private static boolean annotationIsMetadata(String corpus, String annotationName


public static String getQName(final AnnoKey key) {
if (key == null) {
return null;
}
if (key.getNs() == null || key.getNs().isEmpty()) {
return key.getName();
} else {
Expand Down
130 changes: 98 additions & 32 deletions src/main/java/org/corpus_tools/annis/gui/MetaDataPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.util.concurrent.FutureCallback;
import com.vaadin.data.ValueProvider;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.server.SerializableComparator;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Accordion;
Expand All @@ -29,10 +30,12 @@
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.corpus_tools.annis.api.model.AnnoKey;
import org.corpus_tools.annis.api.model.Annotation;
import org.corpus_tools.annis.api.model.CorpusConfiguration;
import org.corpus_tools.annis.gui.components.ExceptionDialog;
import org.corpus_tools.salt.common.SCorpus;
import org.corpus_tools.salt.common.SCorpusGraph;
Expand All @@ -49,15 +52,58 @@
* @author Benjamin Weißenfels {@literal <[email protected]>}
*/
public class MetaDataPanel extends Panel {
private final class MetadataAvailableCallback implements FutureCallback<SCorpusGraph> {

private static class CorpusMetadataCallResult {
SCorpusGraph metadata;
CorpusConfiguration config;
}

private static class ConfiguredSortOrderComparator implements SerializableComparator<Annotation> {

private static final long serialVersionUID = 1L;
private ArrayList<String> corpusAnnotationOrder;

public ConfiguredSortOrderComparator(Collection<String> corpusAnnotationOrder) {
if (corpusAnnotationOrder == null) {
this.corpusAnnotationOrder = new ArrayList<>();
} else {
this.corpusAnnotationOrder = new ArrayList<>(corpusAnnotationOrder);
}

}

@Override
public int compare(Annotation o1, Annotation o2) {

String q1 = Helper.getQName(o1.getKey());
q1 = q1 == null ? "" : q1;
String q2 = Helper.getQName(o2.getKey());
q2 = q2 == null ? "" : q2;


int pos1 = this.corpusAnnotationOrder.indexOf(q1);
int pos2 = this.corpusAnnotationOrder.indexOf(q2);

if (pos1 < 0) {
pos1 = this.corpusAnnotationOrder.size();
}
if (pos2 < 0) {
pos2 = this.corpusAnnotationOrder.size();
}
return ComparisonChain.start().compare(pos1, pos2).compare(q1, q2).result();
}
}

private final class MetadataAvailableCallback
implements FutureCallback<CorpusMetadataCallResult> {
@Override
public void onFailure(Throwable t) {
layout.removeComponent(progress);
ExceptionDialog.show(t, "Could not get meta data", getUI());
}

@Override
public void onSuccess(SCorpusGraph result) {
public void onSuccess(CorpusMetadataCallResult result) {
layout.removeComponent(progress);
Accordion accordion = new Accordion();
accordion.setSizeFull();
Expand All @@ -74,11 +120,40 @@ public void onSuccess(SCorpusGraph result) {
}
}

private boolean addCorpusMetadata(SCorpusGraph result, Accordion accordion) {
private Grid<Annotation> setupTable(ListDataProvider<Annotation> metaData,
CorpusConfiguration config) {
ValueProvider<Annotation, String> nameProvider = anno -> Helper.getQName(anno.getKey());


if (config == null) {
metaData.setSortOrder(nameProvider, SortDirection.ASCENDING);
} else {
metaData.setSortComparator(
new ConfiguredSortOrderComparator(config.getView().getCorpusAnnotationOrder()));
}
Grid<Annotation> tblMeta = new Grid<>(Annotation.class);
tblMeta.setDataProvider(metaData);
Column<Annotation, String> nameColumn = tblMeta.addColumn(nameProvider);
nameColumn.setWidthUndefined();
nameColumn.setCaption("Name");
nameColumn.setId("genname");
Column<Annotation, ?> valueColumn =
tblMeta.addComponentColumn(anno -> new Label(anno.getVal(), ContentMode.HTML));
valueColumn.setId("genval");
valueColumn.setCaption("Value");

tblMeta.setColumns(nameColumn.getId(), valueColumn.getId());

tblMeta.setSizeFull();
valueColumn.setExpandRatio(1);
return tblMeta;
}

private boolean addCorpusMetadata(CorpusMetadataCallResult result, Accordion accordion) {
boolean hasResult = false;

// Sort the (sub-) corpora so sub-corpora come first
List<SCorpus> corpora = new ArrayList<>(result.getCorpora());
List<SCorpus> corpora = new ArrayList<>(result.metadata.getCorpora());
corpora.sort((c1, c2) -> {
URI u1 = c1.getPath();
URI u2 = c2.getPath();
Expand All @@ -98,24 +173,26 @@ private boolean addCorpusMetadata(SCorpusGraph result, Accordion accordion) {
corpusAnnos.add(anno);
}


if (!corpusAnnos.isEmpty()) {

String path = c.getPath().toString();
if (path.startsWith("salt:/")) {
path = path.substring("salt:/".length());
}
path = path + " (corpus)";
accordion.addTab(setupTable(new ListDataProvider<>(corpusAnnos)), path);
accordion.addTab(setupTable(new ListDataProvider<>(corpusAnnos), result.config), path);
hasResult = true;
}
}
return hasResult;
}

private boolean addDocumentMetadata(SCorpusGraph result, Accordion accordion) {
private boolean addDocumentMetadata(CorpusMetadataCallResult result, Accordion accordion) {
boolean hasResult = false;

// Add all document metadata first, then the corpus metadata
List<SDocument> documents = result.getDocuments();
List<SDocument> documents = result.metadata.getDocuments();
if (documents != null) {
// There should only be one document in the corpus graph, but keeping the code generic
// should not hurt
Expand All @@ -141,7 +218,7 @@ private boolean addDocumentMetadata(SCorpusGraph result, Accordion accordion) {
path = path + " (document)";
}

accordion.addTab(setupTable(new ListDataProvider<>(docAnnos)), path);
accordion.addTab(setupTable(new ListDataProvider<>(docAnnos), result.config), path);
hasResult = true;
}
}
Expand Down Expand Up @@ -215,7 +292,6 @@ public MetaDataPanel(String toplevelCorpusName, Optional<String> documentName) {

layout.addComponent(progress);
layout.setComponentAlignment(progress, Alignment.MIDDLE_CENTER);

}


Expand All @@ -225,29 +301,19 @@ public void attach() {

final UI ui = getUI();

Background.runWithCallback(() -> Helper.getMetaData(toplevelCorpusName, documentName, ui),
new MetadataAvailableCallback());
}
Background.runWithCallback(() -> {
CorpusMetadataCallResult result = new CorpusMetadataCallResult();

result.metadata = Helper.getMetaData(toplevelCorpusName, documentName, ui);
if (ui instanceof AnnisUI) {
result.config = ((AnnisUI) ui).getCorpusConfigWithCache(toplevelCorpusName);
} else {
result.config = Helper.getCorpusConfig(toplevelCorpusName, ui);
}
return result;

private Grid<Annotation> setupTable(ListDataProvider<Annotation> metaData) {
ValueProvider<Annotation, String> nameProvider = anno -> Helper.getQName(anno.getKey());
metaData.setSortOrder(nameProvider, SortDirection.ASCENDING);

Grid<Annotation> tblMeta = new Grid<>(Annotation.class);
tblMeta.setDataProvider(metaData);
Column<Annotation, String> nameColumn = tblMeta.addColumn(nameProvider);
nameColumn.setWidthUndefined();
nameColumn.setCaption("Name");
nameColumn.setId("genname");
Column<Annotation, ?> valueColumn =
tblMeta.addComponentColumn(anno -> new Label(anno.getVal(), ContentMode.HTML));
valueColumn.setId("genval");
valueColumn.setCaption("Value");

tblMeta.setColumns(nameColumn.getId(), valueColumn.getId());

tblMeta.setSizeFull();
valueColumn.setExpandRatio(1);
return tblMeta;
}, new MetadataAvailableCallback());
}


}
14 changes: 13 additions & 1 deletion src/main/java/org/corpus_tools/annis/gui/ServiceStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ServiceStarter
implements ApplicationListener<ApplicationReadyEvent>, DisposableBean {


private static final String LOGGING_SECTION = "logging";

private final static Logger log = LoggerFactory.getLogger(ServiceStarter.class);

@Autowired
Expand Down Expand Up @@ -195,7 +197,17 @@ protected File getServiceConfig() throws IOException {
Paths.get(System.getProperty("user.home"), ".annis", "v4", "service_data.sqlite3")
.toAbsolutePath().toString());

if (previousDatabase == null || previousSqlite == null) {
// Change service debug level if ANNIS itself is in debug mode
Map<String, Object> loggingConfig;
if (configToml.isTable(LOGGING_SECTION)) {
loggingConfig = configToml.getTable(LOGGING_SECTION).toMap();
} else {
loggingConfig = new LinkedHashMap<>();
config.put(LOGGING_SECTION, loggingConfig);
}
Object previousDebugConfig = loggingConfig.put("debug", log.isDebugEnabled());

if (previousDatabase == null || previousSqlite == null || previousDebugConfig == null) {
// Write updated configuration to file
TomlWriter writer = new TomlWriter();
writer.write(config, result);
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,16 @@ components:
items:
type: string
description: A list of fully qualified annotation names that should be hidden when displayed.
corpus_annotation_order:
type: array
items:
type: string
description: >
A sorted list of fully qualified annotation names. When showing
(metadata) annotations for a (sub)-corpus, the given annotations
should be displayed first and in the given order. Annotations
not listed should be appended in alphabetical order to the given
entries.
example_queries:
type: array
description: An array of example queries for the corpus with a description.
Expand Down
Loading

0 comments on commit faa622d

Please sign in to comment.