Skip to content

Commit

Permalink
Ported allPredicates()
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Feb 18, 2024
1 parent 444eb84 commit c7cade4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ public void addPrefix(IRDFStore store, String prefix, String namespace)
* @param resourceURI subject of the triples
* @param predicate predicate of the triples
* @return List of objects (resources and literals).
* @throws BioclipseException
*/
*/
public List<String> getForPredicate(IRDFStore store, String resourceURI, String predicate) {
StringMatrix results = sparql(store,
"SELECT DISTINCT ?object WHERE {" +
Expand Down Expand Up @@ -701,4 +700,21 @@ public List<String> allClasses(IRDFStore store) throws BioclipseException {
return results.getColumn("class");
}

/**
* Lists all existing predicates.
*
* @param store the {@link IRDFStore}
* @return a {@link List} with all unique predicates
*
* @throws BioclipseException when the {@link IRDFStore} could not be queried
*/
public List<String> allPredicates(IRDFStore store) throws BioclipseException {
StringMatrix results = sparql(store,

Check warning on line 712 in managers-semweb/managers-rdf/src/main/java/net/bioclipse/managers/RDFManager.java

View check run for this annotation

Codecov / codecov/patch

managers-semweb/managers-rdf/src/main/java/net/bioclipse/managers/RDFManager.java#L712

Added line #L712 was not covered by tests
"SELECT DISTINCT ?predicate WHERE {" +
" [] ?predicate []" +
"}"
);
return results.getColumn("predicate");

Check warning on line 717 in managers-semweb/managers-rdf/src/main/java/net/bioclipse/managers/RDFManager.java

View check run for this annotation

Codecov / codecov/patch

managers-semweb/managers-rdf/src/main/java/net/bioclipse/managers/RDFManager.java#L717

Added line #L717 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,22 @@ public void allClasses() throws Exception {
IRDFStore store = rdf.createInMemoryStore(true);
store = rdf.importFile(store, "/RDFTests/classes.ttl", "TURTLE");
List<String> classes = rdf.allClasses(store);
System.out.println(classes);
assertNotNull(classes);
assertNotSame(0, classes.size());
for (String clazz : classes) {
if (clazz.equals("https://example.org/ClassOne")) return;
}
}

@Test
public void allPredicates() throws Exception {
IRDFStore store = rdf.createInMemoryStore(true);
store = rdf.importFile(store, "/RDFTests/classes.ttl", "TURTLE");
List<String> classes = rdf.allClasses(store);
assertNotNull(classes);
assertNotSame(0, classes.size());
for (String clazz : classes) {
if (clazz.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")) return;
}
}
}

0 comments on commit c7cade4

Please sign in to comment.