From 9f626b38de15c50361f4bd5a279f1ef950291b22 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Wed, 20 Sep 2023 22:00:02 +0200 Subject: [PATCH] #4196 - Save memory by not creating empty arrays in CAS - Adjust link features and multi-value features to not store empty arrays --- .../feature/multistring/MultiValueStringFeatureSupport.java | 2 +- .../ukp/inception/schema/feature/FeatureUtil.java | 5 +++++ .../ui/kb/feature/MultiValueConceptFeatureSupport.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/feature/multistring/MultiValueStringFeatureSupport.java b/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/feature/multistring/MultiValueStringFeatureSupport.java index 193c7d3c59d..6009aa47e8a 100644 --- a/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/feature/multistring/MultiValueStringFeatureSupport.java +++ b/inception/inception-api-annotation/src/main/java/de/tudarmstadt/ukp/inception/annotation/feature/multistring/MultiValueStringFeatureSupport.java @@ -137,7 +137,7 @@ public void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, FeatureStructure fs = getFS(aCas, aFeature, aAddress); List values = unwrapFeatureValue(aFeature, fs.getCAS(), aValue); - if (values == null) { + if (values == null || values.isEmpty()) { FSUtil.setFeature(fs, aFeature.getName(), (Collection) null); return; } diff --git a/inception/inception-api-schema/src/main/java/de/tudarmstadt/ukp/inception/schema/feature/FeatureUtil.java b/inception/inception-api-schema/src/main/java/de/tudarmstadt/ukp/inception/schema/feature/FeatureUtil.java index be5dd5c63c0..b230822aeed 100644 --- a/inception/inception-api-schema/src/main/java/de/tudarmstadt/ukp/inception/schema/feature/FeatureUtil.java +++ b/inception/inception-api-schema/src/main/java/de/tudarmstadt/ukp/inception/schema/feature/FeatureUtil.java @@ -147,6 +147,11 @@ private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeat public static void setLinkFeatureValue(FeatureStructure aFS, Feature aFeature, List linkFSes) { + if (linkFSes == null || linkFSes.isEmpty()) { + aFS.setFeatureValue(aFeature, null); + return; + } + // Create a new array if size differs otherwise re-use existing one var array = (ArrayFS) ICasUtil.getFeatureFS(aFS, aFeature.getShortName()); if (array == null || (array.size() != linkFSes.size())) { diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/feature/MultiValueConceptFeatureSupport.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/feature/MultiValueConceptFeatureSupport.java index ac5f923bbfe..e759337033d 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/feature/MultiValueConceptFeatureSupport.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/feature/MultiValueConceptFeatureSupport.java @@ -282,7 +282,7 @@ public void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, FeatureStructure fs = getFS(aCas, aFeature, aAddress); List values = unwrapFeatureValue(aFeature, fs.getCAS(), aValue); - if (values == null) { + if (values == null || values.isEmpty()) { FSUtil.setFeature(fs, aFeature.getName(), (Collection) null); return; }