<commit_before>/*
 *  Licensed 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.
 *
 *  See the NOTICE file distributed with this work for additional
 *  information regarding copyright ownership.
 */
 
package org.seaborne.tdb2.loader;

import org.apache.jena.atlas.logging.FmtLog ;
import org.apache.jena.atlas.logging.ProgressLogger ;
import org.apache.jena.query.Dataset ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.system.StreamRDF ;
import org.apache.jena.riot.system.StreamRDFLib ;
import org.seaborne.tdb2.lib.TDBTxn ;
import org.seaborne.tdb2.store.DatasetGraphTDB ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;

public class Loader {
    
    private static final int BATCH_SIZE = 100 ;
    
    // XXX StreamRDFBatchSplit and parallel index update.
    private static Logger LOG = LoggerFactory.getLogger("Loader") ;
    
    public static void bulkLoad(Dataset ds, String ... files) {
        DatasetGraphTDB dsg = (DatasetGraphTDB)ds.asDatasetGraph() ;
        StreamRDF s1 = StreamRDFLib.dataset(dsg) ;
        ProgressLogger plog = new ProgressLogger(LOG, "Triples", 100000, 10) ;
        StreamRDFMonitor sMonitor = new StreamRDFMonitor(s1, plog) ;
        StreamRDF s3 = sMonitor ;

        sMonitor.startMonitor(); 
        TDBTxn.executeWrite(ds, () -> {
            for ( String fn : files ) {
                if ( files.length > 1 )
                    FmtLog.info(LOG, "File: %s",fn);
                RDFDataMgr.parse(s3, fn) ;
            }
        }) ;
        sMonitor.finishMonitor();  
    }
    
    public static void bulkLoadBatching(Dataset ds, String ... files) {
        DatasetGraphTDB dsg = (DatasetGraphTDB)ds.asDatasetGraph() ;

        StreamRDFBatchSplit s1 = new StreamRDFBatchSplit(dsg, 10) ;
        ProgressLogger plog = new ProgressLogger(LOG, "Triples", 100000, BATCH_SIZE) ;
        // Want the monitor on the outside to capture transaction wrapper costs.
        StreamRDFMonitor sMonitor = new StreamRDFMonitor(s1, plog) ;
        StreamRDF s3 = sMonitor ;

        sMonitor.startMonitor(); 
        TDBTxn.executeWrite(ds, () -> {
            for ( String fn : files ) {
                if ( files.length > 1 )
                    FmtLog.info(LOG, "File: %s",fn);
                RDFDataMgr.parse(s3, fn) ;
            }
        }) ;
        sMonitor.finishMonitor();  
    }
}
<commit_msg>ProgressLogger -> ProgressMonitor and use ProgressStreamRDF.<commit_after>/*
 *  Licensed 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.
 *
 *  See the NOTICE file distributed with this work for additional
 *  information regarding copyright ownership.
 */
 
package org.seaborne.tdb2.loader;

import org.apache.jena.atlas.lib.ProgressMonitor ;
import org.apache.jena.atlas.logging.FmtLog ;
import org.apache.jena.query.Dataset ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.system.ProgressStreamRDF ;
import org.apache.jena.riot.system.StreamRDF ;
import org.apache.jena.riot.system.StreamRDFLib ;
import org.seaborne.tdb2.lib.TDBTxn ;
import org.seaborne.tdb2.store.DatasetGraphTDB ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;

public class Loader {
    
    private static final int BATCH_SIZE = 100 ;
    
    // XXX StreamRDFBatchSplit and parallel index update.
    private static Logger LOG = LoggerFactory.getLogger("Loader") ;
    
    public static void bulkLoad(Dataset ds, String ... files) {
        DatasetGraphTDB dsg = (DatasetGraphTDB)ds.asDatasetGraph() ;
        StreamRDF s1 = StreamRDFLib.dataset(dsg) ;
        ProgressMonitor plog = ProgressMonitor.create(LOG, "Triples", 100000, 10) ;
        ProgressStreamRDF sMonitor = new ProgressStreamRDF(s1, plog) ;
        StreamRDF s3 = sMonitor ;

        plog.start(); 
        TDBTxn.executeWrite(ds, () -> {
            for ( String fn : files ) {
                if ( files.length > 1 )
                    FmtLog.info(LOG, "File: %s",fn);
                RDFDataMgr.parse(s3, fn) ;
            }
        }) ;
        plog.finish();
        plog.finishMessage();
    }
    
    public static void bulkLoadBatching(Dataset ds, String ... files) {
        DatasetGraphTDB dsg = (DatasetGraphTDB)ds.asDatasetGraph() ;

        StreamRDFBatchSplit s1 = new StreamRDFBatchSplit(dsg, 10) ;
        ProgressMonitor plog = ProgressMonitor.create(LOG, "Triples", 100000, BATCH_SIZE) ;
        // Want the monitor on the outside to capture transaction wrapper costs.
        StreamRDF s3 = new ProgressStreamRDF(s1, plog) ;

        plog.start(); 
        TDBTxn.executeWrite(ds, () -> {
            for ( String fn : files ) {
                if ( files.length > 1 )
                    FmtLog.info(LOG, "File: %s",fn);
                RDFDataMgr.parse(s3, fn) ;
            }
        }) ;
        plog.finish();  
        plog.finishMessage();
    }
}

{'fraction_non_alphanumeric': 0.09710566877890049, 'fraction_numerical': 0.01301592738482617, 'mean_word_length': 2.585021485573972, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '976786', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1753, 'n_words': 471}