本文整理汇总了Java中org.apache.jena.ontology.OntClass.listSuperClasses方法的典型用法代码示例。如果您正苦于以下问题:Java OntClass.listSuperClasses方法的具体用法?Java OntClass.listSuperClasses怎么用?Java OntClass.listSuperClasses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.ontology.OntClass
的用法示例。
在下文中一共展示了OntClass.listSuperClasses方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAbsolutePathBuilder
import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
public UriBuilder getAbsolutePathBuilder(OntClass ontClass)
{
if (ontClass == null) throw new IllegalArgumentException("OntClass cannot be null");
ExtendedIterator<OntClass> superClassIt = ontClass.listSuperClasses();
try
{
while (superClassIt.hasNext())
{
OntClass superClass = superClassIt.next();
if (superClass.canAs(HasValueRestriction.class))
{
HasValueRestriction hvr = superClass.as(HasValueRestriction.class);
if (hvr.getOnProperty().equals(SIOC.HAS_PARENT) || hvr.getOnProperty().equals(SIOC.HAS_CONTAINER))
{
if (!hvr.getHasValue().isURIResource())
{
if (log.isErrorEnabled()) log.error("Value restriction on class {} for property {} is not a URI resource", ontClass, hvr.getOnProperty());
throw new OntologyException("Value restriction on class '" + ontClass + "' for property '" + hvr.getOnProperty() + "' is not a URI resource");
}
Resource absolutePath = hvr.getHasValue().asResource();
return UriBuilder.fromUri(absolutePath.getURI());
}
}
}
}
finally
{
superClassIt.close();
}
return getAbsolutePathBuilder();
}
示例2: constructInstance
import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
/**
* Constructs new anonymous individual of an ontology class.
* It walks up the superclass chains and executes SPIN constructors.
*
* @param forClass class for which to construct new instance
* @param property property that attaches <code>CONSTRUCT</code> query resource to class resource, usually <code>spin:constructor</code>
* @param instance the instance resource
* @param baseURI base URI of the query
* @param reachedClasses classes that were already constructed
* @see org.spinrdf.inference.SPINConstructors
* @return the instance resource with constructed properties
*/
public Resource constructInstance(OntClass forClass, Property property, Resource instance, String baseURI, Set<OntClass> reachedClasses)
{
if (forClass == null) throw new IllegalArgumentException("OntClass cannot be null");
if (instance == null) throw new IllegalArgumentException("Instance Resource cannot be null");
if (baseURI == null) throw new IllegalArgumentException("Base URI cannot be null");
if (reachedClasses == null) throw new IllegalArgumentException("Set<OntClass> cannot be null");
// do not construct instance for the same class more than once
if (reachedClasses.contains(forClass)) return instance;
NodeIterator constructorIt = forClass.listPropertyValues(property);
try
{
while (constructorIt.hasNext()) // traverse all constructors
{
RDFNode constructor = constructorIt.next();
if (!constructor.isResource())
{
if (log.isErrorEnabled()) log.error("Constructor is invoked but {} is not defined for class '{}'", property, forClass.getURI());
throw new OntologyException("Constructor is invoked but '" + property.getURI() + "' not defined for class '" + forClass.getURI() +"'");
}
Statement queryText = constructor.asResource().getProperty(SP.text);
if (queryText == null || !queryText.getObject().isLiteral())
{
if (log.isErrorEnabled()) log.error("Constructor resource '{}' does not have sp:text property", constructor);
throw new OntologyException("Constructor resource '" + constructor + "' does not have sp:text property");
}
Query basedQuery = new ParameterizedSparqlString(queryText.getString(), baseURI).asQuery();
QuerySolutionMap bindings = new QuerySolutionMap();
bindings.add(SPIN.THIS_VAR_NAME, instance);
// skip SPIN template bindings for now - might support later
// execute the constructor on the target model
try (QueryExecution qex = QueryExecutionFactory.create(basedQuery, instance.getModel()))
{
qex.setInitialBinding(bindings);
instance.getModel().add(qex.execConstruct());
reachedClasses.add(forClass);
}
}
}
finally
{
constructorIt.close();
}
ExtendedIterator<OntClass> superClassIt = forClass.listSuperClasses();
try
{
while (superClassIt.hasNext())
{
OntClass superClass = superClassIt.next();
constructInstance(superClass, property, instance, baseURI, reachedClasses);
}
}
finally
{
superClassIt.close();
}
return instance;
}
示例3: addInstance
import org.apache.jena.ontology.OntClass; //导入方法依赖的package包/类
public Resource addInstance(OntClass forClass, Property property, Resource instance, String baseURI, Set<OntClass> reachedClasses)
{
if (forClass == null) throw new IllegalArgumentException("OntClass cannot be null");
if (property == null) throw new IllegalArgumentException("Property cannot be null");
if (instance == null) throw new IllegalArgumentException("Resource cannot be null");
if (baseURI == null) throw new IllegalArgumentException("Base URI string cannot be null");
if (reachedClasses == null) throw new IllegalArgumentException("Set<OntClass> cannot be null");
constructInstance(forClass, property, instance, baseURI, new HashSet<OntClass>()).
addProperty(RDF.type, forClass);
reachedClasses.add(forClass);
// evaluate AllValuesFromRestriction to construct related instances
ExtendedIterator<OntClass> superClassIt = forClass.listSuperClasses();
try
{
while (superClassIt.hasNext())
{
OntClass superClass = superClassIt.next();
// construct restriction
if (superClass.canAs(AllValuesFromRestriction.class))
{
AllValuesFromRestriction avfr = superClass.as(AllValuesFromRestriction.class);
if (avfr.getAllValuesFrom().canAs(OntClass.class))
{
OntClass valueClass = avfr.getAllValuesFrom().as(OntClass.class);
if (reachedClasses.contains(valueClass))
{
if (log.isErrorEnabled()) log.error("Circular template restriction between '{}' and '{}' is not allowed", forClass.getURI(), valueClass.getURI());
throw new OntologyException("Circular template restriction between '" + forClass.getURI() + "' and '" + valueClass.getURI() + "' is not allowed");
}
Resource value = instance.getModel().createResource().
addProperty(RDF.type, valueClass);
instance.addProperty(avfr.getOnProperty(), value);
// add inverse properties
ExtendedIterator<? extends OntProperty> it = avfr.getOnProperty().listInverseOf();
try
{
while (it.hasNext())
{
value.addProperty(it.next(), instance);
}
}
finally
{
it.close();
}
addInstance(valueClass, property, value, baseURI, reachedClasses);
}
}
}
}
finally
{
superClassIt.close();
}
return instance;
}