Search in sources :

Example 1 with Repository

use of org.openrdf.repository.Repository in project incubator-rya by apache.

the class RyaAccumuloSailFactoryTest method testCreateFromTemplateName.

@Test
public void testCreateFromTemplateName() throws Exception {
    LocalRepositoryManager repoman = new LocalRepositoryManager(Files.createTempDir());
    repoman.initialize();
    try (InputStream templateStream = RepositoryConfig.class.getResourceAsStream("RyaAccumuloSail.ttl")) {
        String template = IOUtils.toString(templateStream);
        final ConfigTemplate configTemplate = new ConfigTemplate(template);
        final Map<String, String> valueMap = ImmutableMap.<String, String>builder().put("Repository ID", "RyaAccumuloSail").put("Repository title", "RyaAccumuloSail Store").put("Rya Accumulo user", "root").put("Rya Accumulo password", "").put("Rya Accumulo instance", "dev").put("Rya Accumulo zookeepers", "zoo1,zoo2,zoo3").put("Rya Accumulo is mock", "true").build();
        final String configString = configTemplate.render(valueMap);
        // final Repository systemRepo = this.state.getManager().getSystemRepository();
        final Graph graph = new LinkedHashModel();
        final RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
        rdfParser.setRDFHandler(new StatementCollector(graph));
        rdfParser.parse(new StringReader(configString), RepositoryConfigSchema.NAMESPACE);
        final Resource repositoryNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
        final RepositoryConfig repConfig = RepositoryConfig.create(graph, repositoryNode);
        repConfig.validate();
        repoman.addRepositoryConfig(repConfig);
        Repository r = repoman.getRepository("RyaAccumuloSail");
        r.initialize();
    }
}
Also used : RepositoryConfig(org.openrdf.repository.config.RepositoryConfig) SailRepositoryConfig(org.openrdf.repository.sail.config.SailRepositoryConfig) InputStream(java.io.InputStream) StatementCollector(org.openrdf.rio.helpers.StatementCollector) Resource(org.openrdf.model.Resource) RDFParser(org.openrdf.rio.RDFParser) ConfigTemplate(org.openrdf.repository.config.ConfigTemplate) Repository(org.openrdf.repository.Repository) Graph(org.openrdf.model.Graph) LocalRepositoryManager(org.openrdf.repository.manager.LocalRepositoryManager) StringReader(java.io.StringReader) LinkedHashModel(org.openrdf.model.impl.LinkedHashModel) Test(org.junit.Test)

Example 2 with Repository

use of org.openrdf.repository.Repository in project incubator-rya by apache.

the class RyaAccumuloSailFactoryTest method testAddStatement.

