Search in sources :

Example 56 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class StatementPatternStorage method addInferredRanges.

protected void addInferredRanges(String tablePrefix, Job job) throws IOException {
    logger.info("Adding inferences to statement pattern[subject:" + subject_value + ", predicate:" + predicate_value + ", object:" + object_value + "]");
    // inference engine
    AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
    InferenceEngine inferenceEngine = new InferenceEngine();
    try {
        AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(job.getConfiguration());
        rdfConf.setTablePrefix(tablePrefix);
        ryaDAO.setConf(rdfConf);
        try {
            if (!mock) {
                ryaDAO.setConnector(new ZooKeeperInstance(inst, zookeepers).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
            } else {
                ryaDAO.setConnector(new MockInstance(inst).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
            }
        } catch (Exception e) {
            throw new IOException(e);
        }
        ryaDAO.init();
        inferenceEngine.setConf(rdfConf);
        inferenceEngine.setRyaDAO(ryaDAO);
        inferenceEngine.setSchedule(false);
        inferenceEngine.init();
        // is it subclassof or subpropertyof
        if (RDF.TYPE.equals(predicate_value)) {
            // try subclassof
            Collection<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubClassOfGraph(), (URI) object_value);
            if (parents != null && parents.size() > 0) {
                // add all relationships
                for (URI parent : parents) {
                    Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, predicate_value, parent);
                    Range range = temp.getValue();
                    if (logger.isDebugEnabled()) {
                        logger.debug("Found subClassOf relationship [type:" + object_value + " is subClassOf:" + parent + "]");
                    }
                    addRange(range);
                }
            }
        } else if (predicate_value != null) {
            // subpropertyof check
            Set<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubPropertyOfGraph(), (URI) predicate_value);
            for (URI parent : parents) {
                Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, parent, object_value);
                Range range = temp.getValue();
                if (logger.isDebugEnabled()) {
                    logger.debug("Found subPropertyOf relationship [type:" + predicate_value + " is subPropertyOf:" + parent + "]");
                }
                addRange(range);
            }
        }
    } catch (Exception e) {
        logger.error("Exception in adding inferred ranges", e);
        throw new IOException(e);
    } finally {
        if (inferenceEngine != null) {
            try {
                inferenceEngine.destroy();
            } catch (InferenceEngineException e) {
                logger.error("Exception closing InferenceEngine", e);
            }
        }
        if (ryaDAO != null) {
            try {
                ryaDAO.destroy();
            } catch (RyaDAOException e) {
                logger.error("Exception closing ryadao", e);
            }
        }
    }
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) Set(java.util.Set) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) MalformedQueryException(org.openrdf.query.MalformedQueryException) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) InferenceEngine(org.apache.rya.rdftriplestore.inference.InferenceEngine) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Map(java.util.Map)

Example 57 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class TextOutputExample method setUpRya.

static void setUpRya() throws AccumuloException, AccumuloSecurityException, RyaDAOException {
    MockInstance mock = new MockInstance(INSTANCE_NAME);
    Connector conn = mock.getConnector(USERNAME, new PasswordToken(USERP));
    AccumuloRyaDAO dao = new AccumuloRyaDAO();
    dao.setConnector(conn);
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(PREFIX);
    dao.setConf(conf);
    dao.init();
    String ns = "http://example.com/";
    dao.add(new RyaStatement(new RyaURI(ns + "s1"), new RyaURI(ns + "p1"), new RyaURI(ns + "o1")));
    dao.add(new RyaStatement(new RyaURI(ns + "s1"), new RyaURI(ns + "p2"), new RyaURI(ns + "o2")));
    dao.add(new RyaStatement(new RyaURI(ns + "s2"), new RyaURI(ns + "p1"), new RyaURI(ns + "o3"), new RyaURI(ns + "g1")));
    dao.add(new RyaStatement(new RyaURI(ns + "s3"), new RyaURI(ns + "p3"), new RyaURI(ns + "o3"), new RyaURI(ns + "g2")));
    dao.destroy();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) RyaURI(org.apache.rya.api.domain.RyaURI) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 58 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class GraphXEdgeInputFormatTest method init.

