Skip to content

Commit

Permalink
Merge pull request #49 from semtk/cardinality-java-client
Browse files Browse the repository at this point in the history
Add oinfo client function to get cardinality violations
  • Loading branch information
Cuddihy, Paul E authored and GitHub Enterprise committed Aug 4, 2023
2 parents 9bad41f + 2273e3a commit d0f40d1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ public PredicateStats execGetCachedPredicateStats(SparqlConnection conn) throws
}
}

/**
* Executes a call to get cardinality violations
* @param conn the connection
* @param maxRows maximum number of violations to return (-1 for no max)
* @param conciseFormat return using format that reduces redundant data and adds class instance count column
* @return jobId
* @throws Exception
*/
public String execGetCardinalityViolations(SparqlConnection conn, int maxRows, boolean conciseFormat) throws ConnectException, EndpointNotFoundException, Exception {
this.parametersJSON.put("conn", conn.toJson().toJSONString());
this.parametersJSON.put("maxRows", maxRows);
this.parametersJSON.put("conciseFormat", conciseFormat);
conf.setServiceEndpoint("ontologyinfo/getCardinalityViolations");

try {
SimpleResultSet res = this.executeWithSimpleResultReturn();
res.throwExceptionIfUnsuccessful();
return res.getJobId();
} finally {
// reset conf and parametersJSON
this.parametersJSON.remove("conn");
this.parametersJSON.remove("maxRows");
this.parametersJSON.remove("conciseFormat");
conf.setServiceEndpoint(null);
}
}

/**
*
* @throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.ge.research.semtk.edc.client.OntologyInfoClientConfig;
import com.ge.research.semtk.edc.client.StatusClient;
import com.ge.research.semtk.edc.client.StatusClientConfig;
import com.ge.research.semtk.load.dataset.CSVDataset;
import com.ge.research.semtk.load.utility.SparqlGraphJson;
import com.ge.research.semtk.ontologyTools.OntologyInfo;
import com.ge.research.semtk.ontologyTools.PredicateStats;
Expand Down Expand Up @@ -163,17 +164,37 @@ public void testCacheThroughQueryClient() throws Exception {
SimpleResultSet res = qClient.uploadOwl(new File("src/test/resources/sampleBattery.owl"));
res.throwExceptionIfUnsuccessful();
oInfo = client.getOntologyInfo(conn);
assertEquals("query client uploadOwl didn't update oInfo cache", 3, oInfo.getNumberOfClasses());


assertEquals("query client uploadOwl didn't update oInfo cache", 3, oInfo.getNumberOfClasses());
}

@Test
public void testGetPredicateStats() throws Exception {
TestGraph.clearGraph();
TestGraph.uploadOwlResource(this.getClass(), "sampleBattery.owl");

PredicateStats stats = TestGraph.getPredicateStats();

PredicateStats stats = TestGraph.getPredicateStats();
}

@Test
public void testGetCardinalityViolations() throws Exception {
TestGraph.clearGraph();
TestGraph.uploadOwlResource(this, "Cardinality.owl"); // load Cardinal.sadl : the classes, restrictions, and instance data
String jobId;
Table table;

// no max rows
jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), -1, false);
table = IntegrationTestUtility.getNodeGroupExecutionRestClient().waitForJobAndGetTable(jobId);
assertEquals(table.getNumRows(), 36);

// max rows
jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), 10, false);
table = IntegrationTestUtility.getNodeGroupExecutionRestClient().waitForJobAndGetTable(jobId);
assertEquals(table.getNumRows(), 10);

// max rows and concise format
jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), -1, true);
table = IntegrationTestUtility.getNodeGroupExecutionRestClient().waitForJobAndGetTable(jobId);
assertEquals(table.getNumRows(), 22);

}
}

0 comments on commit d0f40d1

Please sign in to comment.