@Ignore
@Test
public void testAddStatement() throws Exception {
    SailRepositoryFactory f = new SailRepositoryFactory();
    Repository r = f.getRepository(getConfig());
    r.initialize();
    RepositoryConnection rc = r.getConnection();
    ValueFactory vf = rc.getValueFactory();
    Statement s = vf.createStatement(vf.createURI("u:a"), vf.createURI("u:b"), vf.createURI("u:c"));
    assertFalse(rc.hasStatement(s, false));
    rc.add(s);
    Assert.assertTrue(rc.hasStatement(s, false));
    rc.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Repository(org.openrdf.repository.Repository) Statement(org.openrdf.model.Statement) ValueFactory(org.openrdf.model.ValueFactory) SailRepositoryFactory(org.openrdf.repository.sail.config.SailRepositoryFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Repository

use of org.openrdf.repository.Repository in project incubator-rya by apache.

the class RyaAccumuloSailFactoryTest method testCreateAccumuloSail.

@Ignore
@Test
public void testCreateAccumuloSail() throws Exception {
    SailRepositoryFactory f = new SailRepositoryFactory();
    Repository r = f.getRepository(getConfig());
    r.initialize();
    RepositoryConnection rc = r.getConnection();
    rc.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Repository(org.openrdf.repository.Repository) SailRepositoryFactory(org.openrdf.repository.sail.config.SailRepositoryFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Repository

use of org.openrdf.repository.Repository in project incubator-rya by apache.

the class ConformanceTest method run.

@Override
public int run(final String[] args) throws Exception {
    // Validate command
    if (args.length < 1 || args.length > 2) {
        System.out.println("Usage:\n");
        System.out.println("\tConformanceTest [configuration options] " + "<test-file> <temp-dir>\n");
        System.out.println("to load test data from an RDF file " + "(configuration property " + MRUtils.FORMAT_PROP + " specifies the format, default RDF/XML); or\n");
        System.out.println("\tConformanceTest [configuration options] <temp-dir>\n");
        System.out.println("to load test data from a Rya instance (specified " + "using standard configuration properties).\n");
        System.out.println("For each test given, run the reasoner over the " + "premise ontology using a temporary Mini Accumulo instance " + "at <temp-dir>, then report conformance results.");
        System.exit(1);
    }
    final Set<Value> conformanceTestURIs = new HashSet<>();
    Collection<OwlTest> conformanceTests = new LinkedList<>();
    final List<OwlTest> successes = new LinkedList<>();
    final List<OwlTest> failures = new LinkedList<>();
    final Configuration conf = getConf();
    Repository repo;
    File workingDir;
    // If tests are in a file, stick them in a repository for querying
    if (args.length == 2) {
        workingDir = new File(PathUtils.clean(args[1]));
        RDFFormat inputFormat = RDFFormat.RDFXML;
        final String formatString = conf.get(MRUtils.FORMAT_PROP);
        if (formatString != null) {
            inputFormat = RDFFormat.valueOf(formatString);
        }
        repo = new SailRepository(new MemoryStore());
        repo.initialize();
        final RepositoryConnection conn = repo.getConnection();
        FileInputStream fileInput = new FileInputStream(PathUtils.clean(args[0]));
        conn.add(fileInput, "", inputFormat);
        fileInput.close();
        conn.close();
    } else // Otherwise, get a Rya repository
    {
        workingDir = new File(PathUtils.clean(args[0]));
        repo = MRReasoningUtils.getRepository(conf);
        repo.initialize();
    }
    // Query for the tests we're interested in
    final RepositoryConnection conn = repo.getConnection();
    conformanceTestURIs.addAll(getTestURIs(conn, TEST_INCONSISTENCY));
    conformanceTestURIs.addAll(getTestURIs(conn, TEST_CONSISTENCY));
    conformanceTestURIs.addAll(getTestURIs(conn, TEST_ENTAILMENT));
    conformanceTestURIs.addAll(getTestURIs(conn, TEST_NONENTAILMENT));
    conformanceTests = getTests(conn, conformanceTestURIs);
    conn.close();
    repo.shutDown();
    // Set up a MiniAccumulo cluster and set up conf to connect to it
    final String username = "root";
    final String password = "root";
    final MiniAccumuloCluster mini = new MiniAccumuloCluster(workingDir, password);
    mini.start();
    conf.set(MRUtils.AC_INSTANCE_PROP, mini.getInstanceName());
    conf.set(MRUtils.AC_ZK_PROP, mini.getZooKeepers());
    conf.set(MRUtils.AC_USERNAME_PROP, username);
    conf.set(MRUtils.AC_PWD_PROP, password);
    conf.setBoolean(MRUtils.AC_MOCK_PROP, false);
    conf.set(MRUtils.TABLE_PREFIX_PROPERTY, "temp_");
    // Run the conformance tests
    int result;
    for (final OwlTest test : conformanceTests) {
        System.out.println(test.uri);
        result = runTest(conf, args, test);
        if (result != 0) {
            return result;
        }
        if (test.success) {
            successes.add(test);
            System.out.println("(SUCCESS)");
        } else {
            failures.add(test);
            System.out.println("(FAIL)");
        }
    }
    mini.stop();
    System.out.println("\n" + successes.size() + " successful tests:");
    for (final OwlTest test : successes) {
        System.out.println("\t[SUCCESS] " + test.type() + " " + test.name);
    }
    System.out.println("\n" + failures.size() + " failed tests:");
    for (final OwlTest test : failures) {
        System.out.println("\t[FAIL] " + test.type() + " " + test.name);
        System.out.println("\t\t(" + test.description + ")");
        for (final Statement triple : test.error) {
            if (test.types.contains(TEST_ENTAILMENT)) {
                System.out.println("\t\tExpected: " + triple);
            } else if (test.types.contains(TEST_NONENTAILMENT)) {
                System.out.println("\t\tUnexpected: " + triple);
            }
        }
    }
    return 0;
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Configuration(org.apache.hadoop.conf.Configuration) SailRepository(org.openrdf.repository.sail.SailRepository) Statement(org.openrdf.model.Statement) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) MemoryStore(org.openrdf.sail.memory.MemoryStore) SailRepository(org.openrdf.repository.sail.SailRepository) Repository(org.openrdf.repository.Repository) Value(org.openrdf.model.Value) File(java.io.File) HashSet(java.util.HashSet) RDFFormat(org.openrdf.rio.RDFFormat)

Example 5 with Repository

use of org.openrdf.repository.Repository in project stanbol by apache.

the class SesameYardComponent method addingService.

@Override
public Object addingService(ServiceReference serviceReference) {
    Repository repo = (Repository) bundleContext.getService(serviceReference);
    if (repo == null) {
        log.error("could not retrieve Sesame Repository for ServiceRefernece {} " + "(repository name: {})", serviceReference, repoId);
    } else {
        if (repoServiceReference != null) {
            // check if the added service reference has a higher ranking
            if (serviceReference.compareTo(repoServiceReference) > 0) {
                log.info("re-regsiter SesameYard because ServiceReference {} " + "has a higher ranking as the currently used one {}!", serviceReference, repoServiceReference);
                unregisterSesameYard();
                registerSesameYard(serviceReference, repo);
            }
        // else the added reference has a lower ranking ... nothing todo
        } else {
            // first service is registered
            registerSesameYard(serviceReference, repo);
        }
    }
    return repo;
}
Also used : Repository(org.openrdf.repository.Repository)

Aggregations

Repository (org.openrdf.repository.Repository)18 SailRepository (org.openrdf.repository.sail.SailRepository)9 RepositoryConnection (org.openrdf.repository.RepositoryConnection)6 RepositoryException (org.openrdf.repository.RepositoryException)6 IOException (java.io.IOException)4 Test (org.junit.Test)4 MemoryStore (org.openrdf.sail.memory.MemoryStore)4 FileNotFoundException (java.io.FileNotFoundException)3 InputStreamReader (java.io.InputStreamReader)3 Statement (org.openrdf.model.Statement)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3 SailException (org.openrdf.sail.SailException)3 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)2 FileInputStream (java.io.FileInputStream)2 StringReader (java.io.StringReader)2 Ignore (org.junit.Ignore)2 RepositoryConfig (org.openrdf.repository.config.RepositoryConfig)2 SailRepositoryFactory (org.openrdf.repository.sail.config.SailRepositoryFactory)2 RDFFormat (org.openrdf.rio.RDFFormat)2 RDFParser (org.openrdf.rio.RDFParser)2