Skip to content

Commit

Permalink
Renaming important classes (JsonBranch->DataElement, OaiPmhXPath->Xpa…
Browse files Browse the repository at this point in the history
…thWrapper)
  • Loading branch information
pkiraly committed Nov 21, 2022
1 parent b4f521a commit fa269f3
Show file tree
Hide file tree
Showing 80 changed files with 1,464 additions and 1,484 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ First, add the library into your project's `pom.xml` file:
<dependency>
<grroupId>de.gwdg.metadata</grroupId>
<artifactId>metadata-qa-api</artifactId>
<version>0.7</version>
<version>0.9.0</version>
</dependency>
</dependencies>
```
Expand All @@ -134,16 +134,16 @@ Define a schema:
Schema schema = new BaseSchema()
// this schema will be used for a CSV file
.setFormat(Format.CSV)
// JsonBranch represents a data element, which might have
// DataELement represents a data element, which might have
// a number of properties
.addField(
new JsonBranch("url", Category.MANDATORY)
new DataELement("url", Category.MANDATORY)
.setExtractable()
)
.addField(new JsonBranch("name"))
.addField(new JsonBranch("alternateName"))
.addField(new DataELement("name"))
.addField(new DataELement("alternateName"))
...
.addField(new JsonBranch("temporalCoverage"));
.addField(new DataELement("temporalCoverage"));
```

Build a `CalculatorFacade` object:
Expand Down Expand Up @@ -483,7 +483,7 @@ The same in JSON:
```

The central piece is the `fields` array. Each item represents the properties of
a single data elements (a JsonBranch in the API). Its properties are:
a single data elements (a DataELement in the API). Its properties are:

* `name` (String): the name or label of the data element
* `path` (String): a address of the data element. If the format is XML, it
Expand Down Expand Up @@ -945,14 +945,14 @@ turn it off.
Schema schema = new BaseSchema()
.setFormat(Format.CSV)
.addField(
new JsonBranch("title", "title")
new DataELement("title", "title")
.setRule(
new Rule()
.withDisjoint("description")
)
)
.addField(
new JsonBranch("url", "url")
new DataELement("url", "url")
.setRule(
new Rule()
.withMinCount(1)
Expand Down Expand Up @@ -1117,7 +1117,7 @@ version name), you have to enable the retrieval of those versions in the `pom.xm
<dependency>
<grroupId>de.gwdg.metadata</grroupId>
<artifactId>metadata-qa-api</artifactId>
<version>0.8-SNAPSHOT</version>
<version>0.9-SNAPSHOT</version>
</dependency>
</dependencies>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import de.gwdg.metadataqa.api.interfaces.Calculator;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.FieldGroup;
import de.gwdg.metadataqa.api.json.JsonBranch;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
Expand Down Expand Up @@ -77,18 +77,18 @@ public List<MetricResult> measure(PathCache cache)
: new ArrayList<>();

