Skip to content

Commit

Permalink
make TestCoverageEvaluator not throw errors (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimkont committed Sep 30, 2015
1 parent a8d6fab commit 6748586
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 64 deletions.
5 changes: 5 additions & 0 deletions rdfunit-core/src/main/java/org/aksw/rdfunit/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ private Resources() {}
/** Constant <code>AUTO_GENERATORS_RS="/org/aksw/rdfunit/configuration/autoGen"{trunked}</code> */
public static final String AUTO_GENERATORS_RS = "/org/aksw/rdfunit/configuration/autoGeneratorsRS.ttl";


public static final String SCHEMAS_LOV = "/org/aksw/rdfunit/configuration/schemas_custom.csv";
public static final String SCHEMAS_CUSTOM = "/org/aksw/rdfunit/configuration/schemas_lov.csv";


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import com.hp.hpl.jena.query.*;
import org.aksw.jena_sparql_api.core.QueryExecutionFactory;
import org.aksw.rdfunit.services.PrefixNSService;
import org.aksw.rdfunit.statistics.DatasetStatisticsClassesCount;
import org.aksw.rdfunit.statistics.DatasetStatisticsPropertiesCount;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

/**
* <p>TestCoverageEvaluator class.</p>
Expand Down Expand Up @@ -61,52 +63,20 @@ private String generateInClause(Collection<String> patterns) {
/**
* <p>calculateCoverage.</p>
*
* @param qef a {@link org.aksw.jena_sparql_api.core.QueryExecutionFactory} object.
* @param testSuiteQEF a {@link org.aksw.jena_sparql_api.core.QueryExecutionFactory} object.
* @param propertiesFile a {@link java.lang.String} object.
* @param classFile a {@link java.lang.String} object.
* @throws java.io.IOException if any.
*/
public void calculateCoverage(QueryExecutionFactory qef, String propertiesFile, String classFile) throws IOException {
public void calculateCoverage(QueryExecutionFactory testSuiteQEF, QueryExecutionFactory inputSource) throws IOException {

String line;
long propertiesTotal = 0;
long classesTotal = 0;

Map<String, Long> properties = new HashMap<>();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream(propertiesFile), "UTF8"))) {

while ((line = br.readLine()) != null) {
// process the line.
String[] ar = line.split(" ");
long count = Long.parseLong(ar[0].trim());
String ref = ar[1].trim();
propertiesTotal += count;
properties.put(ref, count);

}
}

Map<String, Long> classes = new HashMap<>();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream(classFile), "UTF8"))) {

while ((line = br.readLine()) != null) {
// process the line.
String[] ar = line.split(" ");
long count = Long.parseLong(ar[0].trim());
String ref = ar[1].trim();
classesTotal += count;
classes.put(ref, count);

}
}

calculateCoverage(qef, properties, propertiesTotal, classes, classesTotal);
Map<String, Long> properties = new DatasetStatisticsPropertiesCount().getStatisticsMap(inputSource);
long propertiesTotal = properties.size();

Map<String, Long> classes = new DatasetStatisticsClassesCount().getStatisticsMap(inputSource);
long classesTotal = classes.size();

calculateCoverage(testSuiteQEF, properties, propertiesTotal, classes, classesTotal);
}

