本文整理汇总了Java中org.apache.jena.util.iterator.ExtendedIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java ExtendedIterator.next方法的具体用法?Java ExtendedIterator.next怎么用?Java ExtendedIterator.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.util.iterator.ExtendedIterator
的用法示例。
在下文中一共展示了ExtendedIterator.next方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: execAllNodes
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
private QueryIterator execAllNodes(Var subjVar, Node nodeLocalname, Binding input, ExecutionContext execCxt)
{
if ( ! nodeLocalname.isVariable() )
{
if ( ! nodeLocalname.isLiteral() )
// Not a variable, not a literal=> can't match
return QueryIterNullIterator.create(execCxt) ;
if( ! NodeUtils.isSimpleString(nodeLocalname) )
return QueryIterNullIterator.create(execCxt) ;
}
//Set bindings = new HashSet() ; // Use a Set if you want unique results.
List<Binding> bindings = new ArrayList<Binding>() ; // Use a list if you want counting results.
Graph graph = execCxt.getActiveGraph() ;
ExtendedIterator<Triple>iter = graph.find(Node.ANY, Node.ANY, Node.ANY) ;
for ( ; iter.hasNext() ; )
{
Triple t = iter.next() ;
slot(bindings, input, t.getSubject(), subjVar, nodeLocalname) ;
slot(bindings, input, t.getPredicate(), subjVar, nodeLocalname) ;
slot(bindings, input, t.getObject(), subjVar, nodeLocalname) ;
}
return new QueryIterPlainWrapper(bindings.iterator(), execCxt) ;
}
示例3: assertIdenticalGraphs
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
private void assertIdenticalGraphs(final Model orig, final Model roundtripped) {
final Graph roundtrippedGraph = roundtripped.getGraph();
final ExtendedIterator<Triple> originalTripleIt = orig.getGraph().find(Node.ANY, Node.ANY, Node.ANY);
while (originalTripleIt.hasNext()) {
final Triple t = originalTripleIt.next();
assertTrue("Roundtripped resource should contain triple " + t + "!", roundtrippedGraph.contains(t));
roundtrippedGraph.delete(t);
}
assertTrue("Triples round in roundtripped resource that weren't in original!\n" + roundtrippedGraph,
roundtrippedGraph.isEmpty());
}
示例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: post
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
String data = "";
String ontologyUri = null;
try {
data = ThingDescriptionUtils.streamToString(payload);
ontologyUri = new URI(data).toString();
data = null;
} catch (IOException e1) {
e1.printStackTrace();
throw new BadRequestException();
} catch (URISyntaxException e2) {
// do nothing
}
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
String rootId = null;
OntModel ontology = ModelFactory.createOntologyModel();
if (data == null) {
ontology.read(ontologyUri.toString(), "Turtle");
} else {
ontologyUri = "http://example.org/"; // TODO
ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
}
Model tdb = dataset.getDefaultModel();
ExtendedIterator<Ontology> it = ontology.listOntologies();
if (!it.hasNext()) {
throw new BadRequestException();
}
while (it.hasNext()) {
Ontology o = it.next();
String prefix = ontology.getNsURIPrefix(o.getURI());
// if no prefix found, generates id
String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
URI resourceUri = URI.create(normalize(uri) + "/" + id);
OntModel axioms;
if (isRootOntology(o.getURI(), ontology)) {
rootId = id;
axioms = ontology;
} else {
axioms = ontology.getImportedModel(o.getURI());
}
// TODO Check if the vocab isn't already registered in the dataset
dataset.addNamedModel(resourceUri.toString(), axioms);
Date currentDate = new Date(System.currentTimeMillis());
DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));
addToAll("/vocab/" + id, new VocabularyHandler(id, instances));
ThingDirectory.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
}
dataset.commit();
RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
return resource;
} catch (Exception e) {
e.printStackTrace();
throw new RESTException();
} finally {
dataset.end();
}
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: post
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
String data = "";
String ontologyUri = null;
try {
data = ThingDescriptionUtils.streamToString(payload);
ontologyUri = new URI(data).toString();
data = null;
} catch (IOException e1) {
e1.printStackTrace();
throw new BadRequestException();
} catch (URISyntaxException e2) {
// do nothing
}
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
String rootId = null;
OntModel ontology = ModelFactory.createOntologyModel();
if (data == null) {
ontology.read(ontologyUri.toString(), "Turtle");
} else {
ontologyUri = "http://example.org/"; // TODO
ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
}
Model tdb = dataset.getDefaultModel();
ExtendedIterator<Ontology> it = ontology.listOntologies();
if (!it.hasNext()) {
throw new BadRequestException();
}
while (it.hasNext()) {
Ontology o = it.next();
String prefix = ontology.getNsURIPrefix(o.getURI());
// if no prefix found, generates id
String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
URI resourceUri = URI.create(normalize(uri) + "/" + id);
OntModel axioms;
if (isRootOntology(o.getURI(), ontology)) {
rootId = id;
axioms = ontology;
} else {
axioms = ontology.getImportedModel(o.getURI());
}
// TODO Check if the vocab isn't already registered in the dataset
dataset.addNamedModel(resourceUri.toString(), axioms);
Date currentDate = new Date(System.currentTimeMillis());
DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));
addToAll("/vocab/" + id, new VocabularyHandler(id, instances));
Repository.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
}
dataset.commit();
RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
return resource;
} catch (Exception e) {
e.printStackTrace();
throw new RESTException();
} finally {
dataset.end();
}
}
示例14: getTidiedGraph
import org.apache.jena.util.iterator.ExtendedIterator; //导入方法依赖的package包/类
private static Graph getTidiedGraph(final Graph graph) {
final Graph betterGraph = GraphFactory.createDefaultGraph();
final ExtendedIterator<Triple> triples = graph.find(Node.ANY, Node.ANY, Node.ANY);
final Map<Node, Node> bnodeMap = new HashMap<>();
while (triples.hasNext()) {
final Triple next = triples.next();
Triple replacement = next;
if (isSkolemizedBnode(replacement.getSubject())) {
if (!bnodeMap.containsKey(replacement.getSubject())) {
bnodeMap.put(replacement.getSubject(), createBlankNode());
}
replacement = new Triple(bnodeMap.get(replacement.getSubject()),
replacement.getPredicate(),
replacement.getObject());
}
if (isSkolemizedBnode(replacement.getObject())) {
if (!bnodeMap.containsKey(replacement.getObject())) {
bnodeMap.put(replacement.getObject(), createBlankNode());
}
replacement = new Triple(replacement.getSubject(),
replacement.getPredicate(),
bnodeMap.get(replacement.getObject()));
}
if (replacement.getObject().isLiteral()
&& replacement.getObject().getLiteral().getDatatype() != null
&& replacement.getObject().getLiteral().getDatatype().equals(XSDDatatype.XSDstring)) {
replacement = new Triple(replacement.getSubject(),
replacement.getPredicate(),
createLiteral(replacement.getObject().getLiteral().getLexicalForm()));
}
betterGraph.add(replacement);
}
return betterGraph;
}