Java Code Examples for org.apache.jena.rdf.model.ResIterator#next()
The following examples show how to use
org.apache.jena.rdf.model.ResIterator#next() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkolemizingDatasetProvider.java From Processor with Apache License 2.0 | 6 votes |
public Model process(Model model) { // if (getRequest().getMethod().equalsIgnoreCase("POST")) // { ResIterator it = model.listSubjects(); try { while (it.hasNext()) { Resource resource = it.next(); process(resource); } } finally { it.close(); } return skolemize(getOntology(), getUriInfo().getBaseUriBuilder(), getUriInfo().getAbsolutePathBuilder(), model); // } // // return model; }
Example 2
Source File: SkolemizingModelProvider.java From Processor with Apache License 2.0 | 6 votes |
@Override public Model process(Model model) { if (getRequest().getMethod().equalsIgnoreCase("POST")) { ResIterator it = model.listSubjects(); try { while (it.hasNext()) { Resource resource = it.next(); process(resource); } } finally { it.close(); } return skolemize(getOntology(), getUriInfo().getBaseUriBuilder(), getUriInfo().getAbsolutePathBuilder(), super.process(model)); } return super.process(model); }
Example 3
Source File: ClassHierarchyLoader.java From gerbil with GNU Affero General Public License v3.0 | 6 votes |
protected Set<Resource> getClasses(Model readModel) { ResIterator iterator = readModel.listSubjectsWithProperty(RDF.type, RDFS.Class); Resource r; Set<Resource> classes = new HashSet<Resource>(); while (iterator.hasNext()) { r = iterator.next(); if (!r.isAnon()) { classes.add(r); } } iterator = readModel.listSubjectsWithProperty(RDF.type, OWL.Class); while (iterator.hasNext()) { r = iterator.next(); if (!r.isAnon()) { classes.add(r); } } return classes; }
Example 4
Source File: Skolemizer.java From Processor with Apache License 2.0 | 5 votes |
public Model build(Model model) { if (model == null) throw new IllegalArgumentException("Model cannot be null"); Map<Resource, String> resourceURIMap = new HashMap<>(); ResIterator resIt = model.listSubjects(); try { while (resIt.hasNext()) { Resource resource = resIt.next(); if (resource.isAnon()) { URI uri = build(resource); if (uri != null) resourceURIMap.put(resource, uri.toString()); } } } finally { resIt.close(); } Iterator<Map.Entry<Resource, String>> entryIt = resourceURIMap.entrySet().iterator(); while (entryIt.hasNext()) { Map.Entry<Resource, String> entry = entryIt.next(); ResourceUtils.renameResource(entry.getKey(), entry.getValue()); } return model; }
Example 5
Source File: ConstraintViolationExceptionMapper.java From Processor with Apache License 2.0 | 5 votes |
@Override public Response toResponse(ConstraintViolationException ex) { Resource exception = toResource(ex, Response.Status.BAD_REQUEST, ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")); ex.getModel().add(exception.getModel()); SPINConstraints.addConstraintViolationsRDF(ex.getConstraintViolations(), ex.getModel(), true); ResIterator it = ex.getModel().listSubjectsWithProperty(RDF.type, SPIN.ConstraintViolation); try { while (it.hasNext()) { Resource violation = it.next(); // connect Response to ConstraintViolations ex.getModel().add(exception, ResourceFactory.createProperty("http://www.w3.org/ns/prov#wasDerivedFrom"), violation); } } finally { it.close(); } return getResponseBuilder(DatasetFactory.create(ex.getModel())). status(Response.Status.BAD_REQUEST). build(); }
Example 6
Source File: RDFToTopicMapConverter.java From ontopia with Apache License 2.0 | 5 votes |
private void doConversion(Model model) throws JenaException { StatementHandler totm = new ToTMStatementHandler(); AResourceWrapper subjw = new AResourceWrapper(); AResourceWrapper propw = new AResourceWrapper(); AResourceWrapper objtw = new AResourceWrapper(); ALiteralWrapper litlw = new ALiteralWrapper(); ResIterator it = model.listSubjects(); while (it.hasNext()) { Resource subject = (Resource) it.next(); StmtIterator it2 = subject.listProperties(); // get all statements while (it2.hasNext()) { Statement stmt = (Statement) it2.next(); subjw.resource = stmt.getSubject(); propw.resource = stmt.getPredicate(); RDFNode obj = stmt.getObject(); if (obj instanceof Resource) { objtw.resource = (Resource) obj; totm.statement(subjw, propw, objtw); } else { litlw.literal = (Literal) obj; totm.statement(subjw, propw, litlw); } } } }
Example 7
Source File: Skolemizer.java From Processor with Apache License 2.0 | 4 votes |
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.path); 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 precedence = new ClassPrecedence(ontClass, level * -1); if (log.isTraceEnabled()) log.trace("Resource {} matched OntClass {}", resource, ontClass); matchedClasses.add(precedence); } } } 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; }
Example 8
Source File: WorkflowBundleParser.java From incubator-taverna-language with Apache License 2.0 | 4 votes |
/** * Workaround for TAVERNA-71 to find annotations in WorkflowBundle * <p> * FIXME: The annotation links should instead be stored in the * {@link Manifest} using taverna-robundle - see TAVERNA-71 * * @param wb * @throws IOException */ private void parseAnnotations(final WorkflowBundle wb) throws IOException { if (! wb.getAnnotations().isEmpty()) { // Assume already parsed return; } URITools uriTools = new URITools(); for (ResourceEntry resource : wb.getResources().listResources("annotation").values()) { Lang lang = RDFLanguages.contentTypeToLang(resource.getMediaType()); if (lang == null) { // Not a semantic annotation continue; } //System.out.println(resource.getPath()); //System.out.println(resource.getMediaType()); Annotation ann = new Annotation(); // Hackish way to generate a name from the annotation filename // as these typically are UUIDs String name = resource.getPath().replace("annotation/", "").replaceAll("\\..*", ""); // strip extension ann.setName(name); ann.setParent(wb); String path = resource.getPath(); ann.setBody(URI.create("/" + path)); URI base = wb.getGlobalBaseURI().resolve(path); Model model = ModelFactory.createDefaultModel(); InputStream inputStream = resource.getUcfPackage().getResourceAsInputStream(path); if (inputStream == null) { // Not found! continue; } RDFDataMgr.read(model, inputStream, base.toASCIIString(), lang); ResIterator subjs = model.listSubjects(); while (subjs.hasNext()) { Resource r = subjs.next(); //System.out.println(r); WorkflowBean b = uriTools.resolveUri(URI.create(r.getURI()), wb); //System.out.println(b); if (b != null) { ann.setTarget(b); } break; } } }