本文整理汇总了Java中org.apache.jena.ontology.OntResource.asOntology方法的典型用法代码示例。如果您正苦于以下问题:Java OntResource.asOntology方法的具体用法?Java OntResource.asOntology怎么用?Java OntResource.asOntology使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.ontology.OntResource
的用法示例。
在下文中一共展示了OntResource.asOntology方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import org.apache.jena.ontology.OntResource; //导入方法依赖的package包/类
public void check(Ontology ontology)
{
if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
marked.put(ontology, Boolean.TRUE);
onStack.put(ontology, Boolean.TRUE);
ExtendedIterator<OntResource> it = ontology.listImports();
try
{
while (it.hasNext())
{
OntResource importRes = it.next();
if (importRes.canAs(Ontology.class))
{
Ontology imported = importRes.asOntology();
if (marked.get(imported) == null)
check(imported);
else if (onStack.get(imported))
{
cycleOntology = imported;
return;
}
}
}
onStack.put(ontology, Boolean.FALSE);
}
finally
{
it.close();
}
}
示例2: match
import org.apache.jena.ontology.OntResource; //导入方法依赖的package包/类
public SortedSet<ClassPrecedence> match(Ontology ontology, Resource resource, Property property, int level)
{
if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
if (resource == null) throw new IllegalArgumentException("Resource cannot be null");
if (property == null) throw new IllegalArgumentException("Property cannot be null");
SortedSet<ClassPrecedence> matchedClasses = new TreeSet<>();
ResIterator it = ontology.getOntModel().listResourcesWithProperty(LDT.segment);
try
{
while (it.hasNext())
{
Resource ontClassRes = it.next();
OntClass ontClass = ontology.getOntModel().getOntResource(ontClassRes).asClass();
// only match templates defined in this ontology - maybe reverse loops?
if (ontClass.getIsDefinedBy() != null && ontClass.getIsDefinedBy().equals(ontology) &&
resource.hasProperty(property, ontClass))
{
ClassPrecedence template = new ClassPrecedence(ontClass, level * -1);
if (log.isTraceEnabled()) log.trace("Resource {} matched OntClass {}", resource, ontClass);
matchedClasses.add(template);
}
}
}
finally
{
it.close();
}
ExtendedIterator<OntResource> imports = ontology.listImports();
try
{
while (imports.hasNext())
{
OntResource importRes = imports.next();
if (importRes.canAs(Ontology.class))
{
Ontology importedOntology = importRes.asOntology();
// traverse imports recursively
Set<ClassPrecedence> matchedImportClasses = match(importedOntology, resource, property, level + 1);
matchedClasses.addAll(matchedImportClasses);
}
}
}
finally
{
imports.close();
}
return matchedClasses;
}