Skip to content

Commit

Permalink
added superclasses endpoint for #98
Browse files Browse the repository at this point in the history
  • Loading branch information
giraygi committed Nov 23, 2024
1 parent b8a0bcd commit 2247f76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,33 @@ HttpEntity<PagedModel<V1Term>> ancestors(@PathVariable("onto")
return new ResponseEntity<>( assembler.toModel(ancestors, termAssembler), HttpStatus.OK);
}

@RequestMapping(path = "/{onto}/terms/{iri}/superclasses", produces = {MediaType.APPLICATION_JSON_VALUE,
MediaTypes.HAL_JSON_VALUE}, method = RequestMethod.GET)
HttpEntity<PagedModel<V1Term>> getSuperClasses(
@PathVariable("onto")
@Parameter(name = "onto",
description = "The ID of the ontology. For example for Data Use Ontology, the ID is duo.",
example = "duo") String ontologyId,
@PathVariable("iri")
@Parameter(name = "iri",
description = "The IRI of the term, this value must be single URL encoded",
example = "http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FDUO_0000017") String termId,
@RequestParam(value = "lang", required = false, defaultValue = "en") String lang,
@Parameter(hidden = true) Pageable pageable,
@Parameter(hidden = true) PagedResourcesAssembler assembler) {

ontologyId = ontologyId.toLowerCase();

String decoded = UriUtils.decode(termId, "UTF-8");
String entityId = ontologyId+"+class+"+decoded;
Page<V1Term> superClasses = graphRepository.getSuperClassPaginated(entityId, lang, pageable);
if (superClasses == null)
throw new ResourceNotFoundException("No super classes could be found for " + ontologyId
+ " and " + termId);

return new ResponseEntity<>( assembler.toModel(superClasses, termAssembler), HttpStatus.OK);
}

@RequestMapping(path = "/{onto}/terms/{iri}/equivalentclasses", produces = {MediaType.APPLICATION_JSON_VALUE,
MediaTypes.HAL_JSON_VALUE}, method = RequestMethod.GET)
HttpEntity<PagedModel<V1Term>> getEquivalentClasses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ public Page<V1Term> getRelatedFromPaginated(String entityId, String lang, Pageab
return neo4jClient.queryPaginated(query, "x", countQuery, parameters("id", entityId), pageable).map(record -> V1TermMapper.mapTerm(record, lang));
}

public Page<V1Term> getSuperClassPaginated(String entityId, String lang, Pageable pageable) {
String query =
"MATCH (a:OntologyClass)-[r:`http://www.w3.org/2000/01/rdf-schema#subClassOf`]->(b:OntologyClass) " +
"WHERE a.id = $id RETURN b";
String countQuery =
"MATCH (a:OntologyClass)-[r:`http://www.w3.org/2000/01/rdf-schema#subClassOf`]->(b:OntologyClass) " +
"WHERE a.id = $id RETURN count(b)";

return neo4jClient.queryPaginated(query, "b", countQuery, parameters("id", entityId), pageable).map(record -> V1TermMapper.mapTerm(record, lang));
}

public Page<V1Term> getEquivalentClassPaginated(String entityId, String lang, Pageable pageable) {
String query =
"MATCH (a:OntologyClass)-[r:`http://www.w3.org/2002/07/owl#equivalentClass`]-(b:OntologyClass) " +
Expand Down

0 comments on commit 2247f76

Please sign in to comment.