@Before
public void init() throws Exception {
    instance = new MockInstance(GraphXEdgeInputFormatTest.class.getName() + ".mock_instance");
    Connector connector = instance.getConnector(username, password);
    connector.tableOperations().create(table);
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix("rya_");
    conf.setDisplayQueryPlan(false);
    apiImpl = new AccumuloRyaDAO();
    apiImpl.setConf(conf);
    apiImpl.setConnector(connector);
    apiImpl.init();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Before(org.junit.Before)

Example 59 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class RdfFileInputToolTest method testNTriplesInput.

@Test
public void testNTriplesInput() throws Exception {
    RdfFileInputTool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Dac.auth=" + auths.toString(), "-Dac.cv=" + auths.toString(), "-Drdf.tablePrefix=" + tablePrefix, "-Drdf.format=" + RDFFormat.NTRIPLES.getName(), "src/test/resources/test.ntriples" });
    RyaStatement rs = new RyaStatement(new RyaURI("urn:lubm:rdfts#GraduateStudent01"), new RyaURI("urn:lubm:rdfts#hasFriend"), new RyaURI("urn:lubm:rdfts#GraduateStudent02"));
    rs.setColumnVisibility(auths.toString().getBytes());
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(tablePrefix);
    conf.setAuths(auths.toString());
    TestUtils.verify(connector, conf, rs);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Test(org.junit.Test)

Example 60 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class QueryBenchmarkRunIT method setup.

@BeforeClass
public static void setup() throws Exception {
    // Squash loud logs.
    Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR);
    // Setup the Mini Accumulo Cluster.
    final File miniDataDir = com.google.common.io.Files.createTempDir();
    final MiniAccumuloConfig cfg = new MiniAccumuloConfig(miniDataDir, ACCUMULO_PASSWORD);
    cluster = new MiniAccumuloCluster(cfg);
    cluster.start();
    // Create a Rya Client connected to the Mini Accumulo Cluster.
    final AccumuloConnectionDetails connDetails = new AccumuloConnectionDetails(ACCUMULO_USER, ACCUMULO_PASSWORD.toCharArray(), cluster.getInstanceName(), cluster.getZooKeepers());
    final Connector connector = cluster.getConnector(ACCUMULO_USER, ACCUMULO_PASSWORD);
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(connDetails, connector);
    // Install an instance of Rya on the mini cluster.
    installRya(ryaClient);
    // Get a Sail object that is backed by the Rya store that is on the mini cluster.
    final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
    ryaConf.setTablePrefix(RYA_INSTANCE_NAME);
    ryaConf.set(ConfigUtils.CLOUDBASE_USER, ACCUMULO_USER);
    ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, ACCUMULO_PASSWORD);
    ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, cluster.getZooKeepers());
    ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, cluster.getInstanceName());
    ryaConf.set(ConfigUtils.USE_PCJ, "true");
    ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString());
    ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.NO_UPDATE.toString());
    sail = RyaSailFactory.getInstance(ryaConf);
    // Load some data into the cluster that will match the query we're testing against.
    loadTestStatements();
    // Add a PCJ to the application that summarizes the query.
    createTestPCJ(ryaClient);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) RyaClient(org.apache.rya.api.client.RyaClient) ClientCnxn(org.apache.zookeeper.ClientCnxn) File(java.io.File) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) BeforeClass(org.junit.BeforeClass)

Aggregations

AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)108 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)26 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)25 Test (org.junit.Test)24 RyaURI (org.apache.rya.api.domain.RyaURI)22 Connector (org.apache.accumulo.core.client.Connector)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)20 RyaStatement (org.apache.rya.api.domain.RyaStatement)20 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)15 Sail (org.openrdf.sail.Sail)15 RyaType (org.apache.rya.api.domain.RyaType)14 StatementPattern (org.openrdf.query.algebra.StatementPattern)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)12 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)12 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 BindingSet (org.openrdf.query.BindingSet)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10