Search in sources :

Example 1 with ProgressMonitor

use of org.apache.jena.atlas.lib.ProgressMonitor in project jena by apache.

the class sdbload method loadOne.

private void loadOne(String filename, boolean replace) {
    Model model = null;
    Dataset dataset = null;
    PrefixMapping pmap;
    Lang lang = RDFLanguages.filenameToLang(filename);
    if (lang == null)
        throw new CmdException("Data syntax not recognized: " + filename);
    // --graph or not
    if (modGraph.getGraphName() != null) {
        model = modGraph.getModel(getStore());
        pmap = model;
    } else {
        dataset = SDBFactory.connectDataset(getStore());
        pmap = dataset.asDatasetGraph().getDefaultGraph().getPrefixMapping();
    }
    // For monitoring only.
    Graph monitorGraph = (model == null) ? null : model.getGraph();
    if (replace) {
        if (model != null)
            model.removeAll();
        else
            dataset.asDatasetGraph().clear();
    }
    boolean showProgress = isVerbose() || getModTime().timingEnabled();
    if (showProgress)
        output.print("Start load: %s", filename);
    StreamRDF stream = streamToStore(pmap, getStore());
    if (modGraph.getGraphName() != null) {
        Node gn = NodeFactory.createURI(modGraph.getGraphName());
        stream = StreamRDFLib.extendTriplesToQuads(gn, stream);
    }
    ProgressMonitor progress = null;
    if (showProgress) {
        progress = new ProgressMonitor(filename, 100_000, 10, output);
        stream = new ProgressStreamRDF(stream, progress);
    }
    if (progress != null)
        progress.start();
    // Load!
    RDFDataMgr.parse(stream, filename, lang);
    if (progress != null) {
        progress.finish();
        progress.finishMessage();
    }
}
Also used : ProgressMonitor(org.apache.jena.atlas.lib.ProgressMonitor) PrefixMapping(org.apache.jena.shared.PrefixMapping) Graph(org.apache.jena.graph.Graph) ModGraph(sdb.cmd.ModGraph) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) CmdException(jena.cmd.CmdException) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) StreamRDF(org.apache.jena.riot.system.StreamRDF) Dataset(org.apache.jena.query.Dataset) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang)

Example 2 with ProgressMonitor

use of org.apache.jena.atlas.lib.ProgressMonitor in project jena by apache.

the class ProcIndexCopy method tupleIndexCopy.

private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label) {
    ProgressMonitor monitor = ProgressMonitor.create(log, label, tickQuantum, superTick);
    monitor.start();
    Iterator<Tuple<NodeId>> iter1 = index1.all();
    long counter = 0;
    for (; iter1.hasNext(); ) {
        counter++;
        Tuple<NodeId> tuple = iter1.next();
        index2.add(tuple);
        monitor.tick();
    }
    index2.sync();
    long time = monitor.finish();
    float elapsedSecs = time / 1000F;
    float rate = (elapsedSecs != 0) ? counter / elapsedSecs : 0;
    print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString());
}
Also used : ProgressMonitor(org.apache.jena.atlas.lib.ProgressMonitor) NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 3 with ProgressMonitor

use of org.apache.jena.atlas.lib.ProgressMonitor in project jena by apache.

the class ProcNodeTableBuilder method exec.

public static void exec(Location location, String dataFileTriples, String dataFileQuads, List<String> datafiles, boolean collectStats) {
    // This formats the location correctly.
    // But we're not really interested in it all.
    DatasetGraphTDB dsg = DatasetBuilderStd.create(location);
    // so close indexes and the prefix table.
    dsg.getTripleTable().getNodeTupleTable().getTupleTable().close();
    dsg.getQuadTable().getNodeTupleTable().getTupleTable().close();
    ProgressMonitor monitor = ProgressMonitor.create(cmdLog, "Data", BulkLoader.DataTickPoint, BulkLoader.superTick);
    OutputStream outputTriples = null;
    OutputStream outputQuads = null;
    try {
        outputTriples = new FileOutputStream(dataFileTriples);
        outputQuads = new FileOutputStream(dataFileQuads);
    } catch (FileNotFoundException e) {
        throw new AtlasException(e);
    }
    NodeTableBuilder sink = new NodeTableBuilder(dsg, monitor, outputTriples, outputQuads, collectStats);
    monitor.start();
    sink.startBulk();
    for (String filename : datafiles) {
        if (datafiles.size() > 0)
            cmdLog.info("Load: " + filename + " -- " + DateTimeUtils.nowAsString());
        RDFDataMgr.parse(sink, filename);
    }
    sink.finishBulk();
    IO.close(outputTriples);
    IO.close(outputQuads);
    // See Stats class.
    if (!location.isMem() && sink.getCollector() != null)
        Stats.write(dsg.getLocation().getPath(Names.optStats), sink.getCollector().results());
    // ---- Monitor
    long time = monitor.finish();
    long total = monitor.getTicks();
    float elapsedSecs = time / 1000F;
    float rate = (elapsedSecs != 0) ? total / elapsedSecs : 0;
    String str = String.format("Total: %,d tuples : %,.2f seconds : %,.2f tuples/sec [%s]", total, elapsedSecs, rate, DateTimeUtils.nowAsString());
    cmdLog.info(str);
}
Also used : ProgressMonitor(org.apache.jena.atlas.lib.ProgressMonitor) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) AtlasException(org.apache.jena.atlas.AtlasException) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Aggregations

ProgressMonitor (org.apache.jena.atlas.lib.ProgressMonitor)3 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 CmdException (jena.cmd.CmdException)1 AtlasException (org.apache.jena.atlas.AtlasException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 Dataset (org.apache.jena.query.Dataset)1 Model (org.apache.jena.rdf.model.Model)1 Lang (org.apache.jena.riot.Lang)1 ProgressStreamRDF (org.apache.jena.riot.system.ProgressStreamRDF)1 StreamRDF (org.apache.jena.riot.system.StreamRDF)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)1 NodeId (org.apache.jena.tdb.store.NodeId)1 ModGraph (sdb.cmd.ModGraph)1