Search in sources :

Example 1 with NodeIterator

use of com.hp.hpl.jena.rdf.model.NodeIterator in project irida by phac-nml.

the class InMemoryTaxonomyService method getMatchingParent.

/**
 * Get a parent node with the matching search term
 *
 * @param resource
 *            The resource to start walking up from
 * @param searchTerm
 *            The search term required
 * @return A parent of the given node with the given search term in the
 *         label.
 */
private Resource getMatchingParent(Resource resource, String searchTerm) {
    NodeIterator subClasses = model.listObjectsOfProperty(resource, RDFS.subClassOf);
    if (subClasses.hasNext()) {
        Resource parentNode = subClasses.next().asResource();
        String elementName = parentNode.getProperty(RDFS.label).getObject().asLiteral().getString();
        if (elementName.toLowerCase().contains(searchTerm.toLowerCase())) {
            return parentNode;
        } else {
            return getMatchingParent(parentNode, searchTerm);
        }
    }
    return null;
}
Also used : NodeIterator(com.hp.hpl.jena.rdf.model.NodeIterator) Resource(com.hp.hpl.jena.rdf.model.Resource) ParameterizedSparqlString(com.hp.hpl.jena.query.ParameterizedSparqlString)

Aggregations

ParameterizedSparqlString (com.hp.hpl.jena.query.ParameterizedSparqlString)1 NodeIterator (com.hp.hpl.jena.rdf.model.NodeIterator)1 Resource (com.hp.hpl.jena.rdf.model.Resource)1