From e6a4b463f84c926ad50d96a4a5f25e3d11ec7721 Mon Sep 17 00:00:00 2001 From: Jenny Williams Date: Fri, 4 Aug 2023 10:21:23 -0400 Subject: [PATCH 1/2] Add oinfo client function to get cardinality violations --- .../semtk/edc/client/OntologyInfoClient.java | 27 ++++++++++++++ .../test/OntologyInfoClientTest_IT.java | 35 +++++++++++++++---- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/edc/client/OntologyInfoClient.java b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/edc/client/OntologyInfoClient.java index 86b8ec33c..d3308eb95 100644 --- a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/edc/client/OntologyInfoClient.java +++ b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/edc/client/OntologyInfoClient.java @@ -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 diff --git a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java index fe317560e..5628dfd86 100644 --- a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java +++ b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java @@ -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; @@ -163,17 +164,39 @@ 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; + CSVDataset result; + + // no max rows + jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), -1, false); + IntegrationTestUtility.getStatusClient(jobId).waitForCompletionSuccess(); + result = IntegrationTestUtility.getResultsClient().getTableResultsCSV(jobId, 999999); + assertEquals(result.getNumRows(), 36); + + // max rows + jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), 10, false); + IntegrationTestUtility.getStatusClient(jobId).waitForCompletionSuccess(); + result = IntegrationTestUtility.getResultsClient().getTableResultsCSV(jobId, 999999); + assertEquals(result.getNumRows(), 10); + + // max rows and concise format + jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), -1, true); + IntegrationTestUtility.getStatusClient(jobId).waitForCompletionSuccess(); + result = IntegrationTestUtility.getResultsClient().getTableResultsCSV(jobId, 999999); + assertEquals(result.getNumRows(), 22); } } From 2273e3acc1fc0ce3c51b36c8a27ee7c4b41c9928 Mon Sep 17 00:00:00 2001 From: Jenny Williams Date: Fri, 4 Aug 2023 10:27:34 -0400 Subject: [PATCH 2/2] Improve call to wait and get table --- .../test/OntologyInfoClientTest_IT.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java index 5628dfd86..4d11c2e27 100644 --- a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java +++ b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoClientTest_IT.java @@ -179,24 +179,22 @@ public void testGetCardinalityViolations() throws Exception { TestGraph.clearGraph(); TestGraph.uploadOwlResource(this, "Cardinality.owl"); // load Cardinal.sadl : the classes, restrictions, and instance data String jobId; - CSVDataset result; + Table table; // no max rows jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), -1, false); - IntegrationTestUtility.getStatusClient(jobId).waitForCompletionSuccess(); - result = IntegrationTestUtility.getResultsClient().getTableResultsCSV(jobId, 999999); - assertEquals(result.getNumRows(), 36); + table = IntegrationTestUtility.getNodeGroupExecutionRestClient().waitForJobAndGetTable(jobId); + assertEquals(table.getNumRows(), 36); // max rows jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), 10, false); - IntegrationTestUtility.getStatusClient(jobId).waitForCompletionSuccess(); - result = IntegrationTestUtility.getResultsClient().getTableResultsCSV(jobId, 999999); - assertEquals(result.getNumRows(), 10); + table = IntegrationTestUtility.getNodeGroupExecutionRestClient().waitForJobAndGetTable(jobId); + assertEquals(table.getNumRows(), 10); // max rows and concise format jobId = this.getClient().execGetCardinalityViolations(TestGraph.getSparqlConn(), -1, true); - IntegrationTestUtility.getStatusClient(jobId).waitForCompletionSuccess(); - result = IntegrationTestUtility.getResultsClient().getTableResultsCSV(jobId, 999999); - assertEquals(result.getNumRows(), 22); + table = IntegrationTestUtility.getNodeGroupExecutionRestClient().waitForJobAndGetTable(jobId); + assertEquals(table.getNumRows(), 22); + } }