if (schema.getCollectionPaths() == null || schema.getCollectionPaths().isEmpty()) {
for (JsonBranch jsonBranch : schema.getPaths()) {
if (!jsonBranch.isActive()) {
for (DataElement dataElement : schema.getPaths()) {
if (!dataElement.isActive()) {
continue;
}
evaluateJsonBranch(jsonBranch, cache, completenessCounter, jsonBranch.getLabel(), null);
evaluateDataElement(dataElement, cache, completenessCounter, dataElement.getLabel(), null);
}
} else {
for (JsonBranch collection : schema.getCollectionPaths()) {
for (DataElement collection : schema.getCollectionPaths()) {
if (!collection.isActive()) {
continue;
}
Object rawJsonFragment = cache.getFragment(collection.getJsonPath());
Object rawJsonFragment = cache.getFragment(collection.getPath());
List<Object> jsonFragments = Converter.jsonObjectToList(rawJsonFragment, schema);
if (jsonFragments.isEmpty()) {
handleEmptyFragment(collection);
Expand All @@ -98,12 +98,12 @@ public List<MetricResult> measure(PathCache cache)
if (skippedEntitySelector.isCollectionSkippable(skippableIds, collection, i, cache, jsonFragment)) {
handleEmptyFragment(collection);
} else {
for (JsonBranch child : collection.getChildren()) {
for (DataElement child : collection.getChildren()) {
if (!child.isActive()) {
continue;
}
var address = String.format("%s/%d/%s", collection.getJsonPath(), i, child.getJsonPath());
evaluateJsonBranch(child, cache, completenessCounter, address, jsonFragment);
var address = String.format("%s/%d/%s", collection.getPath(), i, child.getPath());
evaluateDataElement(child, cache, completenessCounter, address, jsonFragment);
}
}
}
Expand Down Expand Up @@ -148,35 +148,35 @@ public void initializeCounters() {
}
}

public void handleEmptyFragment(JsonBranch collection) {
for (JsonBranch child : collection.getChildren()) {
public void handleEmptyFragment(DataElement collection) {
for (DataElement child : collection.getChildren()) {
if (!child.isActive()) {
continue;
}
handleValues(completenessCounter, child, null);
}
}

public void evaluateJsonBranch(JsonBranch jsonBranch,
PathCache cache,
CompletenessCounter completenessCounter,
String address,
Object jsonFragment) {
List<T> values = cache.get(address, jsonBranch.getJsonPath(), jsonFragment);
handleValues(completenessCounter, jsonBranch, values);
public void evaluateDataElement(DataElement dataElement,
PathCache cache,
CompletenessCounter completenessCounter,
String address,
Object jsonFragment) {
List<T> values = cache.get(address, dataElement.getPath(), jsonFragment);
handleValues(completenessCounter, dataElement, values);
}

private void handleValues(CompletenessCounter completenessCounter,
JsonBranch jsonBranch,
DataElement dataElement,
List<T> values) {
if (completeness) {
completenessCounter.increaseTotal(jsonBranch.getCategories());
completenessCounter.increaseTotal(dataElement.getCategories());
}

if (values != null && !values.isEmpty() && !isEmpty(values)) {
handleNonNullValues(completenessCounter, jsonBranch, values);
handleNonNullValues(completenessCounter, dataElement, values);
} else {
handleNullValues(jsonBranch);
handleNullValues(dataElement);
}
}

Expand All @@ -193,12 +193,12 @@ private boolean isEmpty(List<T> values) {
}

private void handleNonNullValues(CompletenessCounter completenessCounter,
JsonBranch jsonBranch,
DataElement dataElement,
List<T> values) {
final String label = jsonBranch.getLabel();
final String label = dataElement.getLabel();

if (completeness) {
completenessCounter.increaseInstance(jsonBranch.getCategories());
completenessCounter.increaseInstance(dataElement.getCategories());
}

if (existence) {
Expand All @@ -218,15 +218,15 @@ private void handleNonNullValues(CompletenessCounter completenessCounter,
}
}

private void handleNullValues(JsonBranch jsonBranch) {
if (existence && !existenceCounter.has(jsonBranch.getLabel()))
existenceCounter.put(jsonBranch.getLabel(), false);
private void handleNullValues(DataElement dataElement) {
if (existence && !existenceCounter.has(dataElement.getLabel()))
existenceCounter.put(dataElement.getLabel(), false);

if (cardinality && !cardinalityCounter.has(jsonBranch.getLabel()))
cardinalityCounter.put(jsonBranch.getLabel(), 0);
if (cardinality && !cardinalityCounter.has(dataElement.getLabel()))
cardinalityCounter.put(dataElement.getLabel(), 0);

if (collectFields && !missingFields.contains(jsonBranch.getLabel()))
missingFields.add(jsonBranch.getLabel());
if (collectFields && !missingFields.contains(dataElement.getLabel()))
missingFields.add(dataElement.getLabel());
}

public void collectFields(boolean collectFields) {
Expand Down Expand Up @@ -348,17 +348,17 @@ public List<String> getHeader() {
}

if (existence) {
for (JsonBranch jsonBranch : schema.getPaths()) {
if (!jsonBranch.isCollection() && jsonBranch.isActive()) {
headers.add("existence:" + jsonBranch.getLabel());
for (DataElement dataElement : schema.getPaths()) {
if (!dataElement.isCollection() && dataElement.isActive()) {
headers.add("existence:" + dataElement.getLabel());
}
}
}

if (cardinality) {
for (JsonBranch jsonBranch : schema.getPaths()) {
if (!jsonBranch.isCollection() && jsonBranch.isActive()) {
headers.add("cardinality:" + jsonBranch.getLabel());
for (DataElement dataElement : schema.getPaths()) {
if (!dataElement.isCollection() && dataElement.isActive()) {
headers.add("cardinality:" + dataElement.getLabel());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/gwdg/metadataqa/api/calculator/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public Indexer(SolrClient solrClient, Schema schema) {
@Override
public List<MetricResult> measure(PathCache cache) {
try {
String recordId = extractValue(cache, schema.getRecordId().getJsonPath()).get(0);
String recordId = extractValue(cache, schema.getRecordId().getPath()).get(0);

Map<String, List<String>> resultMap = new HashMap<>();
for (UniquenessField solrField : solrFields) {
List<String> values = extractValue(cache, solrField.getJsonPath());
List<String> values = extractValue(cache, solrField.getPath());
if (!values.isEmpty())
resultMap.put(solrField.getSolrField(), values);
}
Expand All @@ -52,9 +52,9 @@ public List<MetricResult> measure(PathCache cache) {
return null;
}

private List<String> extractValue(PathCache cache, String jsonPath) {
private List<String> extractValue(PathCache cache, String path) {
List<String> values = new ArrayList<>();
List<XmlFieldInstance> instances = cache.get(jsonPath);
List<XmlFieldInstance> instances = cache.get(path);
if (instances != null && !instances.isEmpty())
for (XmlFieldInstance instance : instances)
if (instance.hasValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import de.gwdg.metadataqa.api.calculator.language.Language;
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.JsonBranch;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
Expand Down Expand Up @@ -34,10 +34,10 @@ public String getCalculatorName() {
@Override
public List<String> getHeader() {
List<String> headers = new ArrayList<>();
for (JsonBranch jsonBranch : schema.getPaths()) {
if (jsonBranch.isActive()
&& !schema.getNoLanguageFields().contains(jsonBranch.getLabel())) {
headers.add("lang:" + jsonBranch.getLabel());
for (DataElement dataElement : schema.getPaths()) {
if (dataElement.isActive()
&& !schema.getNoLanguageFields().contains(dataElement.getLabel())) {
headers.add("lang:" + dataElement.getLabel());
}
}
return headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import de.gwdg.metadataqa.api.calculator.language.Multilinguality;
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.interfaces.MetricResult;
import de.gwdg.metadataqa.api.json.JsonBranch;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
Expand Down Expand Up @@ -64,17 +64,17 @@ public String getCalculatorName() {
@Override
public List<String> getHeader() {
List<String> headers = new ArrayList<>();
for (JsonBranch jsonBranch : schema.getPaths()) {
if (jsonBranch.isActive() && !schema.getNoLanguageFields().contains(jsonBranch.getLabel())) {
for (DataElement dataElement : schema.getPaths()) {
if (dataElement.isActive() && !schema.getNoLanguageFields().contains(dataElement.getLabel())) {
switch (resultType) {
case EXTENDED:
headers.add("lang:sum:" + jsonBranch.getLabel());
headers.add("lang:average:" + jsonBranch.getLabel());
headers.add("lang:normalized:" + jsonBranch.getLabel());
headers.add("lang:sum:" + dataElement.getLabel());
headers.add("lang:average:" + dataElement.getLabel());
headers.add("lang:normalized:" + dataElement.getLabel());
break;
case NORMAL:
default:
headers.add("lang:" + jsonBranch.getLabel());
headers.add("lang:" + dataElement.getLabel());
break;
}
}
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.json.JsonBranch;
import de.gwdg.metadataqa.api.json.DataElement;
import de.gwdg.metadataqa.api.model.pathcache.PathCache;
import de.gwdg.metadataqa.api.problemcatalog.FieldCounterBasedResult;
import de.gwdg.metadataqa.api.schema.Schema;
Expand Down Expand Up @@ -134,9 +134,9 @@ public boolean isTermCollectionEnabled() {
@Override
public List<String> getHeader() {
List<String> headers = new ArrayList<>();
for (JsonBranch jsonBranch : schema.getIndexFields()) {
headers.add(jsonBranch.getLabel() + ":sum");
headers.add(jsonBranch.getLabel() + ":avg");
for (DataElement dataElement : schema.getIndexFields()) {
headers.add(dataElement.getLabel() + ":sum");
headers.add(dataElement.getLabel() + ":avg");
}
return headers;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.gwdg.metadataqa.api.calculator.edm;

import de.gwdg.metadataqa.api.json.JsonBranch;
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;
Expand Down Expand Up @@ -44,7 +44,7 @@ private EnhancementIdExtractor() {

public static List<String> extractIds(PathCache cache, Schema schema) {
List<String> enhancementIds = new ArrayList<>();
String path = schema.getPathByLabel("Proxy").getJsonPath().replace("false", "true");
String path = schema.getPathByLabel("Proxy").getPath().replace("false", "true");
Object rawJsonFragment = cache.getFragment(path);
List<Object> jsonFragments = Converter.jsonObjectToList(rawJsonFragment, schema);
if (schema.getFormat().equals(Format.JSON)) {
Expand All @@ -56,12 +56,12 @@ public static List<String> extractIds(PathCache cache, Schema schema) {
}

public static void processXml(PathCache cache, Schema schema, List<String> enhancementIds, List<Object> jsonFragments) {
JsonBranch parent = schema.getPathByLabel("Proxy");
for (JsonBranch child : parent.getChildren()) {
DataElement parent = schema.getPathByLabel("Proxy");
for (DataElement child : parent.getChildren()) {
if (isEnrichmentField(child.getLabel())) {
String address = child.getAbsoluteJsonPath(schema.getFormat());
String address = child.getAbsolutePath(schema.getFormat());
Object context = jsonFragments.get(0);
List<EdmFieldInstance> fieldInstances = cache.get(address, child.getJsonPath(), context);
List<EdmFieldInstance> fieldInstances = cache.get(address, child.getPath(), context);
if (fieldInstances != null && !fieldInstances.isEmpty()) {
for (EdmFieldInstance fieldInstance : fieldInstances) {
if (fieldInstance.isUrl()) {
Expand Down
Loading

0 comments on commit fa269f3

Please sign in to comment.