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; }
@Override public boolean hasStatement(Statement statement) { if (statement == null) { return false; } Model graph = null; GraphConnection graphConnection = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); SimpleSelector selector = getJenaSelector(graph, statement); return graph.contains(selector.getSubject(), selector.getPredicate(), selector.getObject()); } finally { if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } }
/** Create a selector. A model <b>may</b> restrict statements that are tested using * the <CODE>selects</CODE> method to those whose subject matches the * subject parameter, whose predicate matches the predicate parameter and whose * object matches the object paramater. Any null parameter is considered to * match anything. * @param subject if not null, the subject of selected statements * must equal this argument. * @param predicate if not null, the predicate of selected statements * must equal this argument. * @param object the object of selected statements * must equal this argument - the null string matches the empty string * @param language the language of the object constraint */ public SimpleSelector(Resource subject, Property predicate, String object, String language) { this.subject = subject; this.predicate = predicate; if (object != null) { this.object = literal( object, language ); } else { this.object = null; } }
@Override public List<Node> getObjects(Node subject, Node predicate) { Model graph = null; GraphConnection graphConnection = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); SimpleSelector selector = getJenaSelector(graph, new StatementImpl(subject, predicate, null)); NodeIterator it = graph.listObjectsOfProperty(selector.getSubject(), selector.getPredicate()); List<Node> res = new ArrayList<Node>(); while (it.hasNext()) { res.add(getNXRelationsNode(it.nextNode().asNode())); } return res; } finally { if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } }
@Override public List<Node> getSubjects(Node predicate, Node object) { Model graph = null; GraphConnection graphConnection = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); SimpleSelector selector = getJenaSelector(graph, new StatementImpl(null, predicate, object)); ResIterator it = graph.listSubjectsWithProperty(selector.getPredicate(), selector.getObject()); List<Node> res = new ArrayList<Node>(); while (it.hasNext()) { res.add(getNXRelationsNode(it.nextResource().asNode())); } return res; } finally { if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } }
/** Test whether a statement should be included in a selection. This method * tests whether the supplied statement satisfies the subject, predicate and * object constraints of the selector and then tests whether it matches the * application provided <CODE>selects</CODE> method. * @param s the statement to be tested * @return true if the statement satisfies the subject, object * and predicate constraints and the selects constraint. */ @Override public boolean test(Statement s) { return (subject == null || subject.equals(s.getSubject())) && (predicate == null || predicate.equals(s.getPredicate())) && (object == null || object.equals(s.getObject())) && selects(s); }
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; }
/** Create a selector. A model <b>may</b> restrict statements that are tested using * the <CODE>selects</CODE> method to those whose subject matches the * subject parameter, whose predicate matches the predicate parameter and whose * object matches the object paramater. Any null parameter is considered to * match anything. * @param subject if not null, the subject of selected statements * must equal this argument. * @param predicate if not null, the predicate of selected statements * must equal this argument. * @param object if not null, the object of selected statements * must equal this argument. */ public SimpleSelector(Resource subject, Property predicate, Object object) { this.subject = subject; this.predicate = predicate; if (object != null) { this.object = literal( object.toString(), "" ); } else { this.object = null; } }
Selector s1 = new SimpleSelector(resource, ORE.aggregates, (RDFNode) null); Selector s2 = new SimpleSelector(resource, ORE.describes, (RDFNode) null); Selector s3 = new SimpleSelector(resource, ORE.isAggregatedBy, (RDFNode) null); Selector s4 = new SimpleSelector(resource, ORE.isDescribedBy, (RDFNode) null); Selector s5 = new SimpleSelector(resource, ORE.lineage, (RDFNode) null); Selector s6 = new SimpleSelector(resource, ORE.proxyFor, (RDFNode) null); Selector s7 = new SimpleSelector(resource, ORE.proxyIn, (RDFNode) 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()) {
Selector s1 = new SimpleSelector(null, ORE.aggregates, resource); Selector s2 = new SimpleSelector(null, ORE.describes, resource); Selector s3 = new SimpleSelector(null, ORE.isAggregatedBy, resource); Selector s4 = new SimpleSelector(null, ORE.isDescribedBy, resource); Selector s5 = new SimpleSelector(null, ORE.lineage, resource); Selector s6 = new SimpleSelector(null, ORE.proxyFor, resource); Selector s7 = new SimpleSelector(null, ORE.proxyIn, resource);
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<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> 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); } }