Skip to content

Commit

Permalink
Rename PathCache to Selector #129
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed May 1, 2023
1 parent c1516a1 commit 27e8144
Show file tree
Hide file tree
Showing 95 changed files with 351 additions and 355 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<project.region>US</project.region>
<argLine>-Duser.timezone=${project.timezone} -Dfile.encoding=${project.build.sourceEncoding} -Duser.language=${project.language} -Duser.region=${project.region}</argLine>
<skipUnitTests>false</skipUnitTests>
<testsToExclude>edu.harvard.iq.dataverse.NonEssentialTests</testsToExclude>

<!-- sonarcloud properties -->
<sonar.projectKey>pkiraly_metadata-qa-api</sonar.projectKey>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.interfaces.Calculator;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;

import java.io.Serializable;
Expand All @@ -24,7 +24,7 @@ public AnnotationCalculator(Map<String, Object> annotaionColumns) {
}

@Override
public List<MetricResult> measure(PathCache cache) {
public List<MetricResult> measure(Selector cache) {
if (results == null) {
FieldCounter<Object> resultMap = new FieldCounter<>();
for (Map.Entry<String, Object> entry : annotaionColumns.entrySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import de.gwdg.metadataqa.api.interfaces.Calculator;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.interfaces.Shutdownable;
import de.gwdg.metadataqa.api.model.pathcache.CsvPathCache;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.PathCacheFactory;
import de.gwdg.metadataqa.api.model.selector.CsvSelector;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.model.selector.SelectorFactory;
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
import de.gwdg.metadataqa.api.schema.Format;
import de.gwdg.metadataqa.api.schema.Schema;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class CalculatorFacade implements Serializable {
protected TfIdfCalculator tfidfCalculator;

// protected Format format = Format.JSON;
protected PathCache<? extends XmlFieldInstance> cache;
protected Selector<? extends XmlFieldInstance> cache;
protected Schema schema;
protected CsvReader csvReader;

Expand Down Expand Up @@ -184,7 +184,7 @@ protected <T extends XmlFieldInstance> Object measureWithGenerics(String content
} else {
var format = schema.getFormat();
if (format != null && content != null) {
cache = PathCacheFactory.getInstance(schema.getFormat(), content);
cache = SelectorFactory.getInstance(schema.getFormat(), content);
if (schema.getFormat().equals(Format.CSV))
initializeCsvCache(content);

Expand All @@ -208,7 +208,7 @@ private void initializeCsvCache(String content) {
LOGGER.log(Level.WARNING, "initializeCsvCache", e);
}

((CsvPathCache)cache).setCsvReader(csvReader);
((CsvSelector)cache).setCsvReader(csvReader);
}

protected <T extends XmlFieldInstance> Object measureCsvWithGenerics(List<String> content,
Expand All @@ -226,7 +226,7 @@ protected <T extends XmlFieldInstance> Object measureCsvWithGenerics(List<String
MetricCollector collector = new MetricCollector();

if (content != null) {
cache = new CsvPathCache<>(csvReader, content);
cache = new CsvSelector<>(csvReader, content);
runMeasurements(collector);
}

Expand Down Expand Up @@ -314,7 +314,7 @@ public CalculatorFacade setCompressionLevel(CompressionLevel compressionLevel) {
return this;
}

public PathCache<? extends XmlFieldInstance> getCache() {
public Selector<? extends XmlFieldInstance> getCache() {
return cache;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.FieldGroup;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
Expand Down Expand Up @@ -68,7 +68,7 @@ public String getCalculatorName() {
}

@Override
public List<MetricResult> measure(PathCache cache)
public List<MetricResult> measure(Selector cache)
throws InvalidJsonException {
initializeCounters();

Expand Down Expand Up @@ -158,7 +158,7 @@ public void handleEmptyFragment(DataElement collection) {
}

public void evaluateDataElement(DataElement dataElement,
PathCache cache,
Selector cache,
CompletenessCounter completenessCounter,
String address,
Object jsonFragment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.gwdg.metadataqa.api.interfaces.Calculator;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.model.EdmFieldInstance;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
Expand Down Expand Up @@ -48,7 +48,7 @@ public String getCalculatorName() {
}

@Override
public List<MetricResult> measure(PathCache cache)
public List<MetricResult> measure(Selector cache)
throws InvalidJsonException {
FieldCounter<String> resultMap = new FieldCounter<>();
if (idPath != null)
Expand All @@ -66,7 +66,7 @@ public List<MetricResult> measure(PathCache cache)
return List.of(new FieldCounterBasedResult<>(getCalculatorName(), resultMap).withNoCompression());
}

private void extractSingleField(PathCache cache, FieldCounter<String> resultMap, String path, String fieldName) {
private void extractSingleField(Selector cache, FieldCounter<String> resultMap, String path, String fieldName) {
List<XmlFieldInstance> values = cache.get(path);
String value = null;
if (values == null || values.isEmpty() || values.get(0) == null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/gwdg/metadataqa/api/calculator/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.interfaces.Shutdownable;
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.schema.Schema;
import de.gwdg.metadataqa.api.uniqueness.SolrClient;
import de.gwdg.metadataqa.api.uniqueness.UniquenessField;
Expand All @@ -31,7 +31,7 @@ public Indexer(SolrClient solrClient, Schema schema) {
}

@Override
public List<MetricResult> measure(PathCache cache) {
public List<MetricResult> measure(Selector cache) {
try {
String recordId = extractValue(cache, schema.getRecordId().getPath()).get(0);

Expand All @@ -52,7 +52,7 @@ public List<MetricResult> measure(PathCache cache) {
return null;
}

private List<String> extractValue(PathCache cache, String path) {
private List<String> extractValue(Selector cache, String path) {
List<String> values = new ArrayList<>();
List<XmlFieldInstance> instances = cache.get(path);
if (instances != null && !instances.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
import java.util.ArrayList;
Expand Down Expand Up @@ -44,7 +44,7 @@ public List<String> getHeader() {
}

@Override
public List<MetricResult> measure(PathCache cache)
public List<MetricResult> measure(Selector cache)
throws InvalidJsonException {

Language language = new Language(schema, cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
import de.gwdg.metadataqa.api.util.SkippedEntitySelector;
Expand Down Expand Up @@ -89,7 +89,7 @@ public List<String> getHeader() {
}

@Override
public List<MetricResult> measure(PathCache cache)
public List<MetricResult> measure(Selector cache)
throws InvalidJsonException {

Multilinguality multilinguality = new Multilinguality(schema, cache, resultType, skippedEntryChecker, skippedEntitySelector);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.gwdg.metadataqa.api.calculator;

import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.model.XmlFieldInstance;

import java.io.Serializable;
Expand All @@ -12,6 +12,6 @@
* @author Péter Király <peter.kiraly at gwdg.de>
*/
public interface SkippedEntryChecker extends Serializable {
List<String> getSkippableCollectionIds(PathCache cache);
List<String> getSkippableCollectionIds(Selector cache);
<T extends XmlFieldInstance> String extractId(T value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import de.gwdg.metadataqa.api.interfaces.Calculator;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
import de.gwdg.metadataqa.api.uniqueness.SolrClient;
Expand Down Expand Up @@ -76,7 +76,7 @@ public String getCalculatorName() {
}

@Override
public List<MetricResult> measure(PathCache cache) {
public List<MetricResult> measure(Selector cache) {
String recordId = cache.getRecordId();
if (recordId.startsWith("/")) {
recordId = recordId.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import de.gwdg.metadataqa.api.calculator.solr.QaSolrClient;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.interfaces.Calculator;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
Expand Down Expand Up @@ -37,7 +37,7 @@ public String getCalculatorName() {
}

@Override
public List<MetricResult> measure(PathCache cache) {
public List<MetricResult> measure(Selector cache) {
String recordId = cache.getRecordId();
if (StringUtils.isNotBlank(recordId) && recordId.startsWith("/")) {
recordId = recordId.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.json.JsonUtils;
import de.gwdg.metadataqa.api.model.EdmFieldInstance;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.schema.Format;
import de.gwdg.metadataqa.api.schema.Schema;
import de.gwdg.metadataqa.api.util.Converter;
Expand Down Expand Up @@ -42,7 +42,7 @@ public final class EnhancementIdExtractor implements Serializable {
private EnhancementIdExtractor() {
}

public static List<String> extractIds(PathCache cache, Schema schema) {
public static List<String> extractIds(Selector cache, Schema schema) {
List<String> enhancementIds = new ArrayList<>();
String path = schema.getPathByLabel("Proxy").getPath().replace("false", "true");
Object rawJsonFragment = cache.getFragment(path);
Expand All @@ -55,7 +55,7 @@ public static List<String> extractIds(PathCache cache, Schema schema) {
return enhancementIds;
}

public static void processXml(PathCache cache, Schema schema, List<String> enhancementIds, List<Object> jsonFragments) {
public static void processXml(Selector cache, Schema schema, List<String> enhancementIds, List<Object> jsonFragments) {
DataElement parent = schema.getPathByLabel("Proxy");
for (DataElement child : parent.getChildren()) {
if (isEnrichmentField(child.getLabel())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.EdmFieldInstance;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.schema.Schema;
import de.gwdg.metadataqa.api.util.Converter;

Expand All @@ -15,12 +15,12 @@
import java.util.TreeMap;

public class Language {
private final PathCache cache;
private final Selector cache;
private final Schema schema;
FieldCounter<String> languageMap;
Map<String, SortedMap<String, Integer>> rawLanguageMap;

public Language(Schema schema, PathCache cache) {
public Language(Schema schema, Selector cache) {
this.schema = schema;
this.cache = cache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.EdmFieldInstance;
import de.gwdg.metadataqa.api.model.LanguageSaturationType;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;
import de.gwdg.metadataqa.api.schema.Schema;
import de.gwdg.metadataqa.api.util.Converter;
import de.gwdg.metadataqa.api.util.SkippedEntitySelector;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class Multilinguality {
public static final String NORMALIZED = MultilingualitySaturationCalculator.CALCULATOR_NAME + ":normalized";

private Schema schema;
private PathCache cache;
private Selector cache;
private MultilingualitySaturationCalculator.ResultTypes resultType;
private SkippedEntryChecker skippedEntryChecker;
private SkippedEntitySelector skippedEntitySelector;
Expand All @@ -45,7 +45,7 @@ public class Multilinguality {
Map<String, Map<String, Double>> rawScoreMap = new LinkedHashMap<>();

public Multilinguality(Schema schema,
PathCache cache,
Selector cache,
MultilingualitySaturationCalculator.ResultTypes resultType,
SkippedEntryChecker skippedEntryChecker,
SkippedEntitySelector skippedEntitySelector) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.gwdg.metadataqa.api.interfaces;

import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;

import java.io.Serializable;
import java.util.List;
Expand All @@ -16,7 +16,7 @@ public interface Calculator extends Serializable {
* @param cache
* The JSON cache object
*/
List<MetricResult> measure(PathCache cache);
List<MetricResult> measure(Selector cache);

/**
* Get header (the name of metrics) as a list.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/gwdg/metadataqa/api/interfaces/Observer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.gwdg.metadataqa.api.interfaces;

import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.selector.Selector;

/**
* Implementation of the Observer design pattern
Expand All @@ -21,7 +21,7 @@ public interface Observer {
* @param results
* The result map
*/
void update(PathCache cache, FieldCounter<Double> results);
void update(Selector cache, FieldCounter<Double> results);

/**
* Get a header, which is the name of metric, the observer measures.
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/de/gwdg/metadataqa/api/model/PathCacheFactory.java

This file was deleted.

Loading

0 comments on commit 27e8144

Please sign in to comment.