@Override public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { return this.delegatedModel.contains(subject, predicate, object); }
@Override public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { return this.delegatedModel.contains(subject, predicate, object); }
/** * Check if a resource is an instance of a given RDFS/OWL class. * * @param model - the underlying RDF2Go model * @param instanceID - URI or BlankNode of the instance * @param classURI - URI of the RDFS/OWL class * @return true if the model contains the triple (instanceID; rdf:type, * classURI) * @throws ModelRuntimeException ... */ public static boolean isInstanceOf(Model model, Resource instanceID, URI classURI) throws ModelRuntimeException { return model.contains(instanceID, RDF.type, classURI); }
@Override public boolean contains(Statement s) throws ModelRuntimeException { log.debug("contains " + s); return this.model.contains(s); }
public static boolean hasInstance(Model model, URI uri, URI classURI) { try { return (model.contains(uri, RDF.type, classURI)); } catch (ModelRuntimeException e) { throw new RuntimeException(e); } }
@Override public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { log.debug("contains " + subject + " " + predicate + " " + object); return this.model.contains(subject, predicate, object); }
@Override public boolean contains(ResourceOrVariable subject, UriOrVariable predicate, String plainLiteral) throws ModelRuntimeException { log.debug("contains " + subject + " " + predicate + " " + plainLiteral); return this.model.contains(subject, predicate, plainLiteral); }
/** * Check if the model contains an instance of the given RDFS/OWL schema * class. It is assumed that every instance of a class has an accompanying * triple of the form (instanceID, rdf:type, classURI) in the model. * * @param model - the underlying RDF2Go model * @param classURI - URI of the RDFS/OWL schema class * @return true if the model contains an instance of the class URI */ public static boolean containsInstance(Model model, URI classURI) { try { return (model.contains(Variable.ANY, RDF.type, classURI)); } catch(Exception e) { throw new RuntimeException(e); } }
/** * Check if .this object is an instance of the given RDFS/OWL class URI. * * @param classURI - * URI of the RDFS/OWL class * @return true if .this is an instance of the given classURI */ public boolean isInstanceof(URI classURI) throws ModelRuntimeException { return this.model.contains(this.getResource(), RDF.type, classURI); }
/** * @param a a Model * @param b a model * @param result should be empty before calling this method * @return the result after executing the intersection * @throws ModelRuntimeException from underlying IO errors, if any. */ public static Model intersection(Model a, Model b, Model result) throws ModelRuntimeException { for(Statement s : a) { if(b.contains(s)) { result.addStatement(s); } } return result; }
public static boolean hasInstance(Model model, Resource classURI, Resource resourceSubject) { if(model == null) throw new IllegalArgumentException("model may not be null"); if(resourceSubject == null) throw new IllegalArgumentException("resourceSubject may not be null"); if(classURI == null) throw new IllegalArgumentException("classURI may not be null"); assertOpen(model); Resource rdfResource = RDFReactorRuntime.genericResource2RDF2Goresource(model, resourceSubject); return model.contains(rdfResource, RDF.type, classURI); }
public static boolean hasValue(Model model, Resource resourceSubject, URI propertyURI) { if(model == null) throw new IllegalArgumentException("model may not be null"); if(resourceSubject == null) throw new IllegalArgumentException("resourceSubject may not be null"); if(propertyURI == null) throw new IllegalArgumentException("propertyURI may not be null"); assertOpen(model); Resource rdfResource = RDFReactorRuntime.genericResource2RDF2Goresource(model, resourceSubject); return model.contains(rdfResource, propertyURI, Variable.ANY); }
public static Object getInstance(Model model, URI uri, Class<?> javaClass) throws Exception { if (model.contains(uri, RDF.type, getClassURI(javaClass))) { return RDFReactorRuntime.resource2reactorbase(model, uri, javaClass); } else return null; }
public static boolean hasValue(Model model, Resource resourceSubject, URI propertyURI, Object value) { if(model == null) throw new IllegalArgumentException("model may not be null"); if(resourceSubject == null) throw new IllegalArgumentException("resourceSubject may not be null"); if(propertyURI == null) throw new IllegalArgumentException("propertyURI may not be null"); if(value == null) throw new IllegalArgumentException("value may not be null"); assertOpen(model); Resource rdfResource = RDFReactorRuntime.genericResource2RDF2Goresource(model, resourceSubject); Node node = RDFReactorRuntime.java2node(model, value); return model.contains(rdfResource, propertyURI, node); }
.contains(this.instanceIdentifier, RDF.type, classURI)) { log.debug("adding type information: " + this.instanceIdentifier + " a " + classURI);
/** * Check if the resource identified by resourceID, has a property * identidified by propertyURI which has the given value among its values. * * @param model - * the underlying RDF2Go model * @param resource - * must be an URI or a BlankNode * @param propertyURI - * URI of the property * @param value - * look for this value of the property * @return true if value is among values for the property * @throws Exception */ @Patrolled public static boolean containsGivenValue(Model model, Resource resource, URI propertyURI, Object value) throws ModelRuntimeException { Node objectNode = RDFReactorRuntime.java2node(model, value); return model.contains(resource, propertyURI, objectNode); }
/** * Remove a value of a property from a resource. * * @param model - * the underlying RDF2Go model * @param resource - * URI or BlankNode of the resource * @param propertyURI - * URI of the property * @param value - * value of the property which is removed * @return true if value could be removed * @throws Exception */ static boolean removeValue(Model model, Resource resource, URI propertyURI, Object value) throws ModelRuntimeException { Node objectNode = RDFReactorRuntime.java2node(model, value); boolean found = model.contains(resource, propertyURI, objectNode); if (found) { model.removeStatement(resource, propertyURI, objectNode); } return found; }
public static void add(Model model, Resource resourceSubject, URI propertyURI, Object value, int maxCardinality) throws CardinalityException { if(model == null) throw new IllegalArgumentException("model may not be null"); if(resourceSubject == null) throw new IllegalArgumentException("resourceSubject may not be null"); if(propertyURI == null) throw new IllegalArgumentException("propertyURI may not be null"); if(value == null) throw new IllegalArgumentException("value may not be null"); assertOpen(model); Resource rdfResource = RDFReactorRuntime.genericResource2RDF2Goresource(model, resourceSubject); Node node = RDFReactorRuntime.java2node(model, value); if(model.contains(rdfResource, propertyURI, node)) { return; } long count = countPropertyValues(model, rdfResource, propertyURI); if(count < maxCardinality) { model.addStatement(rdfResource, propertyURI, node); } else throw new CardinalityException("Adding this value would violate maxCardinality = " + maxCardinality + " for property " + propertyURI); }
@Test public void testUriRename() { Model m = RDF2Go.getModelFactory().createModel(); m.open(); URI a = new URIImpl("urn:test:a"); URI b = new URIImpl("urn:test:b"); URI c = new URIImpl("urn:test:c"); URI superRel = new URIImpl( "http://www.semanticdesktop.org/ontologies/2007/09/cds/hasSuperRelation"); m.addStatement(superRel, b, c); m.addStatement(a, superRel, c); m.addStatement(a, b, superRel); Map<String, URI> nsMap = new HashMap<String, URI>(); URISearchReplaceRule.searchAndReplace(m, nsMap, superRel, RDFS.subPropertyOf); m.dump(); Assert.assertFalse(m.contains(superRel, Variable.ANY, Variable.ANY)); }
@Test public void testUriPrefixRename() { Model m = RDF2Go.getModelFactory().createModel(); m.open(); URI a = new URIImpl("urn:test:a"); URI b = new URIImpl("urn:test:b"); URI c = new URIImpl("urn:test:c"); URI superRel = new URIImpl( "http://www.semanticdesktop.org/ontologies/2007/09/cds/hasSuperRelation"); m.addStatement(superRel, b, c); m.addStatement(a, superRel, c); m.addStatement(a, b, superRel); NamespaceSearchReplaceRule.searchAndReplace(m, "urn:test:", "http://example.com#"); m.dump(); Assert.assertFalse(m.contains(a, Variable.ANY, Variable.ANY)); } }