Skip to content

Commit

Permalink
Merge pull request #846 from korpling/feature/avoid-context-npe
Browse files Browse the repository at this point in the history
Avoid null pointer exceptions when merging corpus configs for search …
  • Loading branch information
thomaskrause authored Mar 11, 2024
2 parents 87969a0 + 26dbe47 commit 6fb1d30
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Avoid null pointer exceptions when merging corpus configs for search
options.

## [4.11.0] - 2024-02-09

### Added
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/corpus_tools/annis/gui/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
*/
public class Helper {

private static final int DEFAULT_CONTEXT = 5;

private static final String UTF_8 = "UTF-8";

private static final Pattern validQNamePattern =
Expand Down Expand Up @@ -663,7 +665,7 @@ public static CorpusConfiguration getDefaultCorpusConfig() {
defaultCorpusConfig.setVisualizers(new LinkedList<>());

defaultCorpusConfig.getView().setPageSize(10);
defaultCorpusConfig.getContext().setDefault(5);
defaultCorpusConfig.getContext().setDefault(DEFAULT_CONTEXT);
defaultCorpusConfig.getContext().setSizes(Arrays.asList(1, 2, 5, 10));
defaultCorpusConfig.getContext().setMax(Integer.MAX_VALUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,14 @@ private CorpusConfiguration mergeConfigs(Collection<String> corpora,

// Calculate merged context
Optional<Integer> mergedDefaultCtx = selectedConfigs.stream()
.filter(config -> config.getContext() != null && config.getContext().getDefault() != null)
.map(config -> config.getContext().getDefault()).min(Comparator.naturalOrder());
if (mergedDefaultCtx.isPresent()) {
corpusConfig.getContext().setDefault(mergedDefaultCtx.get());
}

Optional<Integer> mergedMaxCtx = selectedConfigs.stream()
.filter(config -> config.getContext() != null && config.getContext().getMax() != null)
.map(config -> config.getContext().getMax()).filter(maxCtx -> maxCtx != null)
.min(Comparator.naturalOrder());
if (mergedMaxCtx.isPresent()) {
Expand All @@ -349,14 +351,17 @@ private CorpusConfiguration mergeConfigs(Collection<String> corpora,
// Add all context steps and sort them
TreeSet<Integer> contextSizes = new TreeSet<>();
for (CorpusConfiguration config : selectedConfigs) {
contextSizes.addAll(config.getContext().getSizes());
if (config.getContext() != null && config.getContext().getSizes() != null) {
contextSizes.addAll(config.getContext().getSizes());
}
}
if (!contextSizes.isEmpty()) {
corpusConfig.getContext().setSizes(new ArrayList<>(contextSizes));
}

// merge the results per page
Optional<Integer> mergedPageSize = selectedConfigs.stream()
.filter(config -> config.getView() != null && config.getView().getPageSize() != null)
.map(config -> config.getView().getPageSize()).min(Comparator.naturalOrder());
if (mergedPageSize.isPresent()) {
corpusConfig.getView().setPageSize(mergedPageSize.get());
Expand All @@ -366,14 +371,23 @@ private CorpusConfiguration mergeConfigs(Collection<String> corpora,
// It is not guaranteed that the different corpora have the same segmentation layers, but all
// corpora have token
Set<String> allContextSegmentations = selectedConfigs.stream()
.filter(
config -> config.getContext() != null && config.getContext().getSegmentation() != null)
.map(config -> config.getContext().getSegmentation()).collect(Collectors.toSet());
if (allContextSegmentations.size() == 1) {
boolean anyTokenAsSegmentation = selectedConfigs.stream().anyMatch(
config -> config.getContext() != null && config.getContext().getSegmentation() == null);
if (!anyTokenAsSegmentation && allContextSegmentations.size() == 1) {
corpusConfig.getContext().setSegmentation(allContextSegmentations.iterator().next());
}

Set<String> allBaseTextSegmentations = selectedConfigs.stream()
.filter(config -> config.getView() != null
&& config.getView().getBaseTextSegmentation() != null)
.map(config -> config.getView().getBaseTextSegmentation()).collect(Collectors.toSet());
if (allBaseTextSegmentations.size() == 1) {
boolean anyTokenAsBaseText = selectedConfigs.stream().anyMatch(
config -> config.getContext() != null && config.getContext().getSegmentation() == null);

if (!anyTokenAsBaseText && allBaseTextSegmentations.size() == 1) {
corpusConfig.getView().setBaseTextSegmentation(allBaseTextSegmentations.iterator().next());
}
return corpusConfig;
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/VAADIN/help/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:root {
/* Browser default font-size is 16px, this way 1 rem = 10px */
font-size: 62.5%;
color-scheme: var(--color-scheme);
}

html {
Expand Down
8 changes: 0 additions & 8 deletions src/main/webapp/VAADIN/help/css/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@
overflow-y: initial;
}

code {
background-color: #666666;
border-radius: 5px;

/* Force background to be printed in Chrome */
-webkit-print-color-adjust: exact;
}

pre > .buttons {
z-index: 2;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/webapp/VAADIN/help/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
--searchresults-border-color: #888;
--searchresults-li-bg: #252932;
--search-mark-bg: #e3b171;

--color-scheme: dark;
}

.coal {
Expand Down Expand Up @@ -90,6 +92,8 @@
--searchresults-border-color: #98a3ad;
--searchresults-li-bg: #2b2b2f;
--search-mark-bg: #355c7d;

--color-scheme: dark;
}

.light {
Expand Down Expand Up @@ -130,6 +134,8 @@
--searchresults-border-color: #888;
--searchresults-li-bg: #e4f2fe;
--search-mark-bg: #a2cff5;

--color-scheme: light;
}

.navy {
Expand Down Expand Up @@ -170,6 +176,8 @@
--searchresults-border-color: #5c5c68;
--searchresults-li-bg: #242430;
--search-mark-bg: #a2cff5;

--color-scheme: dark;
}

.rust {
Expand Down Expand Up @@ -210,6 +218,8 @@
--searchresults-border-color: #888;
--searchresults-li-bg: #dec2a2;
--search-mark-bg: #e69f67;

--color-scheme: light;
}

@media (prefers-color-scheme: dark) {
Expand Down

0 comments on commit 6fb1d30

Please sign in to comment.