org.openrdf.query.MalformedQueryException Java Examples
The following examples show how to use
org.openrdf.query.MalformedQueryException.
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: SPARQLUpdateTestv2.java From database with GNU General Public License v2.0 | 6 votes |
protected long countSolutions(final String query) throws QueryEvaluationException, RepositoryException, MalformedQueryException { TupleQueryResult result = con.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(); try { long n = 0; while (result.hasNext()) { final BindingSet bset = result.next(); n++; if (logger.isInfoEnabled()) logger.info(bset.toString()); } return n; } finally { result.close(); } }
Example #2
Source File: SPARQLQueryTest.java From database with GNU General Public License v2.0 | 6 votes |
protected static String getManifestName(Repository manifestRep, RepositoryConnection con, String manifestFileURL) throws QueryEvaluationException, RepositoryException, MalformedQueryException { // Try to extract suite name from manifest file TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL, "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}"); manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createURI(manifestFileURL)); TupleQueryResult manifestNames = manifestNameQuery.evaluate(); try { if (manifestNames.hasNext()) { return manifestNames.next().getValue("ManifestName").stringValue(); } } finally { manifestNames.close(); } // Derive name from manifest URL int lastSlashIdx = manifestFileURL.lastIndexOf('/'); int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1); return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx); }
Example #3
Source File: BigdataSPARQL2ASTParserTest.java From database with GNU General Public License v2.0 | 6 votes |
/** * projection of ungrouped variable, more complex example than Group-6 */ public void test_group07() throws MalformedQueryException { final String query = "prefix lode: <http://linkedevents.org/ontology/>\n"+ "prefix dc: <http://purl.org/dc/elements/1.1/>\n"+ "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+ "select ?event ?eventName ?venue ?photo\n"+ "where {\n"+ " ?photo lode:illustrate ?event .\n"+ " {\n"+ " select ?event ?eventName ?venue\n"+ " where {\n"+ " ?event dc:title ?eventName .\n"+ " ?event lode:atPlace ?venue .\n"+ " ?venue rdfs:label \"Live Music Hall\" .\n"+ " }\n"+ " }\n"+ "}\n"+ "GROUP BY ?event\n" ; negativeTest(query); }
Example #4
Source File: SPARQLInferenceTest.java From neo4j-sparql-extension with GNU General Public License v3.0 | 6 votes |
@Before public void before() throws RepositoryException, IOException, RDFParseException, MalformedQueryException, QueryResultParseException, QueryResultHandlerException { repo = new SailRepository(new MemoryStore()); repo.initialize(); conn = repo.getConnection(); vf = conn.getValueFactory(); conn.add(getResource(data), "file://", RDFFormat.TURTLE); SPARQLResultsXMLParserFactory factory = new SPARQLResultsXMLParserFactory(); parser = factory.getParser(); parser.setValueFactory(vf); List<Rule> rules; rules = Rules.fromOntology(getResource(data)); QueryRewriter rewriter = new QueryRewriter(conn, rules); query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString); nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); System.out.println("== QUERY (" + this.name + ") =="); System.out.println(nonInfQuery); System.out.println("== REWRITTEN QUERY (" + this.name + ") =="); System.out.println(query); }
Example #5
Source File: ResourceObjectTest.java From anno4j with Apache License 2.0 | 6 votes |
@Test public void testPrefix() throws RepositoryException, IllegalAccessException, InstantiationException, ParseException, MalformedQueryException, QueryEvaluationException { Annotation anno = this.anno4j.createObject(Annotation.class, (Resource) new URIImpl("http://example.org/anno1")); Annotation anno2 = this.anno4j.createObject(Annotation.class, (Resource) new URIImpl("http://xmlns.com/foaf/0.1/anno2")); Annotation anno3 = this.anno4j.createObject(Annotation.class, (Resource) new URIImpl("http://purl.org/dc/terms/anno3")); QueryService qs = this.anno4j.createQueryService(); qs.addPrefix("ex", "http://example.org/"); List<Annotation> result = qs.addCriteria(".", "ex:anno1").execute(Annotation.class); assertEquals(1, result.size()); QueryService qs2 = this.anno4j.createQueryService(); List<Annotation> result2 = qs2.addCriteria(".", "foaf:anno2").execute(Annotation.class); assertEquals(1, result2.size()); QueryService qs3 = this.anno4j.createQueryService(); List<Annotation> result3 = qs3.addCriteria(".", "dcterms:anno3").execute(Annotation.class); assertEquals(1, result3.size()); }
Example #6
Source File: SchemaSanitizingObjectSupport.java From anno4j with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #7
Source File: BuildableRDFSClazzSupport.java From anno4j with Apache License 2.0 | 6 votes |
@Override public Set<RDFSClazz> getDirectSuperclazzes() throws RepositoryException { ObjectConnection connection = getObjectConnection(); try { ObjectQuery query = connection.prepareObjectQuery( "SELECT ?c {" + " <" + getResourceAsString() + "> rdfs:subClassOf ?c . " + " MINUS {" + " <"+ getResourceAsString() + "> rdfs:subClassOf+ ?c2 . " + " ?c2 rdfs:subClassOf+ ?c . " + " FILTER(?c != ?c2 && <" + getResourceAsString() + "> != ?c2)" + " }" + "}" ); return query.evaluate(RDFSClazz.class).asSet(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } }
Example #8
Source File: TestTicket4249.java From database with GNU General Public License v2.0 | 6 votes |
private void executeQuery(final RepositoryConnection conn, final String string, final double start, final double length, final String expected) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, VisitorException { final ValueFactory vf = conn.getValueFactory(); final String query = "select ?substring WHERE { BIND ( SUBSTR(?string, ?start, ?length) as ?substring ) . }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("string", vf.createLiteral(string)); q.setBinding("start", vf.createLiteral(start)); q.setBinding("length", vf.createLiteral(length)); final TupleQueryResult tqr = q.evaluate(); try { while (tqr.hasNext()) { final BindingSet bindings = tqr.next(); // assert expected value assertEquals(expected, bindings.getBinding("substring").getValue().stringValue()); } } finally { tqr.close(); } }
Example #9
Source File: TestNoExceptions.java From database with GNU General Public License v2.0 | 6 votes |
private void executeQuery(final SailRepository repo, final String query) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { final ValueFactory vf = conn.getValueFactory(); conn.commit(); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); TupleQueryResult tqr = tq.evaluate(); tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #10
Source File: ValidatedTransaction.java From anno4j with Apache License 2.0 | 6 votes |
/** * Returns all resources that exist in a specific context. * @param context The context from which to get resources. * @return All resources (IRIs) that are present in {@code context}. * @throws RepositoryException Thrown if an error occurs while querying the repository. */ private Set<ResourceObject> getResourcesFromContext(URI context) throws RepositoryException { try { String q = QUERY_PREFIX + "SELECT ?o " + "FROM NAMED <" + context.toString() + "> " + "{" + " GRAPH <" + context.toString() + "> {" + " { ?o ?p ?x . } UNION { ?x ?p ?o . }" + " FILTER ( isIRI(?o) )" + " }" + "}"; Set<ResourceObject> resources = new HashSet<>(); for (Object current : getConnection().prepareObjectQuery(q).evaluate().asSet()) { if(current instanceof ResourceObject) { resources.add((ResourceObject) current); } } return resources; } catch (QueryEvaluationException | MalformedQueryException e) { throw new RepositoryException(e); } }
Example #11
Source File: SPARQLUpdateConformanceTest.java From database with GNU General Public License v2.0 | 6 votes |
protected static String getManifestName(Repository manifestRep, RepositoryConnection con, String manifestFileURL) throws QueryEvaluationException, RepositoryException, MalformedQueryException { // Try to extract suite name from manifest file TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL, "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}"); manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createURI(manifestFileURL)); TupleQueryResult manifestNames = manifestNameQuery.evaluate(); try { if (manifestNames.hasNext()) { return manifestNames.next().getValue("ManifestName").stringValue(); } } finally { manifestNames.close(); } // Derive name from manifest URL int lastSlashIdx = manifestFileURL.lastIndexOf('/'); int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1); return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx); }
Example #12
Source File: AnnotationTest.java From anno4j with Apache License 2.0 | 6 votes |
@Test public void testSingleTarget() throws RepositoryException, InstantiationException, IllegalAccessException, UpdateExecutionException, MalformedQueryException { // Create annotation Annotation annotation = anno4j.createObject(Annotation.class); // Create specific resource SpecificResource specificResource = anno4j.createObject(SpecificResource.class); ResourceObject resourceObject = anno4j.createObject(ResourceObject.class); resourceObject.setResourceAsString("http://www.somepage.org/resource1/"); specificResource.setSource(resourceObject); annotation.addTarget(specificResource); // Query annotation Annotation result = anno4j.findByID(Annotation.class, annotation.getResourceAsString()); // Tests assertEquals(1, result.getTargets().size()); assertEquals(("http://www.somepage.org/resource1/"), ((SpecificResource) result.getTargets().toArray()[0]).getSource().getResource().toString()); }
Example #13
Source File: TestTicket1755.java From database with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") private void testQuery(final BigdataSailRepositoryConnection conn, final String query, final int expectedIVs) throws MalformedQueryException, RepositoryException, QueryEvaluationException { TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); TupleQueryResult tqr = tq.evaluate(); try { int cnt = 0; while (tqr.hasNext()) { tqr.next(); cnt++; } // assertEquals("Expected 1 row in resultset", 1, cnt); QueryRoot queryRoot = ((BigdataSailTupleQuery)tq).getASTContainer().getOriginalAST(); cnt = 0; for (Object filterNode: queryRoot.getWhereClause().getChildren(FilterNode.class)) { cnt += checkNode((BOp)filterNode); } assertEquals("Expected inlined IV for date literal", expectedIVs, cnt); } finally { tqr.close(); } }
Example #14
Source File: TestRollbacks.java From database with GNU General Public License v2.0 | 6 votes |
private void reader(final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, InterruptedException { query(conn); // Thread.sleep(100); query(conn); ++counter; if (counter % 3 == 0) conn.commit(); else conn.rollback(); // if (counter % 7 == 0) { // conn.close(); // conn = repo.getConnection(); // conn.setAutoCommit(false); // } }
Example #15
Source File: TestValueExprBuilder.java From database with GNU General Public License v2.0 | 6 votes |
/** * Simple unit test for a value expression which is a URI. */ public void test_select_uri() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ( <http://xmlns.com/foaf/0.1/> as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createURI("http://xmlns.com/foaf/0.1/"))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }
Example #16
Source File: BigdataSailRemoteRepositoryConnection.java From database with GNU General Public License v2.0 | 5 votes |
@Override public Update prepareUpdate(final QueryLanguage ql, final String query, final String baseURI) throws RepositoryException, MalformedQueryException { if (baseURI != null) throw new UnsupportedOperationException("baseURI not supported"); return prepareUpdate(ql, query); }
Example #17
Source File: BigdataSPARQLUpdateTest2.java From database with GNU General Public License v2.0 | 5 votes |
/** * A test which verifies that an exception is NOT thrown if * the named solution set does not exist and SILENT is specified. */ public void test_dropSolutionSet_02() throws UpdateExecutionException, RepositoryException, MalformedQueryException { if (!isSolutionSetUpdateEnabled()) { /* * Test requires this feature. */ return; } con.prepareUpdate(QueryLanguage.SPARQL, "drop silent solutions %namedSet1").execute(); }
Example #18
Source File: TestGroupGraphPatternBuilder.java From database with GNU General Public License v2.0 | 5 votes |
/** * Test for a named graph triple pattern where the graph is a constant. * <pre> * select ?s where {GRAPH <http://www.bigdata.com> {?s ?p ?o}} * </pre> */ public void test_named_graph_pattern_graphConstant() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ?s where {GRAPH <http://www.bigdata.com> {?s ?p ?o}}"; final IV<BigdataValue, ?> graphConst = makeIV(valueFactory .createURI("http://www.bigdata.com")); final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("s")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); final JoinGroupNode graphGroup = new JoinGroupNode(); graphGroup.setContext(new ConstantNode(graphConst)); graphGroup.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), new ConstantNode( graphConst), Scope.NAMED_CONTEXTS)); whereClause.addChild(graphGroup); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
Example #19
Source File: PathTest.java From anno4j with Apache License 2.0 | 5 votes |
@Test public void falseTest() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException { List<Annotation> annotations = queryService .addCriteria("oa:hasBody/ex:value", "Value3") .execute(); assertEquals(0, annotations.size()); }
Example #20
Source File: ValidatedTransaction.java From anno4j with Apache License 2.0 | 5 votes |
/** * Checks for every properties that is in a <code>rdfs:subPropertyOf</code> relation, whether its value set is actually * a subset of all superproperties value sets. * @param anchors A set of resources which properties will be checked. * @throws RepositoryException Thrown if an error occurs querying the connected triplestore. * @throws ValidationFailedException Thrown if any of the checked properties violates the above condition. */ private void validateSubPropertyOf(Collection<ResourceObject> anchors) throws RepositoryException, ValidationFailedException { String q = QUERY_PREFIX + "SELECT ?p1 ?p2 ?o ?i " + "{" + buildValuesClause(anchors, "i") + " " + " ?i ?p1 ?o ." + " ?p1 rdfs:subPropertyOf+ ?p2 ." + " " + " MINUS {" + " ?i ?p2 ?o ." + " }" + " " + "} LIMIT 1"; Set<?> result; try { ObjectQuery query = getConnection().prepareObjectQuery(q); result = query.evaluate().asSet(); } catch (MalformedQueryException | RepositoryException | QueryEvaluationException e) { throw new RepositoryException(e); } if(result.size() > 0) { Object[] row = (Object[]) result.iterator().next(); String subPropertyIri = row[0].toString(); String superPropertyIri = row[1].toString(); Object value = row[2]; String objectIri = row[3].toString(); throw new ValidationFailedException("Superproperty " + superPropertyIri + " of " + subPropertyIri + " is missing value " + value + " (resource: " + objectIri + ")", this); } }
Example #21
Source File: LanguageTest.java From anno4j with Apache License 2.0 | 5 votes |
@Test /** * Querying for annotations, containing bodies with german lang values. */ public void testSecondBody() throws RepositoryException, QueryEvaluationException, MalformedQueryException, ParseException { List<Annotation> list = queryService .addCriteria("oa:hasBody/ex:languageValue[@de]") .execute(); assertEquals(1, list.size()); LangTestBody testBody = (LangTestBody) list.get(0).getBodies().iterator().next(); assertEquals("de", testBody.getLangString().getLang()); assertEquals("Zweiter Wert", testBody.getLangString().toString()); }
Example #22
Source File: TestTicket353.java From database with GNU General Public License v2.0 | 5 votes |
private void executeQuery(final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { final ValueFactory vf = conn.getValueFactory(); conn.add(vf.createURI("os:subject"), vf.createURI("os:prop"), vf.createLiteral("value")); conn.commit(); String query = "SELECT ?b { {} union { ?a ?b ?c } }" ; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); TupleQueryResult tqr = tq.evaluate(); assertTrue(tqr.hasNext()); while (tqr.hasNext()) { System.err.println(tqr.next()); } tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #23
Source File: TestStaticAnalysis.java From database with GNU General Public License v2.0 | 5 votes |
/** * Unit test of static analysis for variables which must be bound by a * query. This involves checking the WHERE clause and the projection for the * query. * * @throws MalformedQueryException */ public void test_static_analysis01() throws MalformedQueryException { final String queryStr = "" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"+ "select ?x where { ?x rdf:type foaf:Person }"; final QueryRoot queryRoot = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI).getOriginalAST(); final StaticAnalysis sa = new StaticAnalysis(queryRoot); final Set<IVariable<?>> expected = new LinkedHashSet<IVariable<?>>(); expected.add(Var.var("x")); assertEquals(expected, sa.getDefinitelyProducedBindings(queryRoot)); assertEquals( expected, sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */)); }
Example #24
Source File: BigdataSailRemoteRepositoryConnection.java From database with GNU General Public License v2.0 | 5 votes |
@Override public GraphQuery prepareGraphQuery(final QueryLanguage ql, final String query) throws RepositoryException, MalformedQueryException { return prepareGraphQuery(ql, query, null); }
Example #25
Source File: TestGroupGraphPatternBuilder.java From database with GNU General Public License v2.0 | 5 votes |
/** * Unit test for two groups, each consisting of one triple pattern. * * <pre> * select ?s where { {?s ?p ?o} . {?o ?p2 ?s}} * </pre> */ public void test_two_simple_join_groups() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ?s where { { ?s ?p ?o } . { ?o ?p2 ?s } }"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("s")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); expected.setWhereClause(whereClause); final JoinGroupNode group1 = new JoinGroupNode(); final JoinGroupNode group2 = new JoinGroupNode(); whereClause.addChild(group1); whereClause.addChild(group2); group1.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); group2.addChild(new StatementPatternNode(new VarNode("o"), new VarNode("p2"), new VarNode("s"), null/* c */, Scope.DEFAULT_CONTEXTS)); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
Example #26
Source File: BigdataSPARQLUpdateTest2.java From database with GNU General Public License v2.0 | 5 votes |
/** * Unit test of CREATE SILENT SOLUTIONS verifies that an error is reported * if SILENT is not specified and the solution set exists and that the error * is suppressed if the SILENT keyword is given. */ public void test_createSolutionSet_02() throws UpdateExecutionException, RepositoryException, MalformedQueryException { if (!isSolutionSetUpdateEnabled()) { /* * Test requires this feature. */ return; } // Should succeed. con.prepareUpdate(QueryLanguage.SPARQL, "create solutions %namedSet1") .execute(); // Should fail. try { con.prepareUpdate(QueryLanguage.SPARQL, "create solutions %namedSet1").execute(); fail("Excepting: " + UpdateExecutionException.class); } catch (UpdateExecutionException ex) { if (log.isInfoEnabled()) log.info("Ignoring expected exception: " + ex); } // Should succeed since SILENT. con.prepareUpdate(QueryLanguage.SPARQL, "create silent solutions %namedSet1").execute(); }
Example #27
Source File: BigdataSailRemoteRepositoryConnection.java From database with GNU General Public License v2.0 | 5 votes |
@Override public Query prepareQuery(final QueryLanguage ql, final String query, final String baseURI) throws RepositoryException, MalformedQueryException { return prepareQuery(ql, query); }
Example #28
Source File: OWLSchemaPersistingManager.java From anno4j with Apache License 2.0 | 5 votes |
/** * Persists the information that a property is the inverse of another property to the default graph of the connected triplestore. * All properties with {@link InverseOf} 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 persistInverseOf(Collection<AccessibleObject> annotatedObjects) throws RepositoryException, UpdateExecutionException { // Get those methods and fields that have the @InverseOf annotation: Collection<AccessibleObject> inverseOfObjects = filterObjectsWithAnnotation(annotatedObjects, InverseOf.class); for (AccessibleObject object : inverseOfObjects) { String iri = getIriFromObject(object); InverseOf inverseOfAnnotation = object.getAnnotation(InverseOf.class); StringBuilder query = new StringBuilder(QUERY_PREFIX) .append(" INSERT DATA { "); for (String inversePropertyIri : inverseOfAnnotation.value()) { query.append("<").append(iri).append("> owl:inverseOf ") .append("<").append(inversePropertyIri).append("> . ") .append("<").append(inversePropertyIri).append("> owl:inverseOf ") .append("<").append(iri).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(); } } }
Example #29
Source File: AnnotationTest.java From anno4j with Apache License 2.0 | 5 votes |
@Test public void testStyle() throws RepositoryException, IllegalAccessException, InstantiationException, ParseException, MalformedQueryException, QueryEvaluationException { Annotation annotation = this.anno4j.createObject(Annotation.class); CssStylesheet sheet = this.anno4j.createObject(CssStylesheet.class); annotation.setStyledBy(sheet); QueryService qs = this.anno4j.createQueryService(); qs.addCriteria("oa:styledBy[is-a oa:CssStyle]"); List<Annotation> result = qs.execute(Annotation.class); assertEquals(1, result.size()); }
Example #30
Source File: OWLSchemaPersistingManager.java From anno4j with Apache License 2.0 | 5 votes |
/** * Persists the information that a property is symmetric to the default graph of the connected triplestore. * All properties with {@link com.github.anno4j.annotations.Symmetric} 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 persistSymmetric(Collection<AccessibleObject> annotatedObjects) throws RepositoryException, UpdateExecutionException { // Get those methods and fields that have the @Symmetric annotation: Collection<AccessibleObject> symmetricObjects = filterObjectsWithAnnotation(annotatedObjects, Symmetric.class); // Prepare the update query and execute it: try { Update update = buildInstanceUpdate(getIrisFromObjects(symmetricObjects), OWL.SYMMETRIC_PROPERTY); update.execute(); } catch (MalformedQueryException e) { throw new UpdateExecutionException(); } }