private void doInsert(final RepositoryConnection conn, final int loop, final int index) throws RepositoryException { final ValueFactory vf = conn.getValueFactory(); final URI c = vf.createURI("context:loop:" + loop + ":item:" + index); final URI s = vf.createURI("subject:loop:" + loop + ":item:" + index); for (int x = 0; x < NUM_STATEMENTS_PER_INSERT; ++x) { final URI p = vf.createURI("predicate:" + x); final Literal o = vf.createLiteral("SomeValue"); conn.add(s, p, o, c); } }
private static void addTriple(Resource subject, String predicate, String object, Model model, ValueFactory valueFactory) throws RepositoryException { if (predicate == null || object == null) return; final URI predUri = valueFactory.createURI(predicate); final URI objUri = valueFactory.createURI(object); Statement stmt = valueFactory.createStatement(subject, predUri, objUri); model.add(stmt); }
private final Model getTestModel(String datatypeValue, IRI datatypeURI) { Model result = new LinkedHashModel(); result.add(vf.createStatement(vf.createBNode(), DC.DESCRIPTION, vf.createLiteral(datatypeValue, datatypeURI))); return result; }
public void addStatement( String subject, URI predicate, String literal ) { Literal object = valueFactory.createLiteral( literal ); URI subjectUri = valueFactory.createURI( subject ); Statement statement = valueFactory.createStatement( subjectUri, predicate, object ); graph.add( statement ); }
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); } }
@Test public void testInComparison1() throws Exception { loadTestData("/testdata-query/dataset-ses1913.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT ?y WHERE { :a :p ?y. FILTER(?y in (:c, :d, 1/0 , 1)) } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertTrue(result.hasNext()); BindingSet bs = result.next(); Value y = bs.getValue("y"); assertNotNull(y); assertTrue(y instanceof Literal); assertEquals(f.createLiteral("1", XMLSchema.INTEGER), y); }
protected static void add_sample_triples(Repository rep, ArrayList<URI> contributors, ArrayList<URI> docs, ArrayList<Literal> years) throws OpenRDFException { ValueFactory f = rep.getValueFactory(); // create some resources and literals to make statements out of URI has_contributor_rel = f.createURI(RelConstants.RL_HAS_CONTRIBUTOR); URI year_rel = f.createURI(RelConstants.RL_YEAR); RepositoryConnection con = rep.getConnection(); try { for (int i = 0; i < NUM_OF_TRIPLES; i++) { con.add(docs.get(i), has_contributor_rel, contributors.get(i)); con.add(docs.get(i), year_rel, years.get(i)); } } finally { con.close(); } }
@Test public void testEmptyCommit() throws Exception { assertThat(testCon.isEmpty(), is(equalTo(true))); assertThat(testCon2.isEmpty(), is(equalTo(true))); testCon.begin(); testCon.add(vf.createBNode(), vf.createURI(URN_PRED), vf.createBNode()); assertThat(testCon.isEmpty(), is(equalTo(false))); assertThat(testCon2.isEmpty(), is(equalTo(true))); testCon.commit(); testCon2.close(); testCon2 = testRepository.getConnection(); assertThat(testCon.isEmpty(), is(equalTo(false))); assertThat(testCon2.isEmpty(), is(equalTo(false))); }
@Test public void testQueryBaseURI() throws Exception { testCon.add(vf.createURI(URN_TEST_S1), vf.createURI(URN_TEST_P1), vf.createURI(URN_TEST_O1)); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { <> ?p ?o }", URN_TEST_S1).evaluate(); try { assertThat(rs.hasNext(), is(equalTo(true))); } finally { rs.close(); } }
private void setupNamespaces() throws IOException, RDFParseException, RepositoryException { testCon.setNamespace(EXAMPLE, EXAMPLE_NS); testCon.setNamespace(RDF_PREFIX, "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); testCon.setNamespace(RDFS_PREFIX, RDFS_NS); // Translated from earlier RDF document. Is this line even necessary? testCon.add(vf.createURI(EXAMPLE_NS, "Main"), vf.createURI(RDFS_NS, "label"), vf.createLiteral("Main Node")); }
public void addCompleteWorksheetHistory(KR2RMLMapping mapping, Resource mappingRes) throws RepositoryException { URI hasWorksheetHistoryUri = f.createURI(Uris.KM_HAS_WORKSHEET_HISTORY_URI); Value historyLiteral = f.createLiteral(mapping.getWorksheetHistory().toString(4)); con.add(mappingRes, hasWorksheetHistoryUri, historyLiteral); }
@Test public void testIdenticalVariablesInStatementPattern() throws Exception { conn.add(alice, f.createURI("http://purl.org/dc/elements/1.1/publisher"), bob); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("SELECT ?publisher "); queryBuilder.append("{ ?publisher <http://purl.org/dc/elements/1.1/publisher> ?publisher }"); conn.prepareTupleQuery(QueryLanguage.SPARQL, queryBuilder.toString()).evaluate( new TupleQueryResultHandlerBase() { public void handleSolution(BindingSet bindingSet) { fail("nobody is self published"); } }); }
protected static void create_sample_triples(Repository rep, ArrayList<URI> contributors, ArrayList<URI> docs, ArrayList<Literal> langs) { ValueFactory f = rep.getValueFactory(); for (int i = 1; i <= NUM_OF_TRIPLES; i++) { contributors.add(f.createURI(RelConstants.NS_PERSON + Integer.toString(i))); docs.add(f.createURI(RelConstants.NS_DOCUMENT + Integer.toString(i))); if (i % 2 == 1) langs.add(f.createLiteral("1863")); else langs.add(f.createLiteral("2011")); } }
@Override public URI createURI(final String uri) { return this.repository.getValueFactory().createURI(uri); }
private void addLogicalSource(KR2RMLMapping mapping, Worksheet worksheet, Resource mappingRes, URI trMapUri) throws RepositoryException { // Add the Logical table information BNode logTableBNode = f.createBNode(); con.add(logTableBNode, repoURIs.get(Uris.RR_TABLENAME_URI), f.createLiteral(worksheet.getTitle())); con.add(logTableBNode, RDF.TYPE, repoURIs.get(Uris.RR_LOGICAL_TABLE_CLASS_URI)); con.add(logTableBNode, repoURIs.get(Uris.KM_IS_PART_OF_MAPPING_URI), mappingRes); con.add(mappingRes, repoURIs.get(Uris.KM_HAS_LOGICAL_TABLE_URI), logTableBNode); con.add(trMapUri, repoURIs.get(Uris.RR_LOGICAL_TABLE_URI), logTableBNode); }
@Override public Object execute(Object repository, Map<String, Object> operationParam) { String relationName = (String) operationParam.get("relationName"); Repository repo = (Repository) repository; try { repo.getConnection().remove((Resource)null, repo.getConnection().getValueFactory().createURI(relationName), (Resource)null,(Resource)null); } catch (Exception e) { return e; } return null; }
@Test public void testInferredStatementCount() throws Exception { assertThat(testCon.isEmpty(), is(equalTo(true))); int inferred = getTotalStatementCount(testCon); URI root = vf.createURI("urn:root"); testCon.add(root, RDF.TYPE, RDF.LIST); testCon.remove(root, RDF.TYPE, RDF.LIST); assertThat(testCon.isEmpty(), is(equalTo(true))); assertThat(getTotalStatementCount(testCon), is(equalTo(inferred))); }
@Override protected Statement convert(BindingSet bindingSet) { Resource subject = (Resource)bindingSet.getValue("subject"); IRI predicate = (IRI)bindingSet.getValue("predicate"); Value object = bindingSet.getValue("object"); Resource context = (Resource)bindingSet.getValue("context"); if (context == null) { return vf.createStatement(subject, predicate, object); } else { return vf.createStatement(subject, predicate, object, context); } } };
@Test public void testAddLiteralWithNewline() throws Exception { Literal test = vf.createLiteral("this is a test\n"); testCon.add(bob, RDFS.LABEL, test); assertTrue(NEWLY_ADDED, testCon.hasStatement(bob, RDFS.LABEL, test, false)); }
private void addQueryNode(Model m, Resource implNode, IRI predicate, String queryText) { if (null != queryText) { ValueFactory factory = SimpleValueFactory.getInstance(); BNode queryNode = factory.createBNode(); m.add(implNode, predicate, queryNode); m.add(queryNode, RDF.TYPE, SP.CONSTRUCT_CLASS); m.add(queryNode, SP.TEXT_PROPERTY, factory.createLiteral(queryText)); } } }