[ https://issues.apache.org/jira/browse/RYA-255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15963696#comment-15963696 ]
ASF GitHub Bot commented on RYA-255: ------------------------------------ Github user kchilton2 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/144#discussion_r110795434 --- Diff: extras/indexingExample/src/main/java/ProspectorExample.java --- @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import org.apache.hadoop.util.ToolRunner; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.utils.ConnectorFactory; +import org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF; +import org.apache.rya.prospector.mr.Prospector; +import org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO; +import org.apache.rya.sail.config.RyaSailFactory; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; +import org.openrdf.sail.Sail; +import org.openrdf.sail.SailConnection; + +import com.beust.jcommander.internal.Lists; + +/** + * Demonstrates how you can use the {@link Prospector} to count values that appear within an instance of Rya and + * then use the {@link ProspectorServiceEvalStatsDAO} to fetch those counts. + */ +public class ProspectorExample { + private static final Logger log = Logger.getLogger(RyaClientExample.class); + + private static final ValueFactory VALUE_FACTORY = new ValueFactoryImpl(); + + private static final URI ALICE = VALUE_FACTORY.createURI("urn:alice"); + private static final URI BOB = VALUE_FACTORY.createURI("urn:bob"); + private static final URI CHARLIE = VALUE_FACTORY.createURI("urn:charlie"); + + private static final URI WORKS_AT = VALUE_FACTORY.createURI("urn:worksAt"); + private static final URI ADMIRES = VALUE_FACTORY.createURI("urn:admires"); + private static final URI LIVES_WITH = VALUE_FACTORY.createURI("urn:livesWith"); + + private static final URI BURGER_JOINT = VALUE_FACTORY.createURI("urn:burgerJoint"); + private static final URI DONUT_SHOP= VALUE_FACTORY.createURI("urn:donutShop"); + + public static void main(final String[] args) throws Exception { + setupLogging(); + + // Configure Rya to use a mock instance. + final AccumuloRdfConfiguration config = new AccumuloRdfConfiguration(); + config.useMockInstance(true); + config.setTablePrefix("rya_"); + config.setUsername("user"); + config.setPassword("pass"); + config.setInstanceName("accumulo"); + + // Load some data into Rya. + final List<Statement> statements = Lists.newArrayList( + VALUE_FACTORY.createStatement(ALICE, WORKS_AT, BURGER_JOINT), + VALUE_FACTORY.createStatement(ALICE, ADMIRES, BOB), + VALUE_FACTORY.createStatement(BOB, WORKS_AT, DONUT_SHOP), + VALUE_FACTORY.createStatement(CHARLIE, WORKS_AT, DONUT_SHOP), + VALUE_FACTORY.createStatement(CHARLIE, LIVES_WITH, BOB), + VALUE_FACTORY.createStatement(BOB, LIVES_WITH, CHARLIE), + VALUE_FACTORY.createStatement(BOB, LIVES_WITH, ALICE)); + + final Sail sail = RyaSailFactory.getInstance(config); + final SailConnection conn = sail.getConnection(); + log.info("Loading the following statements into a Mock instance of Accumulo Rya:"); + conn.begin(); + for(final Statement statement : statements) { + log.info(" " + statement.toString()); + conn.addStatement(statement.getSubject(), statement.getPredicate(), statement.getObject()); + } + conn.commit(); + conn.close(); + + // Create the table that the Prospector's results will be written to. + ConnectorFactory.connect(config) + .tableOperations() + .create("rya_prospects"); + + // Run the Prospector using the configuration file that is in the resources directory. + log.info(""); + log.info("Running the Map Reduce job that computes the Prospector results."); + ToolRunner.run(new Prospector(), new String[]{ "src/main/resources/stats_cluster_config.xml" }); + + // Print the table that was created by the Prospector. + log.info(""); + log.info("The following cardinalities were written to the Prospector table:"); + final ProspectorServiceEvalStatsDAO dao = ProspectorServiceEvalStatsDAO.make(config); + + // Do each of the Subjects. + double cardinality = dao.getCardinality(config, CARDINALITY_OF.SUBJECT, Lists.newArrayList(ALICE)); --- End diff -- I think reducing the lines of the code, in this case, actually makes the example a lot harder to understand. > Provide an example class that demonstrates Prospector. > ------------------------------------------------------ > > Key: RYA-255 > URL: https://issues.apache.org/jira/browse/RYA-255 > Project: Rya > Issue Type: Improvement > Reporter: Kevin Chilton > Assignee: Kevin Chilton > > Create an example class that demonstrates how the Prospector may be used to > build and harvest information about a Rya instance. -- This message was sent by Atlassian JIRA (v6.3.15#6346)