Search in sources :

Example 6 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class StoragePrefixesSimpleMem method accessForUpdate.

// Access or return a fresh, empty.
private PrefixMap accessForUpdate(Node graphName) {
    graphName = canonicalGraphName(graphName);
    PrefixMap pmap = map.get(graphName);
    if (pmap == null) {
        pmap = createPrefixMap();
        map.put(graphName, pmap);
    }
    return pmap;
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap)

Example 7 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class StoragePrefixesSimpleMem method access.

// Access or return the empty, dummy mapping.
private PrefixMap access(Node graphName) {
    graphName = canonicalGraphName(graphName);
    PrefixMap pmap = map.get(graphName);
    if (pmap == null)
        return PrefixMapZero.empty;
    return pmap;
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap)

Example 8 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class CompactWriter method print.

/**
 * Write shapes with directives BASE/PREFIX/IMPORTS.
 */
public static void print(IndentedWriter out, Shapes shapes) {
    // Output PrefixMap
    PrefixMap graphPrefixMap = shapes.getPrefixMap();
    // Formatter PrefixMap - with the std prefixes if not overridden.
    PrefixMap pmapWithStd = SHACLC.withStandardPrefixes();
    // Add to copy of standrard so it can override any standard settings.
    pmapWithStd.putAll(graphPrefixMap);
    NodeFormatter nodeFmt = new NodeFormatterTTL(null, pmapWithStd);
    boolean someOutput = false;
    // BASE - output if and only if there is exactly one.
    String baseURI = shapes.getBaseURI();
    if (baseURI != null) {
        if (someOutput)
            out.println();
        RiotLib.writeBase(out, baseURI, true);
        someOutput = true;
    }
    // PREFIX
    if (!graphPrefixMap.isEmpty()) {
        if (someOutput)
            out.println();
        RiotLib.writePrefixes(out, graphPrefixMap, true);
        someOutput = true;
    }
    // IMPORTS
    if (shapes.getImports() != null) {
        if (!shapes.getImports().isEmpty()) {
            if (someOutput)
                out.println();
            shapes.getImports().forEach(n -> {
                out.print("IMPORTS ");
                out.pad(WriterConst.PREFIX_IRI);
                nodeFmt.format(out, n);
                out.println();
            });
        }
    }
    PrefixMapping prefixMappingWithStd = Prefixes.adapt(pmapWithStd);
    ShapeOutputVisitor visitor = new ShapeOutputVisitor(prefixMappingWithStd, nodeFmt, out);
    shapes.iteratorAll().forEachRemaining(sh -> {
        out.println();
        writeOneShapeCompact(out, nodeFmt, visitor, sh);
    // writeOneShapeCompactOrSkip(out, nodeFmt, visitor, sh);
    });
    out.flush();
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) PrefixMapping(org.apache.jena.shared.PrefixMapping) NodeFormatter(org.apache.jena.riot.out.NodeFormatter) NodeFormatterTTL(org.apache.jena.riot.out.NodeFormatterTTL)

Example 9 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class TestDatasetPrefixes method dsg_prefixes_txn_3.

@Test
public void dsg_prefixes_txn_3() {
    Assume.assumeTrue(supportsPromote);
    DatasetGraph dsg = create();
    Assume.assumeTrue(dsg.supportsTransactionAbort());
    Txn.exec(dsg, TxnType.READ_PROMOTE, () -> {
        PrefixMap pmap = dsg.prefixes();
        pmap.add("ex", "http://example/2");
    });
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 10 with PrefixMap

use of org.apache.jena.riot.system.PrefixMap in project jena by apache.

the class TestDatasetPrefixes method dsg_prefixes_txn_2.

// Legacy: TDBTransactionException is not under JenaTransactionException.
@Test(expected = JenaException.class)
public void dsg_prefixes_txn_2() {
    Assume.assumeTrue(txnIsolation);
    DatasetGraph dsg = create();
    Txn.executeRead(dsg, () -> {
        PrefixMap pmap = dsg.prefixes();
        try {
            // Write inside read.
            // TIM prefixes are standalone, MRSW so they are thread safe but not tied to the TIM transaction lifecycle.
            // No Isolation.
            pmap.add("ex", "http://example/2");
        } catch (JenaTransactionException | TDBTransactionException ex) {
            throw ex;
        }
    });
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException) TDBTransactionException(org.apache.jena.tdb.transaction.TDBTransactionException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Aggregations

PrefixMap (org.apache.jena.riot.system.PrefixMap)33 Test (org.junit.Test)16 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 Map (java.util.Map)3 Node (org.apache.jena.graph.Node)2 QueryCancelledException (org.apache.jena.query.QueryCancelledException)2 QueryExecException (org.apache.jena.query.QueryExecException)2 NodeFormatter (org.apache.jena.riot.out.NodeFormatter)2 NodeFormatterTTL (org.apache.jena.riot.out.NodeFormatterTTL)2 JsonLdApi (com.github.jsonldjava.core.JsonLdApi)1 JsonLdOptions (com.github.jsonldjava.core.JsonLdOptions)1 RDFDataset (com.github.jsonldjava.core.RDFDataset)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Iter (org.apache.jena.atlas.iterator.Iter)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 JsonString (org.apache.jena.atlas.json.JsonString)1 StoragePrefixes (org.apache.jena.dboe.storage.StoragePrefixes)1