public boolean hasProxy() throws OREException { Selector selector = new SimpleSelector(null, ORE.proxyFor, res); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { return true; } return false; }
public ResourceMap getResourceMap(URI uri) throws OREException { Selector selector = new SimpleSelector(null, ORE.isAggregatedBy, res); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { ResourceMap rem = JenaOREFactory.createResourceMap(model, uri); return rem; } return null; }
private List<EIInstance> create(final Model model) { if ( model == null ) { return Collections.emptyList(); } final List<EIInstance> instances = new ArrayList<EIInstance>(); final Set<Resource> subjects = model.listSubjects().toSet(); // create an EIInstance per subject for (final Resource r : subjects) { final Model subModel = model.query( new SimpleSelector( r, null, (RDFNode)null ) ); final EIInstance ei = jenaIntanceFactory.create( EIURI.create( r.getURI() ), subModel ); if ( ei != null && !EIInstance.NULL_INSTANCE.equals( ei ) ) { instances.add( ei ); } } return instances; }
Resource subjectResource = rIter.next(); log.trace("Testing Subject {} to see if it is the Object of any Statement.", subjectResource); if (!m.listStatements(new SimpleSelector(null, null, subjectResource)).hasNext()) {
public void setModel(Model model, URI resourceURI) throws OREException { // verify that the URI for the resource map is not already in use for another // part of the object Resource subject = model.createResource(resourceURI.toString()); Selector aggSelector = new SimpleSelector(subject, ORE.aggregates, (RDFNode) null); Selector proxySelector = new SimpleSelector(subject, ORE.proxyFor, (RDFNode) null); StmtIterator aggItr = model.listStatements(aggSelector); StmtIterator proxyItr = model.listStatements(proxySelector); if (aggItr.hasNext() || proxyItr.hasNext()) { throw new OREException("ResourceMap may not have the same URI as an Aggregation or Proxy"); } // now go back and build the resource map in the super class super.setModel(model, resourceURI); } }
public void setTypes(List<URI> types) { super.setTypes(types); // ensure that the required type is still set Selector selector = new SimpleSelector(res, RDF.type, ORE.Proxy); StmtIterator itr = model.listStatements(selector); if (!itr.hasNext()) { res.addProperty(RDF.type, ORE.Proxy); } }
public void setTypes(List<URI> types) { super.setTypes(types); // ensure that the required type is still set Selector selector = new SimpleSelector(res, RDF.type, ORE.ResourceMap); StmtIterator itr = model.listStatements(selector); if (!itr.hasNext()) { res.addProperty(RDF.type, ORE.ResourceMap); } }
public void setTypes(List<URI> types) { super.setTypes(types); // ensure that the required type is still set Selector selector = new SimpleSelector(res, RDF.type, ORE.Aggregation); StmtIterator itr = model.listStatements(selector); if (!itr.hasNext()) { res.addProperty(RDF.type, ORE.Aggregation); } }
public void setTypes(List<URI> types) { super.setTypes(types); // ensure that the required type is still set Selector selector = new SimpleSelector(res, RDF.type, ORE.Aggregation); StmtIterator itr = model.listStatements(selector); if (!itr.hasNext()) { res.addProperty(RDF.type, ORE.AggregatedResource); } }
public List<ResourceMap> getResourceMaps() throws OREException { try { List<ResourceMap> rems = new ArrayList<ResourceMap>(); Selector selector = new SimpleSelector(res, ORE.isDescribedBy, (RDFNode) null); StmtIterator itr = model.listStatements(selector); while (itr.hasNext()) { Statement statement = itr.nextStatement(); ResourceMap rem = JenaOREFactory.createResourceMap(model, new URI(statement.getSubject().getURI())); rems.add(rem); } return rems; } catch (URISyntaxException e) { throw new OREException(e); } }
public List<Proxy> getProxies() throws OREException { try { Selector selector = new SimpleSelector(null, ORE.proxyIn, res); List<Proxy> proxies = new ArrayList<Proxy>(); StmtIterator itr = model.listStatements(selector); while (itr.hasNext()) { Statement statement = itr.nextStatement(); URI resURI = new URI(statement.getSubject().getURI()); Proxy proxy = JenaOREFactory.createProxy(model, resURI); proxies.add(proxy); } return proxies; } catch (URISyntaxException e) { throw new OREException(e); } }
public List<ResourceMap> getAuthoritative() throws OREException { try { List<ResourceMap> rems = new ArrayList<ResourceMap>(); Selector selector = new SimpleSelector(null, OREX.isAuthoritativeFor, res); StmtIterator itr = model.listStatements(selector); while (itr.hasNext()) { Statement statement = itr.nextStatement(); ResourceMap rem = JenaOREFactory.createResourceMap(model, new URI(statement.getSubject().getURI())); rems.add(rem); } return rems; } catch (URISyntaxException e) { throw new OREException(e); } }
public List<Proxy> getRelated(URI uri) throws OREException { try { List<Proxy> related = new ArrayList<Proxy>(); Selector selector = new SimpleSelector(res, model.createProperty(uri.toString()), (RDFNode) null); StmtIterator itr = model.listStatements(selector); while (itr.hasNext()) { Statement statement = itr.nextStatement(); if (statement.getObject() instanceof Resource) { Proxy proxy = JenaOREFactory.createProxy(model, new URI(((Resource) statement.getObject()).getURI())); related.add(proxy); } } return related; } catch (URISyntaxException e) { throw new OREException(e); } }
public Proxy createProxy(URI proxyURI, URI arURI) throws OREException { // first validate whether this is allowed: // - proxy must be unique in Aggregation // - proxy must be unique to AggregatedResource Selector selector = new SimpleSelector(model.createResource(proxyURI.toString()), null, (RDFNode) null); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { throw new OREException("URI: " + proxyURI.toString() + " is already in use by this Aggregation"); } // go ahead and create the proxy Proxy proxy = OREFactory.createProxy(proxyURI); // if the URI doesn't exist, it will be created proxy.setProxyForURI(arURI); this.addProxy(proxy); ((ProxyJena) proxy).setModel(model, proxyURI); return proxy; }
public void setTypes(List<URI> types) { super.setTypes(types); // ensure that the required type is still set Selector selector = new SimpleSelector(res, RDF.type, model.createResource("http://purl.org/dc/terms/Agent")); StmtIterator itr = model.listStatements(selector); if (!itr.hasNext()) { res.addProperty(RDF.type, model.createResource("http://purl.org/dc/terms/Agent")); } }
public Proxy getProxy() throws OREException { try { Selector selector = new SimpleSelector(null, ORE.proxyFor, res); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { Statement statement = itr.nextStatement(); Proxy proxy = JenaOREFactory.createProxy(model, new URI(statement.getSubject().getURI())); return proxy; } return null; } catch (URISyntaxException e) { throw new OREException(e); } }
public void setAuthoritative(boolean authoritative) throws OREException { if (authoritative) { Selector selector = new SimpleSelector(null, ORE.isDescribedBy, res); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { Statement statement = itr.nextStatement(); res.addProperty(OREX.isAuthoritativeFor, statement.getSubject()); } } else { res.removeAll(OREX.isAuthoritativeFor); } }
public ResourceMap parse(InputStream is) throws OREParserException { try { Model model = this.parseToModel(is); Selector selector = new SimpleSelector(null, ORE.describes, (RDFNode) null); StmtIterator itr = model.listStatements(selector); if (itr.hasNext()) { Statement statement = itr.nextStatement(); Resource resource = (Resource) statement.getSubject(); ResourceMap rem = JenaOREFactory.createResourceMap(model, new URI(resource.getURI())); return rem; } return null; } catch (URISyntaxException e) { throw new OREParserException(e); } catch (OREException e) { throw new OREParserException(e); } }
protected void recursiveRemove(Resource resource) throws OREException { // set up a general selector for getting things which the resource is the subject of Selector self = new SimpleSelector(resource, null, (RDFNode) null); // first thing to do is drill all the way to the bottom of the hierarchy using // this first iterator StmtIterator itr1 = model.listStatements(self); while (itr1.hasNext()) { Statement statement = itr1.nextStatement(); RDFNode node = statement.getObject(); if (node instanceof Resource) { if (this.recursivelyRemovable(statement)) { this.recursiveRemove((Resource) node); } } } // finally, we can remove all these statements using a second iterator StmtIterator itr2 = model.listStatements(self); model.remove(itr2); }
/** * Gets Jena statement selector corresponding to the NXRelations statement. * * @param graph the jena graph * @param nuxStatement NXRelations statement * @return jena statement selector */ private static SimpleSelector getJenaSelector(Model graph, Statement nuxStatement) { com.hp.hpl.jena.rdf.model.Resource subjResource = null; com.hp.hpl.jena.graph.Node subject = getJenaNode(nuxStatement.getSubject()); if (subject != null && subject.isURI()) { subjResource = graph.getResource(subject.getURI()); } Property predProp = null; com.hp.hpl.jena.graph.Node predicate = getJenaNode(nuxStatement.getPredicate()); if (predicate != null && predicate.isURI()) { predProp = graph.getProperty(predicate.getURI()); } com.hp.hpl.jena.graph.Node object = getJenaNode(nuxStatement.getObject()); RDFNode objRDF = null; if (object != null) { objRDF = graph.asRDFNode(object); } return new SimpleSelector(subjResource, predProp, objRDF); }