Search in sources :

Example 81 with Model

use of org.apache.jena.rdf.model.Model 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 82 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class ScriptDesc method read.

public static ScriptDesc read(String filename) {
    AssemblerVocab.init();
    Model m = FileManager.get().loadModel(filename);
    return worker(m);
}
Also used : Model(org.apache.jena.rdf.model.Model)

Example 83 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class sdbmeta method execPut.

private void execPut(StoreConfig conf, String tag, List<String> positionalArgs) {
    if (positionalArgs.size() == 0)
        throw new CmdException("No file to load");
    Model model = conf.getModel(tag);
    if (model == null)
        model = ModelFactory.createDefaultModel();
    for (String filename : positionalArgs) FileManager.get().readModel(model, filename);
    conf.setModel(tag, model);
}
Also used : CmdException(jena.cmd.CmdException) Model(org.apache.jena.rdf.model.Model)

Example 84 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class StoreUtils method load.

public static void load(Store store, String graphIRI, String filename) {
    Model model = SDBFactory.connectNamedModel(store, graphIRI);
    FileManager.get().readModel(model, filename);
}
Also used : Model(org.apache.jena.rdf.model.Model)

Example 85 with Model

use of org.apache.jena.rdf.model.Model in project jena by apache.

the class T_TDBWriteTransaction method run.

public static void run(String location) {
    if (false) {
        Journal journal = Journal.create(Location.create(location));
        JournalControl.print(journal);
        journal.close();
    }
    //String location = args[0]; // + "/" + UUID.randomUUID().toString();
    //String baseGraphName = "com.ibm.test.graphNamePrefix.";   
    long totalExecTime = 0L;
    long size = 0;
    Dataset dataset = TDBFactory.createDataset(location);
    Dataset dataset1 = TDBFactory.createDataset(location);
    if (bracketWithReader)
        dataset1.begin(ReadWrite.READ);
    for (int i = 0; i < TOTAL; i++) {
        List<String> lastProcessedUris = new ArrayList<>();
        for (int j = 0; j < 10 * i; j++) {
            String lastProcessedUri = "http://test.net/xmlns/test/1.0/someUri" + j;
            lastProcessedUris.add(lastProcessedUri);
        }
        //Dataset dataset = TDBFactory.createDataset(location);
        //String graphName = baseGraphName + i;
        long t = System.currentTimeMillis();
        try {
            dataset.begin(ReadWrite.WRITE);
            Model m = dataset.getDefaultModel();
            m.removeAll();
            Resource subject = m.createResource(INDEX_INFO_SUBJECT);
            Property predicate = m.createProperty(TIMESTAMP_PREDICATE);
            m.addLiteral(subject, predicate, System.currentTimeMillis());
            predicate = m.createProperty(URI_PREDICATE);
            for (String uri : lastProcessedUris) {
                m.add(subject, predicate, m.createResource(uri));
            }
            predicate = m.createProperty(VERSION_PREDICATE);
            m.addLiteral(subject, predicate, 1.0);
            size += m.size() + 1;
            predicate = m.createProperty(INDEX_SIZE_PREDICATE);
            m.addLiteral(subject, predicate, size);
            dataset.commit();
        } catch (Throwable e) {
            dataset.abort();
            throw new RuntimeException(e);
        } finally {
            dataset.end();
            long writeOperationDuration = System.currentTimeMillis() - t;
            totalExecTime += writeOperationDuration;
            System.out.println("Write operation " + i + " took " + writeOperationDuration + "ms");
        }
    }
    if (bracketWithReader)
        dataset1.end();
    System.out.println("All " + TOTAL + " write operations wrote " + size + " triples and took " + totalExecTime + "ms");
}
Also used : Dataset(org.apache.jena.query.Dataset) ArrayList(java.util.ArrayList) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Journal(org.apache.jena.tdb.transaction.Journal) Property(org.apache.jena.rdf.model.Property)

Aggregations

Model (org.apache.jena.rdf.model.Model)444 Test (org.junit.Test)177 BaseTest (org.apache.jena.atlas.junit.BaseTest)96 Resource (org.apache.jena.rdf.model.Resource)87 StringReader (java.io.StringReader)43 Dataset (org.apache.jena.query.Dataset)31 RDFReader (org.apache.jena.rdf.model.RDFReader)30 Property (org.apache.jena.rdf.model.Property)24 DatasetAccessor (org.apache.jena.query.DatasetAccessor)20 InfModel (org.apache.jena.rdf.model.InfModel)20 Node (org.apache.jena.graph.Node)19 Statement (org.apache.jena.rdf.model.Statement)18 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)15 Reader (java.io.Reader)14 JsonString (org.apache.jena.atlas.json.JsonString)14 AbstractFusekiTest (org.apache.jena.fuseki.AbstractFusekiTest)14 FusekiTest (org.apache.jena.fuseki.FusekiTest)14 Graph (org.apache.jena.graph.Graph)14 JenaException (org.apache.jena.shared.JenaException)14 Triple (org.apache.jena.graph.Triple)13