Skip to content

Commit

Permalink
refactor PropertyComparisonProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkeil committed Sep 12, 2024
1 parent 5f38adf commit 7a1066c
Show file tree
Hide file tree
Showing 15 changed files with 739 additions and 787 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ public Stream<Resource> getResourceKeys(Resource sample) throws NullPointerExcep
return IntStream.range(0, sampleSize).map(localId -> localId + sampleId * sampleSize).mapToObj(i -> ResourceFactory.createResource(Integer.toString(i)));
}

public Map<String, Set<RDFNode>> selectResourceValues(Resource resource, Resource sample,
Collection<String> variables) {
public Map<String, Set<RDFNode>> getValuesByVariable(Resource resource, Resource sample,
Collection<String> variables) {
int resourceId = Integer.parseInt(resource.getURI());
int sampleId = Integer.parseInt(sample.getURI());
if (resourceId / sampleSize == sampleId) {
return selectResourceValues(resourceId, sampleId, variables.iterator().next());
return getValuesByVariable(resourceId, sampleId, variables.iterator().next());
} else {
return null;
}
}

public Map<String, Set<RDFNode>> selectResourceValues(int resourceId, int sampleId,
String variable) {
Set<RDFNode> valuesSet = new HashSet<>(1); // Note: must be mutable
public Map<String, Set<RDFNode>> getValuesByVariable(int resourceId, int sampleId,
String variable) {
Set<RDFNode> valuesSet = new HashSet<>(1); // Note: must be mutable TODO not necessary after not ignoring wrong values for measures anymore
if (resourceId % sampleSize >= sampleSize * errorRate) {
valuesSet.add(correctValue);
} else {
Expand All @@ -80,15 +80,15 @@ public Map<String, Set<RDFNode>> selectResourceValues(int resourceId, int sample
return Collections.singletonMap(variable, valuesSet);
}

public Map<Resource, Map<String, Set<RDFNode>>> selectResourceValues(Collection<Resource> resources,
Resource sample, List<String> variables) {
public Map<Resource, Map<String, Set<RDFNode>>> getValuesByVariableResource(Collection<Resource> resources,
Resource sample, List<String> variables) {
int sampleId = Integer.parseInt(sample.getURI());
String variable = variables.iterator().next();
Map<Resource, Map<String, Set<RDFNode>>> resourceValues = new HashMap<>();
for (Resource resource : resources) {
int resourceId = Integer.parseInt(resource.getURI());
if (resourceId / sampleSize == sampleId) {
resourceValues.put(resource, selectResourceValues(resourceId, sampleId, variable));
resourceValues.put(resource, getValuesByVariable(resourceId, sampleId, variable));
}
}
return resourceValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public Stream<Resource> getResourceKeys(Aspect aspect, Resource dataset) throws
return this.dataSupplier.getResourceKeys(dataset);
}

@Override
public Stream<List<Resource>> getCorrespondenceGroups() {
return this.dataSupplier.getCorrespondenceGroups();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,11 @@ public Stream<Resource> getResourceKeys(@SuppressWarnings("unused") Aspect aspec
return this.dataSupplier.getResourceKeys(dataset);
}

public Map<String, Set<RDFNode>> selectResourceValues(Resource resource, Resource dataset,
@SuppressWarnings("unused") Aspect aspect,
Collection<String> variables) {
return this.dataSupplier.selectResourceValues(resource, dataset, variables);
}

public Map<Resource, Map<String, Set<RDFNode>>> selectResourceValues(Collection<Resource> resources,
Resource dataset,
@SuppressWarnings("unused") Aspect aspect,
List<String> variables) {
return this.dataSupplier.selectResourceValues(resources, dataset, variables);
@Override
protected Map<String, Set<RDFNode>> getValuesByVariable(Resource dataset, Resource resource) {
return this.dataSupplier.getValuesByVariable(resource, dataset, variables);
}


@Override
public Stream<List<Resource>> getCorrespondenceGroups() {
return this.dataSupplier.getCorrespondenceGroups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ public void supplierTest(int datasetCount) {
int rightValuesSingle = 0, wrongValuesSingle = 0, rightValuesCollection = 0, wrongValuesCollection = 0;
for (Resource resource : population[i]) {
// single resource method
Assertions.assertEquals(1, supplier.selectResourceValues(resource, dataset.get(i),
Assertions.assertEquals(1, supplier.getValuesByVariable(resource, dataset.get(i),
Collections.singletonList("var")).get("var").size());
if (supplier.selectResourceValues(resource, dataset.get(i), Collections.singletonList("var")).get(
if (supplier.getValuesByVariable(resource, dataset.get(i), Collections.singletonList("var")).get(
"var").contains(ComparisonBenchmarkDataSupplier.correctValue)) {
rightValuesSingle++;
} else {
wrongValuesSingle++;
}

// resource collection method
Assertions.assertEquals(1, supplier.selectResourceValues(Collections.singletonList(resource),
Assertions.assertEquals(1, supplier.getValuesByVariableResource(Collections.singletonList(resource),
dataset.get(i), Collections.singletonList("var")).get(resource).size());
Assertions.assertEquals(1, supplier.selectResourceValues(Collections.singletonList(resource),
Assertions.assertEquals(1, supplier.getValuesByVariableResource(Collections.singletonList(resource),
dataset.get(i), Collections.singletonList("var")).get(resource).get("var").size());
if (supplier.selectResourceValues(Collections.singletonList(resource), dataset.get(i),
if (supplier.getValuesByVariableResource(Collections.singletonList(resource), dataset.get(i),
Collections.singletonList("var")).get(resource).get("var").contains(ComparisonBenchmarkDataSupplier.correctValue)) {
rightValuesCollection++;
} else {
Expand Down
Loading

0 comments on commit 7a1066c

Please sign in to comment.