本文整理汇总了Java中org.apache.jena.util.iterator.ExtendedIterator.close方法的典型用法代码示例。如果您正苦于以下问题:Java ExtendedIterator.close方法的具体用法?Java ExtendedIterator.close怎么用?Java ExtendedIterator.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.util.iterator.ExtendedIterator
的用法示例。
在下文中一共展示了ExtendedIterator.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasSuperTemplate
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
@Override
public final boolean hasSuperTemplate(Template superTemplate)
{
if (superTemplate == null) throw new IllegalArgumentException("Template cannot be null");
ExtendedIterator<OntClass> it = listSuperClasses(false);
try
{
while (it.hasNext())
{
OntClass nextClass = it.next();
if (nextClass.canAs(Template.class))
{
Template nextTemplate = nextClass.as(Template.class);
if (nextTemplate.equals(superTemplate) || nextTemplate.hasSuperTemplate(superTemplate))
return true;
}
}
}
finally
{
it.close();
}
return false;
}
示例2: getObject
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
public static Node getObject(Node subject, Node predicate, Graph graph) {
ExtendedIterator<Triple> it = graph.find(subject, predicate, Node.ANY);
try {
return it.hasNext()
? it.next().getObject()
: null;
} finally {
it.close();
}
}
示例3: init
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
@Override
public void init(ClassPropertyMetadata cpm, Node classNode, Graph graph) {
ExtendedIterator<Triple> it = graph.find(classNode, RDFS.subClassOf.asNode(), Node.ANY);
while(it.hasNext()) {
Node superClass = it.next().getObject();
if(superClass.isBlank() && graph.contains(superClass, OWL.onProperty.asNode(), cpm.getPredicate())) {
if(cpm.getLocalRange() == null) {
Node localRange = JenaNodeUtil.getObject(superClass, OWL.allValuesFrom.asNode(), graph);
if(localRange != null) {
cpm.setLocalRange(localRange);
it.close();
break;
}
}
if(cpm.getMaxCount() == null) {
Node maxCountNode = JenaNodeUtil.getObject(superClass, OWL.maxCardinality.asNode(), graph);
if(maxCountNode == null) {
maxCountNode = JenaNodeUtil.getObject(superClass, OWL.cardinality.asNode(), graph);
}
if(maxCountNode != null && maxCountNode.isLiteral()) {
Object value = maxCountNode.getLiteralValue();
if(value instanceof Number) {
cpm.setMaxCount(((Number) value).intValue());
}
}
}
}
}
}
示例4: addSuperParameters
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
protected Map<Property, Parameter> addSuperParameters(Template template, Map<Property, Parameter> args)
{
if (template == null) throw new IllegalArgumentException("Template Set cannot be null");
if (args == null) throw new IllegalArgumentException("Parameter Map cannot be null");
ExtendedIterator<OntClass> superIt = template.listSuperClasses();
try
{
while (superIt.hasNext())
{
OntClass superClass = superIt.next();
if (superClass.canAs(Template.class))
{
Template superTemplate = superClass.as(Template.class);
Map<Property, Parameter> superArgs = superTemplate.getLocalParameters();
Iterator<Entry<Property, Parameter>> entryIt = superArgs.entrySet().iterator();
while (entryIt.hasNext())
{
Entry<Property, Parameter> entry = entryIt.next();
args.putIfAbsent(entry.getKey(), entry.getValue()); // reject Parameters for existing predicates
}
addSuperParameters(superTemplate, args); // recursion to super class
}
}
}
finally
{
superIt.close();
}
return args;
}
示例5: getLanguages
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
protected List<Locale> getLanguages(Property property)
{
if (property == null) throw new IllegalArgumentException("Property cannot be null");
List<Locale> languages = new ArrayList<>();
Resource langs = getPropertyResourceValue(property);
if (langs != null)
{
if (!langs.canAs(RDFList.class))
{
if (log.isErrorEnabled()) log.error("ldt:lang value is not an rdf:List on template '{}'", getURI());
throw new OntologyException("ldt:lang value is not an rdf:List on template '" + getURI() +"'");
}
// could use list order as priority (quality value q=)
RDFList list = langs.as(RDFList.class);
ExtendedIterator<RDFNode> it = list.iterator();
try
{
while (it.hasNext())
{
RDFNode langTag = it.next();
if (!langTag.isLiteral())
{
if (log.isErrorEnabled()) log.error("Non-literal language tag (ldt:lang member) on template '{}'", getURI());
throw new OntologyException("Non-literal language tag (ldt:lang member) on template '" + getURI() +"'");
}
languages.add(Locale.forLanguageTag(langTag.asLiteral().getString()));
}
}
finally
{
it.close();
}
}
return languages;
}
示例6: getAbsolutePathBuilder
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的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();
}
示例7: check
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的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();
}
}
示例8: constructInstance
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的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;
}
示例9: addInstance
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的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;
}
示例10: match
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
/**
* Matches path (relative URI) against URI templates in sitemap ontology.
* This method uses Jersey implementation of the JAX-RS URI matching algorithm.
*
* @param ontology sitemap ontology
* @param path URI path
* @param level
* @return URI template/class mapping
*/
public List<TemplatePrecedence> match(Ontology ontology, CharSequence path, int level)
{
if (ontology == null) throw new IllegalArgumentException("Ontology cannot be null");
if (path == null) throw new IllegalArgumentException("CharSequence cannot be null");
if (log.isTraceEnabled()) log.trace("Matching path '{}' against resource templates in sitemap: {}", path, ontology);
if (log.isTraceEnabled()) log.trace("Ontology import level: {}", level);
List<TemplatePrecedence> matches = new ArrayList<>();
ResIterator it = ontology.getOntModel().listResourcesWithProperty(RDF.type, LDT.Template);
try
{
while (it.hasNext())
{
Template template = it.next().as(Template.class);
// only match templates defined in this ontology - maybe reverse loops?
if (template.getIsDefinedBy() != null && template.getIsDefinedBy().equals(ontology))
{
if (template.getPath() == null)
{
if (log.isErrorEnabled()) log.error("Template class {} does not have value for {} annotation", template, LDT.path);
throw new OntologyException("Template class '" + template + "' does not have value for '" + LDT.path + "' annotation");
}
UriTemplate uriTemplate = template.getPath();
HashMap<String, String> map = new HashMap<>();
if (uriTemplate.match(path, map))
{
if (log.isTraceEnabled()) log.trace("Path {} matched UriTemplate {}", path, uriTemplate);
if (log.isTraceEnabled()) log.trace("Path {} matched OntClass {}", path, template);
TemplatePrecedence precedence = new TemplatePrecedence(template, level * -1);
matches.add(precedence);
}
else
if (log.isTraceEnabled()) log.trace("Path {} did not match UriTemplate {}", path, uriTemplate);
}
}
List<Ontology> importedOntologies = new ArrayList<>(); // collect imports first to avoid CME within iterator
ExtendedIterator<OntResource> importIt = ontology.listImports();
try
{
while (importIt.hasNext())
{
OntResource importRes = importIt.next();
if (importRes.canAs(Ontology.class)) importedOntologies.add(importRes.asOntology());
}
}
finally
{
importIt.close();
}
//traverse imports recursively, safely make changes to OntModel outside the iterator
for (Ontology importedOntology : importedOntologies)
matches.addAll(match(importedOntology, path, level + 1));
}
finally
{
it.close();
}
return matches;
}
示例11: match
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的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;
}