it.uniroma2.art.sheet2rdf.resolver.PropertyRangeResolver Maven / Gradle / Ivy
package it.uniroma2.art.sheet2rdf.resolver;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryResult;
public class PropertyRangeResolver {
private RepositoryConnection repoConnection;
public PropertyRangeResolver(RepositoryConnection repoConnection){
this.repoConnection = repoConnection;
}
/**
* Given a property looks for its range into the model passed to the constructor.
* If no range is found, it returns null.
* @param property
* @return
*/
public IRI getRange(IRI property) {
//get the property ranges
RepositoryResult rangeStmts = repoConnection.getStatements(property, RDFS.RANGE, null, true);
while (rangeStmts.hasNext()) {
Value range = rangeStmts.next().getObject();
if (range instanceof IRI) {
return (IRI) range;
}
}
//no IRI range found, lookup for range of super properties
RepositoryResult superPropStmts = repoConnection.getStatements(property, RDFS.SUBPROPERTYOF, null, true);
if (superPropStmts.hasNext()) {
return getRange((IRI) superPropStmts.next().getObject());
} else {
return null;
}
}
}