/** * Returns an prepared update to the default graph of the connected triplestore, * which will insert statements stating that every given resource is * an instance of the given class. * Thus for every instance <code>i</code> in <code>instances</code> the following statement will be inserted:<br> * <code><i> rdf:type <clazz> .</code><br> * {@link Update#execute()} must be called afterwards for the update to have effect. * @param instances The resources which should all be declared instances of <code>clazz</code>. * Note that the given resources must be fully qualified URIs. * @param clazz The class to which all <code>instances</code> should belong. * Must be a fully qualified URI. * @return The prepared update. * @throws RepositoryException Thrown on error regarding the connected triplestore. * @throws MalformedQueryException Thrown if the generated query is malformed, e.g. because a resource * in <code>instances</code> is not a fully qualified URI. */ private Update buildInstanceUpdate(Collection<String> instances, String clazz) throws RepositoryException, MalformedQueryException { StringBuilder query = new StringBuilder(QUERY_PREFIX) .append("INSERT DATA {"); for(String instance : instances) { query.append(" <").append(instance).append("> a <").append(clazz).append("> ."); } query.append("}"); return getConnection().prepareUpdate(query.toString()); }
/** * Persists inheritance information for the given concepts to the default graph of the connected * triplestore. * The inheritance is modelled using <code>rdfs:subClassOf</code> predicate. * @param concepts The {@link Iri} annotated concept types which inheritance structure should be persisted. * @throws RepositoryException Thrown if an error occurs while inserting into the connected triplestore. */ private void persistInheritance(Collection<Class<?>> concepts) throws RepositoryException { StringBuilder q = new StringBuilder(QUERY_PREFIX + "INSERT DATA {"); for (Class<?> concept : concepts) { Iri conceptIri = concept.getAnnotation(Iri.class); for (Class<?> superConcept : concept.getInterfaces()) { if(conceptIri != null && superConcept.isAnnotationPresent(Iri.class)) { Iri superConceptIri = superConcept.getAnnotation(Iri.class); q.append("<").append(conceptIri.value()).append("> rdfs:subClassOf <").append(superConceptIri.value()).append("> . "); } } } q.append("}"); try { getConnection().prepareUpdate(q.toString()).execute(); } catch (MalformedQueryException | UpdateExecutionException e) { throw new RepositoryException(e); } }
Update update = getConnection().prepareUpdate(query.toString()); update.execute(); } catch (MalformedQueryException e) {
/** * Persists the information that a property is a subproperty of another to the default graph of the connected triplestore. * All properties with {@link SubPropertyOf} annotation are considered. * @param annotatedObjects The {@link Iri} annotated objects that should be considered. * @throws RepositoryException Thrown on error regarding the connected triplestore. * @throws UpdateExecutionException Thrown if an error occurred while executing the update. */ private void persistSubPropertyOf(Collection<AccessibleObject> annotatedObjects) throws RepositoryException, UpdateExecutionException { // Get those methods and fields that have the @Transitive annotation: Collection<AccessibleObject> subPropertyObjects = filterObjectsWithAnnotation(annotatedObjects, SubPropertyOf.class); for (AccessibleObject object : subPropertyObjects) { String iri = getIriFromObject(object); SubPropertyOf subPropertyAnnotation = object.getAnnotation(SubPropertyOf.class); StringBuilder query = new StringBuilder(QUERY_PREFIX) .append(" INSERT DATA { "); for (String superPropertyIri : subPropertyAnnotation.value()) { query.append("<").append(iri).append("> ") .append("<").append(RDFS.SUB_PROPERTY_OF).append("> ") .append("<").append(superPropertyIri).append("> . "); } query.append("}"); // Prepare the update query and execute it: try { Update update = getConnection().prepareUpdate(query.toString()); update.execute(); } catch (MalformedQueryException e) { throw new UpdateExecutionException(); } } }
public void asUpdate() throws OpenRDFException { String base = query.getBaseURI(); String sparql = bindMultiples(query.toString()); Update qry = bindSingles(con.prepareUpdate(SPARQL, sparql, base)); qry.execute(); }
connection.prepareUpdate( "INSERT {" + " <" + root.getResourceAsString() + "> ?p ?o ." + ).execute(); connection.prepareUpdate( "INSERT {" + " ?s ?p <" + root.getResourceAsString() + "> ." + connection.prepareUpdate( "DELETE WHERE {" + " <" + clazz.getResourceAsString() +"> ?p ?o ." + "}" ).execute(); connection.prepareUpdate( "DELETE WHERE {" + " ?s ?p <" + clazz.getResourceAsString() +"> ." +
/** * Clears the Anno4j underlying triplestore. * This is required in order to prevent a drop in throughput while parsing. * * @throws RepositoryException Thrown if no connection to the object repository could be made. * @throws UpdateExecutionException Thrown if an error occurred while executing the clearing query. */ private void clear() throws RepositoryException, UpdateExecutionException { String deleteUpdate = "DELETE {?s ?p ?o}\n" + "WHERE {?s ?p ?o}"; ObjectConnection connection = anno4j.getObjectRepository().getConnection(); Update update; try { update = connection.prepareUpdate(deleteUpdate); } catch (MalformedQueryException e) { e.printStackTrace(); return; } update.execute(); }
public void asUpdate() throws OpenRDFException { String base = query.getBaseURI(); String sparql = bindMultiples(query.toString()); Update qry = bindSingles(con.prepareUpdate(SPARQL, sparql, base)); qry.execute(); }
connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> ?p <" + ((ResourceObject) value).getResourceAsString() + "> . " + connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE DATA {" + " <" + getResourceAsString() + "> <" + propertyIri + "> <" + ((ResourceObject) value).getResourceAsString() + "> . " + connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> ?p ?v . " + connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> <" + propertyIri + "> ?v . " +
/** * Complements symmetric properties ({@code owl:SymmetricProperty}) in order to satisfy * symmetry. * @throws RepositoryException Thrown if an error occurs while updating the repository. */ private void sanitizeSymmetry() throws RepositoryException { ObjectConnection connection = getObjectConnection(); try { connection.prepareUpdate(QueryLanguage.SPARQL, "INSERT {" + " ?o ?p <" + getResourceAsString() + "> . " + "} WHERE {\n" + " <" + getResourceAsString() + "> ?p ?o . " + " ?p a owl:SymmetricProperty . " + "}" ).execute(); } catch (MalformedQueryException | UpdateExecutionException e) { throw new RepositoryException(e); } }
/** * Sets the resource as the value of the inverse property for any value of a property of this * resource that has an inverse property. * @throws RepositoryException Thrown if an error occurs while updating the repository. */ private void sanitizeInverseProperties() throws RepositoryException { ObjectConnection connection = getObjectConnection(); try { connection.prepareUpdate(QueryLanguage.SPARQL, "INSERT {" + " ?o ?inverse <" + getResourceAsString() + "> . " + "} WHERE {" + " <" + getResourceAsString() + "> ?p ?o . " + " ?p owl:inverseOf ?inverse . " + "}" ).execute(); } catch (MalformedQueryException | UpdateExecutionException e) { throw new RepositoryException(e); } }
/** * Complements transitive edges for transitive properties ({@code owl:TransitiveProperty}). * @throws RepositoryException Thrown if an error occurs while updating the repository. */ private void sanitizeTransitivity() throws RepositoryException { ObjectConnection connection = getObjectConnection(); try { connection.prepareUpdate(QueryLanguage.SPARQL, "INSERT {" + " <" + getResourceAsString() + "> ?p ?z . " + "} WHERE {" + " <" + getResourceAsString() + "> ?p ?y . " + " ?y ?p ?z . " + " ?p a owl:TransitiveProperty . " + "}" ).execute(); } catch (MalformedQueryException | UpdateExecutionException e) { throw new RepositoryException(e); } }
/** * Complements values of superproperties according to values set for subproperties. * @throws RepositoryException Thrown if an error occurs while updating the repository. */ private void sanitizeSuperProperties() throws RepositoryException { ObjectConnection connection = getObjectConnection(); try { connection.prepareUpdate(QueryLanguage.SPARQL, "INSERT {" + " <" + getResourceAsString() + "> ?super ?o . " + "} WHERE {" + " <" + getResourceAsString() + "> ?p ?o . " + " ?p rdfs:subPropertyOf+ ?super . " + " MINUS {" + " <" + getResourceAsString() + "> ?super ?o2 ." + " {" + " ?o2 owl:sameAs+ ?o . " + " }" + " UNION " + " {" + " ?o owl:sameAs+ ?o2 . " + " }" + " }" + "}" ).execute(); } catch (MalformedQueryException | UpdateExecutionException e) { throw new RepositoryException(e); } }
ObjectConnection connection = getObjectConnection(); try { connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> ?sub ?o . " +
anno4j.getObjectRepository().getConnection().prepareUpdate( "INSERT {" + " ?c a rdfs:Class . " + "}" ).execute(); anno4j.getObjectRepository().getConnection().prepareUpdate( "INSERT {" + " ?p a rdf:Property . " + anno4j.getObjectRepository().getConnection().prepareUpdate( "INSERT {" + " ?p rdfs:domain ?v . " + "}" ).execute(); anno4j.getObjectRepository().getConnection().prepareUpdate( "INSERT {" + " ?p rdfs:range ?v . " + anno4j.getObjectRepository().getConnection().prepareUpdate( "INSERT {" + " ?p ?t ?v . " + anno4j.getObjectRepository().getConnection().prepareUpdate( "INSERT {" + " ?p rdfs:domain owl:Thing . " + anno4j.getObjectRepository().getConnection().prepareUpdate(
Update query = connection.prepareUpdate(QUERY_PREFIX + "INSERT DATA { " + " <" + clazz.getResourceAsString() + "> rdfs:subClassOf <" + restriction.getResourceAsString() + "> ." + "}");