private void calculateCoverage(QueryExecutionFactory model, Map<String, Long> propertyCount, long totalProperties, Map<String, Long> classCount, long totalClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class DatasetStatistics {
* @param qef the qef
* @return a Map, if doGetCounts is false, the number defaults to 0
*/
public Map<String, Integer> getStatisticsMap(QueryExecutionFactory qef) {
public Map<String, Long> getStatisticsMap(QueryExecutionFactory qef) {

return getStats(getStatisticsQuery(), qef);

Expand All @@ -48,8 +48,8 @@ public Map<String, Integer> getStatisticsMap(QueryExecutionFactory qef) {
public DatasetStatistics() {
}

private Map<String, Integer> getStats(String sparqlQuery, QueryExecutionFactory qef) {
Map<String, Integer> stats = new HashMap<>();
private Map<String, Long> getStats(String sparqlQuery, QueryExecutionFactory qef) {
Map<String, Long> stats = new HashMap<>();

QueryExecution qe = null;
try {
Expand All @@ -64,7 +64,7 @@ private Map<String, Integer> getStats(String sparqlQuery, QueryExecutionFactory
if (qs.contains("count")) {
c = qs.get("count").asLiteral().getInt();
}
stats.put(s, c);
stats.put(s, new Long(c));
}
} finally {
if (qe != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected DatasetStatistics getStatisticsObject() {

@Test
public void testGetStats() throws Exception {
for (Map.Entry<String, Integer> entry : executeBasicTest().entrySet()) {
assertEquals(new Integer(0), entry.getValue());
for (Map.Entry<String, Long> entry : executeBasicTest().entrySet()) {
assertEquals(new Long(0), entry.getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ protected DatasetStatistics getStatisticsObject() {
@Test
public void testGetStats() throws Exception {

for (Map.Entry<String, Integer> entry : executeBasicTest().entrySet()) {
assertNotEquals(new Integer(0), entry.getValue());
for (Map.Entry<String, Long> entry : executeBasicTest().entrySet()) {
assertNotEquals(new Long(0), entry.getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected DatasetStatistics getStatisticsObject() {

@Test
public void testGetStats() throws Exception {
for (Map.Entry<String, Integer> entry : executeBasicTest().entrySet()) {
assertEquals(new Integer(0), entry.getValue());
for (Map.Entry<String, Long> entry : executeBasicTest().entrySet()) {
assertEquals(new Long(0), entry.getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ protected DatasetStatistics getStatisticsObject() {
@Test
public void testGetStats() throws Exception {

for (Map.Entry<String, Integer> entry : executeBasicTest().entrySet()) {
assertNotEquals(new Integer(0), entry.getValue());
for (Map.Entry<String, Long> entry : executeBasicTest().entrySet()) {
assertNotEquals(new Long(0), entry.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ protected DatasetStatistics getStatisticsObject() {

@Test
public void testGetStats() throws Exception {
for (Map.Entry<String, Integer> entry : executeBasicTest().entrySet()) {
assertEquals(new Integer(0), entry.getValue());
for (Map.Entry<String, Long> entry : executeBasicTest().entrySet()) {
assertEquals(new Long(0), entry.getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void setUp() throws Exception {

protected abstract DatasetStatistics getStatisticsObject();

protected Map<String, Integer> executeBasicTest() {
Map<String, Integer> stats = getStatisticsObject().getStatisticsMap(qef);
protected Map<String, Long> executeBasicTest() {
Map<String, Long> stats = getStatisticsObject().getStatisticsMap(qef);
assertEquals(getExteptedItems(), stats.size());

return stats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ public static void main(String[] args) throws Exception {

// Calculate coverage
if (configuration.isCalculateCoverageEnabled()) {
Model model = ModelFactory.createDefaultModel();
PrefixNSService.setNSPrefixesInModel(model);
Model testSuiteModel = ModelFactory.createDefaultModel();
PrefixNSService.setNSPrefixesInModel(testSuiteModel);
for (TestCase ut : testSuite.getTestCases()) {
TestCaseWriter.create(ut).write(model);
TestCaseWriter.create(ut).write(testSuiteModel);
}

TestCoverageEvaluator tce = new TestCoverageEvaluator();
tce.calculateCoverage(new QueryExecutionFactoryModel(model), dataset.getPrefix() + ".property.count", dataset.getPrefix() + ".class.count");
tce.calculateCoverage(new QueryExecutionFactoryModel(testSuiteModel), configuration.getTestSource().getExecutionFactory());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ValidateWS extends RDFUnitWebService {
@Override
public void init() throws ServletException {
RDFUnitUtils.fillSchemaServiceFromLOV();
RDFUnitUtils.fillSchemaServiceFromFile(ValidateWS.class.getResourceAsStream("/org/aksw/rdfunit/schemaDecl.csv"));
RDFUnitUtils.fillSchemaServiceFromFile(ValidateWS.class.getResourceAsStream("/org/aksw/rdfunit/configuration/schemaDecl.csv"));
try {
RDFUnit rdfunit = new RDFUnit();
rdfunit.init();
Expand Down

0 comments on commit 6748586

Please sign in to comment.