From 948c0ed743f8a44f666d3e4d7467c273c29126d9 Mon Sep 17 00:00:00 2001 From: pkiraly Date: Wed, 7 Jul 2021 22:39:24 +0200 Subject: [PATCH] issue #74: enabling field extractor only if there are extractable fields in the schema. --- .../api/calculator/CalculatorFactory.java | 2 +- .../api/calculator/CalculatorFactoryTest.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/test/java/de/gwdg/metadataqa/api/calculator/CalculatorFactoryTest.java diff --git a/src/main/java/de/gwdg/metadataqa/api/calculator/CalculatorFactory.java b/src/main/java/de/gwdg/metadataqa/api/calculator/CalculatorFactory.java index 01a9ac65..850eb813 100644 --- a/src/main/java/de/gwdg/metadataqa/api/calculator/CalculatorFactory.java +++ b/src/main/java/de/gwdg/metadataqa/api/calculator/CalculatorFactory.java @@ -47,7 +47,7 @@ private void configure() { } private void addExtractor() { - if (configuration.isFieldExtractorEnabled()) + if (configuration.isFieldExtractorEnabled() && !schema.getExtractableFields().isEmpty()) calculators.add(new FieldExtractor(schema)); } diff --git a/src/test/java/de/gwdg/metadataqa/api/calculator/CalculatorFactoryTest.java b/src/test/java/de/gwdg/metadataqa/api/calculator/CalculatorFactoryTest.java new file mode 100644 index 00000000..f85316b3 --- /dev/null +++ b/src/test/java/de/gwdg/metadataqa/api/calculator/CalculatorFactoryTest.java @@ -0,0 +1,49 @@ +package de.gwdg.metadataqa.api.calculator; + +import de.gwdg.metadataqa.api.configuration.MeasurementConfiguration; +import de.gwdg.metadataqa.api.interfaces.Calculator; +import de.gwdg.metadataqa.api.json.JsonBranch; +import de.gwdg.metadataqa.api.schema.BaseSchema; +import de.gwdg.metadataqa.api.schema.Format; +import de.gwdg.metadataqa.api.schema.Schema; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +public class CalculatorFactoryTest { + + @Test + public void createWithExtractable() { + Schema schema = new BaseSchema() + .setFormat(Format.CSV) + .addField(new JsonBranch("url")) + .addField(new JsonBranch("name").setExtractable()); + + MeasurementConfiguration config = new MeasurementConfiguration() + .enableFieldExtractor() + .enableCompletenessMeasurement(); + + List calculators = CalculatorFactory.create(config, schema); + assertEquals(2, calculators.size()); + assertEquals("fieldExtractor", calculators.get(0).getCalculatorName()); + assertEquals("completeness", calculators.get(1).getCalculatorName()); + } + + @Test + public void createWithoutExtractable() { + Schema schema = new BaseSchema() + .setFormat(Format.CSV) + .addField(new JsonBranch("url")) + .addField(new JsonBranch("name")); + + MeasurementConfiguration config = new MeasurementConfiguration() + .enableFieldExtractor() + .enableCompletenessMeasurement(); + + List calculators = CalculatorFactory.create(config, schema); + assertEquals(1, calculators.size()); + assertEquals("completeness", calculators.get(0).getCalculatorName()); + } +} \ No newline at end of file