Skip to content

Commit

Permalink
issue #74: enabling field extractor only if there are extractable fie…
Browse files Browse the repository at this point in the history
…lds in the schema.
  • Loading branch information
pkiraly committed Jul 7, 2021
1 parent 2849cad commit 948c0ed
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void configure() {
}

private void addExtractor() {
if (configuration.isFieldExtractorEnabled())
if (configuration.isFieldExtractorEnabled() && !schema.getExtractableFields().isEmpty())
calculators.add(new FieldExtractor(schema));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Calculator> 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<Calculator> calculators = CalculatorFactory.create(config, schema);
assertEquals(1, calculators.size());
assertEquals("completeness", calculators.get(0).getCalculatorName());
}
}

0 comments on commit 948c0ed

Please sign in to comment.