org.openrdf.repository.sail.SailRepository Java Examples
The following examples show how to use
org.openrdf.repository.sail.SailRepository.
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: 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 #2
Source File: InterfaceTypeSpecTest.java From anno4j with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { generationConfig = new OntGenerationConfig(); List<String> identifierLangPreference = Arrays.asList("en", "de", OntGenerationConfig.UNTYPED_LITERAL); List<String> javaDocLangPreference = Arrays.asList("de", "en", OntGenerationConfig.UNTYPED_LITERAL); generationConfig.setIdentifierLanguagePreference(identifierLangPreference); generationConfig.setJavaDocLanguagePreference(javaDocLangPreference); // Prevent persisting of schema information from other tests (would be rooted to ex:Vehicle): Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), new IDGeneratorAnno4jURN(), null, false); modelBuilder = new OWLJavaFileGenerator(anno4j); // Create a RDFS model builder instance: VehicleOntologyLoader.addVehicleOntology(modelBuilder); // Build the ontology model: modelBuilder.build(); }
Example #3
Source File: SPARQLQuery.java From neo4j-sparql-extension with GNU General Public License v3.0 | 6 votes |
/** * Create a new SPARQL 1.1 query resource based on a repository. * * @param rep the repository this resources operates on */ public SPARQLQuery(SailRepository rep) { super(rep); // initialize additional result MIME-Types queryResultVariants = Variant.mediaTypes( MediaType.valueOf(RDFMediaType.SPARQL_RESULTS_JSON), MediaType.valueOf(RDFMediaType.SPARQL_RESULTS_XML), MediaType.valueOf(RDFMediaType.SPARQL_RESULTS_CSV), MediaType.valueOf(RDFMediaType.SPARQL_RESULTS_TSV) ).add().build(); booleanResultVariants = Variant.mediaTypes( MediaType.valueOf(RDFMediaType.SPARQL_RESULTS_JSON), MediaType.valueOf(RDFMediaType.SPARQL_RESULTS_XML), MediaType.valueOf(MediaType.TEXT_PLAIN) ).add().build(); // get reference to query rewriting component this.qwfactory = QueryRewriterFactory.getInstance(rep); // get query timeout from properties String sout = SPARQLExtensionProps.getProperty("query.timeout"); this.timeout = Integer.parseInt(sout); }
Example #4
Source File: RepositoryConnectionTest.java From database with GNU General Public License v2.0 | 6 votes |
@Test public void testAddStatement() throws Exception { testCon.add(bob, name, nameBob); assertTrue(NEWLY_ADDED, testCon.hasStatement(bob, name, nameBob, false)); Statement statement = vf.createStatement(alice, name, nameAlice); testCon.add(statement); assertTrue(NEWLY_ADDED, testCon.hasStatement(statement, false)); assertTrue(NEWLY_ADDED, testCon.hasStatement(alice, name, nameAlice, false)); Repository tempRep = new SailRepository(new MemoryStore()); tempRep.initialize(); RepositoryConnection con = tempRep.getConnection(); con.add(testCon.getStatements(null, null, null, false)); assertTrue("Temp Repository should contain newly added statement", con.hasStatement(bob, name, nameBob, false)); con.close(); tempRep.shutDown(); }
Example #5
Source File: ConceptQueryTest.java From anno4j with Apache License 2.0 | 6 votes |
@Test public void testGetConcepts() throws Exception { // Create an Anno4j object and load the ontology information: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); InputStream is = new ByteArrayInputStream(ONTOLOGY_RDFS_TURTLE.getBytes("UTF-8")); anno4j.getRepository().getConnection().add(is, "http://example.org/v2/", RDFFormat.TURTLE); // Test resources are mapped to their correct concepts: assertEquals(Sets.<Class<?>>newHashSet(Cabrio.class), anno4j.getConcepts("http://example.org/v2/r8spyder")); assertEquals(Sets.<Class<?>>newHashSet(Car.class), anno4j.getConcepts("http://example.org/v2/golf")); assertEquals(Sets.<Class<?>>newHashSet(Camper.class), anno4j.getConcepts("http://example.org/v2/vario")); // Resources with unknown type are mapped to ResourceObject: assertEquals(Sets.<Class<?>>newHashSet(ResourceObject.class), anno4j.getConcepts("http://example.org/v2/318i")); // Test resource with multiple specific types: assertEquals(Sets.<Class<?>>newHashSet(Car.class, Truck.class), anno4j.getConcepts("http://example.org/v2/t5")); }
Example #6
Source File: ConceptQueryTest.java From anno4j with Apache License 2.0 | 6 votes |
@Test public void testGetConcept() throws Exception { // Create an Anno4j object and load the ontology information: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); InputStream is = new ByteArrayInputStream(ONTOLOGY_RDFS_TURTLE.getBytes("UTF-8")); anno4j.getRepository().getConnection().add(is, "http://example.org/v2/", RDFFormat.TURTLE); // Test resources are mapped to their correct concepts: assertEquals(Cabrio.class, anno4j.getConcept("http://example.org/v2/r8spyder")); assertEquals(Car.class, anno4j.getConcept("http://example.org/v2/golf")); assertEquals(Camper.class, anno4j.getConcept("http://example.org/v2/vario")); // Resources with unknown type are mapped to ResourceObject: assertEquals(ResourceObject.class, anno4j.getConcept("http://example.org/v2/318i")); // Resources with multiple types are mapped to any of them: Class<? extends ResourceObject> t5Concept = anno4j.getConcept("http://example.org/v2/t5"); assertTrue(t5Concept.equals(Car.class) || t5Concept.equals(Truck.class)); }
Example #7
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 #8
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests propagation of updates across different objects for the same resource. */ @Test public void testUpgradePropagation() throws Exception { // Create an Anno4j instance and get its object connection: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); ObjectConnection connection = anno4j.getObjectRepository().getConnection(); // Get two objects for the same resource: Annotation a = anno4j.createObject(Annotation.class, (Resource) new URIImpl("urn:anno4j_test:a1")); Annotation b = anno4j.findByID(Annotation.class, "urn:anno4j_test:a1"); // Test that both objects have the same values after setting at one: a.setBodyTexts(Sets.newHashSet("a")); assertEquals(Sets.newHashSet("a"), a.getBodyTexts()); assertEquals(Sets.newHashSet("a"), b.getBodyTexts()); // Refresh objects: connection.refresh(a); connection.refresh(b); // Test other way round (after values have been cached): b.setBodyTexts(Sets.newHashSet("a", "b")); assertEquals(Sets.newHashSet("a", "b"), new HashSet<>(a.getBodyTexts())); assertEquals(Sets.newHashSet("a", "b"), new HashSet<>(b.getBodyTexts())); }
Example #9
Source File: ProxyCompileTool.java From anno4j with Apache License 2.0 | 6 votes |
/** * Creates an Anno4j instance that can use the concepts contained in the given JAR file. * @param ontologyJar A JAR file containing concepts. * @param classLoader The class loader to use. * @param persistSchemaAnnotations Whether schema annotations should be scanned. * @return Returns an Anno4j instance. * @throws Exception Thrown on error. */ private static Anno4j getAnno4jWithClassLoader(File ontologyJar, ClassLoader classLoader, boolean persistSchemaAnnotations) throws Exception { Set<URL> clazzes = new HashSet<>(); clazzes.addAll(ClasspathHelper.forManifest(ontologyJar.toURI().toURL())); Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), new IDGeneratorAnno4jURN(), null, persistSchemaAnnotations, clazzes); // Register concepts found in JAR: RoleMapper mapper = anno4j.getObjectRepository().getConnection().getObjectFactory().getResolver().getRoleMapper(); for (final String className : getClassNamesInJar(ontologyJar)) { Class<?> clazz = classLoader.loadClass(className); if(clazz.getAnnotation(Iri.class) != null) { mapper.addConcept(clazz); } } return anno4j; }
Example #10
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests retrieving resources with a more general type than specified in the repository. */ @Test public void testReadGeneralType() throws Exception { // Create an Anno4j instance and get its repository connection for direct triple access: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); RepositoryConnection repoConnection = anno4j.getRepository().getConnection(); // Add some triples to the repository: repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:p1"), new URIImpl(RDF.TYPE), new URIImpl(FOAF.PERSON))); ResourceObject p = anno4j.findByID(Person.class, "urn:anno4j_test:p1"); assertNotNull(p); p = anno4j.findByID(Agent.class, "urn:anno4j_test:p1"); assertNotNull(p); p = anno4j.findByID(ResourceObject.class, "urn:anno4j_test:p1"); assertNotNull(p); }
Example #11
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests reading of resources that do not have a type assigned in the repository. */ @Test public void testReadNoType() throws Exception { // Create an Anno4j instance and get its repository connection for direct triple access: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); RepositoryConnection repoConnection = anno4j.getRepository().getConnection(); // Resource urn:anno4j_test:p1 is present but does not have a rdf:type repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:p1"), new URIImpl(FOAF.MBOX), new LiteralImpl("[email protected]"))); // Try retrieving the resource with a specific type: Person p = anno4j.findByID(Person.class, "urn:anno4j_test:p1"); assertNull(p); }
Example #12
Source File: TestTicket632.java From database with GNU General Public License v2.0 | 6 votes |
private void executeQuery(final URI serviceUri, final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); final ValueFactory vf = conn.getValueFactory(); conn.setAutoCommit(false); try { final String query = "SELECT ?x { SERVICE <" + serviceUri.stringValue() + "> { ?x <u:1> ?bool1 } }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("bool1", vf.createLiteral(true)); final TupleQueryResult tqr = q.evaluate(); try { tqr.hasNext(); } finally { tqr.close(); } } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #13
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests reading objects and their property values from the repository. */ @Test public void testRead() throws Exception { // Create an Anno4j instance and get its repository connection for direct triple access: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); RepositoryConnection repoConnection = anno4j.getRepository().getConnection(); // Add some triples to the repository: repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:p1"), new URIImpl(RDF.TYPE), new URIImpl(FOAF.PERSON))); repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:p1"), new URIImpl(FOAF.MBOX), new LiteralImpl("[email protected]"))); Person p = anno4j.findByID(Person.class, "urn:anno4j_test:p1"); assertNotNull(p); assertEquals("[email protected]", p.getMbox()); }
Example #14
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests re-creation of already created objects in a different context. */ @Test public void testCreateExistingOtherContext() throws Exception { // Create an Anno4j instance and get its object connection: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); ObjectConnection connection = anno4j.getObjectRepository().getConnection(); // Create an object: Person a = anno4j.createObject(Person.class, (Resource) new URIImpl("urn:anno4j_test:p1")); a.setMbox("[email protected]"); // Create another object with the same IRI: Person b = anno4j.createObject(Person.class, new URIImpl("urn:anno4j_test:context1"), new URIImpl("urn:anno4j_test:p1")); // The new object should NOT have a value for the property foaf:mbox: assertNull(b.getMbox()); // The objects should be comparable (because the resource identified by an IRI is always the same): assertTrue(a.equals(b) && b.equals(a)); // Modification done to the second object should NOT persist to the first (after refreshing): b.setMbox("[email protected]"); connection.refresh(a); assertEquals("[email protected]", a.getMbox()); }
Example #15
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests re-creation of already created objects in the same context. */ @Test public void testCreateExisting() throws Exception { // Create an Anno4j instance and get its object connection: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); ObjectConnection connection = anno4j.getObjectRepository().getConnection(); // Create an object: Person a = anno4j.createObject(Person.class, (Resource) new URIImpl("urn:anno4j_test:p1")); a.setMbox("[email protected]"); // Create another object with the same IRI: Person b = anno4j.createObject(Person.class, (Resource) new URIImpl("urn:anno4j_test:p1")); // The new object should have the same value for the property foaf:mbox: assertEquals("[email protected]", b.getMbox()); // The objects should be comparable: assertTrue(a.equals(b) && b.equals(a)); // Modification done to the second object should persist to the first (after refreshing): b.setMbox("[email protected]"); connection.refresh(a); assertEquals("[email protected]", a.getMbox()); }
Example #16
Source File: CRUDTest.java From anno4j with Apache License 2.0 | 6 votes |
/** * Tests basic object creation and persistence of triples. */ @Test public void testCreate() throws Exception { // Create an Anno4j instance and get its repository connection for direct triple access: Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false); RepositoryConnection repoConnection = anno4j.getRepository().getConnection(); // Test simple object creation: Person p = anno4j.createObject(Person.class, (Resource) new URIImpl("urn:anno4j_test:p1")); p.setMbox("[email protected]"); // Two statments (rdf:type, foaf:mbox) should be created: Collection<Statement> statements = getStatements(repoConnection); assertEquals(2, statements.size()); assertTrue(statements.contains(new StatementImpl(new URIImpl("urn:anno4j_test:p1"), new URIImpl(RDF.TYPE), new URIImpl(FOAF.PERSON)))); assertTrue(statements.contains(new StatementImpl(new URIImpl("urn:anno4j_test:p1"), new URIImpl(FOAF.MBOX), new LiteralImpl("[email protected]")))); }
Example #17
Source File: BigdataSparqlTest.java From database with GNU General Public License v2.0 | 6 votes |
@Override protected Repository newRepository() throws RepositoryException { if (true) { final Properties props = getProperties(); if (cannotInlineTests.contains(testURI)){ // The test can not be run using XSD inlining. props.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false"); props.setProperty(Options.INLINE_DATE_TIMES, "false"); } if(unicodeStrengthIdentical.contains(testURI)) { // Force identical Unicode comparisons. props.setProperty(Options.COLLATOR, CollatorEnum.JDK.toString()); props.setProperty(Options.STRENGTH, StrengthEnum.Identical.toString()); } final BigdataSail sail = new BigdataSail(props); // return new DatasetRepository(new BigdataSailRepository(sail)); return new BigdataSailRepository(sail); } else { return new DatasetRepository(new SailRepository(new MemoryStore())); } }
Example #18
Source File: TestRollbacks.java From database with GNU General Public License v2.0 | 6 votes |
private void runConcurrentStuff(final SailRepository repo,final int maxCounter) throws Exception, InterruptedException { try { final List<Callable<Void>> tasks = new LinkedList<Callable<Void>>(); tasks.add(new DoStuff(repo, true/*writer*/, maxCounter)); tasks.add(new DoStuff(repo, false/*reader*/, maxCounter)); tasks.add(new DoStuff(repo, false/*reader*/, maxCounter)); final List<Future<Void>> futures = executorService.invokeAll(tasks); // Look for the first cause. final Throwable t = firstCause.get(); if (t != null) { // Found it. throw new RuntimeException(t); } // test each future. for (Future<Void> f : futures) { f.get(); } } finally { repo.shutDown(); } }
Example #19
Source File: TestTicket276.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(); addData(conn); conn.commit(); final String query = "SELECT ?x { ?x ?a ?t . ?x ?lookup ?l }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding( "a", vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")); q.setBinding("t", vf.createURI("os:class/Location")); q.setBinding("lookup", vf.createURI("os:prop/lookupName")); q.setBinding("l", vf.createLiteral("amsterdam")); final TupleQueryResult tqr = q.evaluate(); while (tqr.hasNext()) { final Set<String> bindingNames = tqr.next() .getBindingNames(); if (log.isInfoEnabled()) log.info("bindingNames=" + bindingNames); } tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #20
Source File: BigdataArbitraryLengthPathTest.java From database with GNU General Public License v2.0 | 5 votes |
protected SailRepository newRepository() throws RepositoryException { if (true) { final Properties props = getProperties(); // if (cannotInlineTests.contains(testURI)){ // // The test can not be run using XSD inlining. // props.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false"); // props.setProperty(Options.INLINE_DATE_TIMES, "false"); // } // // if(unicodeStrengthIdentical.contains(testURI)) { // // Force identical Unicode comparisons. // props.setProperty(Options.COLLATOR, CollatorEnum.JDK.toString()); // props.setProperty(Options.STRENGTH, StrengthEnum.Identical.toString()); // } final BigdataSail sail = new BigdataSail(props); return new BigdataSailRepository(sail); } else { /* * Run against openrdf. */ SailRepository repo = new SailRepository(new MemoryStore()); return repo; } }
Example #21
Source File: TestTicket355.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 ?subj WHERE { " + "?subj <os:prop> ?val . " + "FILTER(STR(?val) != ?arg)}"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); tq.setBinding("arg", vf.createLiteral("notValue")); TupleQueryResult tqr = tq.evaluate(); assertTrue(tqr.hasNext()); tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #22
Source File: TestTicket355.java From database with GNU General Public License v2.0 | 5 votes |
public void testBug() throws Exception { // try with Sesame MemoryStore: executeQuery(new SailRepository(new MemoryStore())); // try with Bigdata: final BigdataSail sail = getSail(); try { executeQuery(new BigdataSailRepository(sail)); } finally { sail.__tearDownUnitTest(); } }
Example #23
Source File: IntegrationTestSupertypeLayer.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Setup fixture for this test. */ @BeforeClass public static void init() throws Exception { inMemoryRepository = new SailRepository(new MemoryStore()); cumulusRepository = new SailRepository(new CumulusRDFSail(new TripleStore())); inMemoryRepository.initialize(); cumulusRepository.initialize(); localConnection = inMemoryRepository.getConnection(); cumulusConnection = cumulusRepository.getConnection(); }
Example #24
Source File: TestTicket1681.java From database with GNU General Public License v2.0 | 5 votes |
private void executeQuery(final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { conn.add(getClass().getResourceAsStream("TestTicket1681.nt"), "", RDFFormat.TURTLE); conn.commit(); final String query = "SELECT * WHERE { ?s <http://p> ?o . FILTER (?o IN (<http://o2>, <http://o3>) ) }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); final TupleQueryResult tqr = q.evaluate(); int cnt = 0; while (tqr.hasNext()) { final Set<String> bindingNames = tqr.next().getBindingNames(); cnt++; if(log.isInfoEnabled()) log.info("bindingNames="+bindingNames); } tqr.close(); assertEquals(1, cnt); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #25
Source File: TestTicket275.java From database with GNU General Public License v2.0 | 5 votes |
public void testBug() throws Exception { // try with Sesame MemoryStore: executeQuery(new SailRepository(new MemoryStore())); final BigdataSail sail = getSail(); try { executeQuery(new BigdataSailRepository(sail)); } finally { sail.__tearDownUnitTest(); } }
Example #26
Source File: TestTicket275.java From database with GNU General Public License v2.0 | 5 votes |
private void executeQuery(final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); conn.setAutoCommit(false); try { conn.add(getClass().getResourceAsStream("TestTicket275.ttl"), "", RDFFormat.TURTLE); conn.commit(); final String query = "SELECT ?lookup WHERE { ?lookup <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <os:class/Lookup> . ?lookup <os:prop/lookup/majorType> ?majorType . OPTIONAL{?lookup <os:prop/lookup/minorType> ?minorType}. FILTER(STR(?majorType) = ?argMajorType). FILTER(!bound(?minorType))}"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("argMajorType", conn.getValueFactory() .createLiteral("majoor")); final TupleQueryResult tqr = q.evaluate(); while (tqr.hasNext()) { final Set<String> bindingNames = tqr.next().getBindingNames(); if(log.isInfoEnabled()) log.info("bindingNames="+bindingNames); } tqr.close(); } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #27
Source File: RepositoryRegistry.java From neo4j-sparql-extension with GNU General Public License v3.0 | 5 votes |
/** * Initializes Sesame repository for Neo4j based on Blueprints * implementation. * * @param database Neo4j database service * @throws RepositoryException if there was a problem initializing the * Sesame repository */ private RepositoryRegistry(GraphDatabaseService database) throws RepositoryException { initRio(); Graph graph = new Neo4j2Graph(database); String patterns = SPARQLExtensionProps.getProperty("query.patterns"); Sail sail = new GraphSail((KeyIndexableGraph) graph, patterns); this.rep = new SailRepository(sail); rep.initialize(); }
Example #28
Source File: TestTicket348.java From database with GNU General Public License v2.0 | 5 votes |
private void executeTest(final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, RDFHandlerException, IOException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); try { conn.setAutoCommit(false); final ValueFactory vf = conn.getValueFactory(); final URI uri = vf.createURI("os:/elem/example"); // run a query which looks for a statement and then adds it if it is not found. addDuringQueryExec(conn, uri, RDF.TYPE, vf.createURI("os:class/Clazz")); // now try to export the statements. final RepositoryResult<Statement> stats = conn.getStatements(null, null, null, false); try { // materialize the newly added statement. stats.next(); } catch (RuntimeException e) { fail(e.getLocalizedMessage(), e); // With Bigdata this fails } finally { stats.close(); } conn.rollback(); // discard the result (or commit, but do something to avoid a logged warning from Sesame). } finally { conn.close(); } } finally { repo.shutDown(); } }
Example #29
Source File: AbstractSailResource.java From neo4j-sparql-extension with GNU General Public License v3.0 | 5 votes |
/** * Initialize result variants and save reference to repository. * @param rep reference to repository */ public AbstractSailResource(SailRepository rep) { this.rep = rep; rdfResultVariants = Variant.mediaTypes( MediaType.valueOf(RDFMediaType.RDF_TURTLE), MediaType.valueOf(RDFMediaType.RDF_NTRIPLES), MediaType.valueOf(RDFMediaType.RDF_XML), MediaType.valueOf(RDFMediaType.RDF_JSON) ).add().build(); }
Example #30
Source File: MergeTest.java From anno4j with Apache License 2.0 | 5 votes |
public void testMergeBlankNodeFromOtherRepository() throws Exception { SailRepository repo = new SailRepository(new MemoryStore()); repo.initialize(); ObjectRepositoryFactory orf = new ObjectRepositoryFactory(); ObjectRepository or = orf.createRepository(config, repo); ObjectConnection oc = or.getConnection(); ValueFactory vf = oc.getValueFactory(); Node n1 = oc.addDesignation(oc.getObject(vf.createBNode()), Node.class); Node n2 = oc.addDesignation(oc.getObject(vf.createBNode()), Node.class); n1.setSibling(n2); n2.setSibling(n1); Node m1 = (Node) con.getObject(con.addObject(n1)); assertNotNull(m1.getSibling()); }