Search in sources :

Example 26 with PrefixMappingImpl

use of org.apache.jena.shared.impl.PrefixMappingImpl in project jena by apache.

the class PrologClauseTest method testAddPrefixes_PrefixMapping.

@ContractTest
public void testAddPrefixes_PrefixMapping() {
    PrefixMapping map = new PrefixMappingImpl();
    map.setNsPrefix("pfx", "uri");
    map.setNsPrefix("pfx2", "uri2");
    PrologClause<?> prologClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = prologClause.addPrefixes(map);
    Query q = builder.build();
    PrefixMapping map2 = q.getPrefixMapping();
    assertEquals(map.getNsPrefixURI("pfx"), map2.getNsPrefixURI("pfx"));
    assertEquals(map.getNsPrefixURI("pfx2"), map2.getNsPrefixURI("pfx2"));
    assertEquals(2, map2.getNsPrefixMap().size());
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) Query(org.apache.jena.query.Query) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ContractTest(org.xenei.junit.contract.ContractTest)

Example 27 with PrefixMappingImpl

use of org.apache.jena.shared.impl.PrefixMappingImpl in project jena by apache.

the class ParseHandlerResolver method declItem.

@Override
protected void declItem(ItemList list, Item item) {
    if (list != declList)
        // Deeper
        return;
    // Prefix - deeper than one.
    boolean isBase = list.get(0).isSymbol(baseTag);
    boolean isPrefix = list.get(0).isSymbol(prefixTag);
    // Old state has already been saved.
    if (isBase) {
        if (!item.isNode())
            throwException("(base ...): not an RDF node for the base.", item);
        if (!item.getNode().isURI())
            throwException("(base ...): not an IRI for the base.", item);
        String newBase = item.getNode().getURI();
        if (baseURI != null)
            baseURI = baseURI.resolve(newBase);
        else
            baseURI = IRIs.resolveIRI(newBase);
        // Remember first base seen
        if (topBase == null)
            topBase = newBase;
        return;
    }
    if (isPrefix) {
        PrefixMapping newPrefixes = new PrefixMappingImpl();
        PrefixMapping itemMappings = BuilderPrefixMapping.build(item);
        // Add exising, overwrite with new
        newPrefixes.setNsPrefixes(prefixes);
        newPrefixes.setNsPrefixes(itemMappings);
        prefixes = newPrefixes;
        // Remember first prefix mapping seen.
        if (topMap == null)
            topMap = itemMappings;
        return;
    }
    throwException("Inconsistent: " + list.shortString(), list);
}
Also used : BuilderPrefixMapping(org.apache.jena.sparql.sse.builders.BuilderPrefixMapping) PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 28 with PrefixMappingImpl

use of org.apache.jena.shared.impl.PrefixMappingImpl in project jena by apache.

the class Prologue method copy.

// public Prologue(PrefixMapping pmap, String base) {
// this.prefixMap = pmap;
// setBaseURI(base);
// }
public Prologue copy() {
    PrefixMapping prefixMap = new PrefixMappingImpl();
    prefixMap.setNsPrefixes(this.prefixMap);
    return new Prologue(prefixMap, resolver);
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 29 with PrefixMappingImpl

use of org.apache.jena.shared.impl.PrefixMappingImpl in project jena by apache.

the class GraphUnionRead method createPrefixMapping.

@Override
protected PrefixMapping createPrefixMapping() {
    PrefixMapping pmap = new PrefixMappingImpl();
    forEachGraph((g) -> {
        PrefixMapping pmapNamedGraph = g.getPrefixMapping();
        pmap.setNsPrefixes(pmapNamedGraph);
    });
    return pmap;
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 30 with PrefixMappingImpl

use of org.apache.jena.shared.impl.PrefixMappingImpl in project jena by apache.

the class TestParameterizedSparqlString method test_param_string_constructor_8.

@Test
public void test_param_string_constructor_8() {
    // Test constructors with predefined prefixes
    PrefixMappingImpl prefixes = new PrefixMappingImpl();
    prefixes.setNsPrefix("ex", "http://example.org");
    ParameterizedSparqlString query = new ParameterizedSparqlString("", prefixes);
    Assert.assertEquals(prefixes.getNsPrefixURI("ex"), query.getNsPrefixURI("ex"));
}
Also used : PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) Test(org.junit.Test)

Aggregations

PrefixMappingImpl (org.apache.jena.shared.impl.PrefixMappingImpl)39 PrefixMapping (org.apache.jena.shared.PrefixMapping)34 Test (org.junit.Test)13 Path (org.apache.jena.sparql.path.Path)11 Graph (org.apache.jena.graph.Graph)8 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)4 TriplePath (org.apache.jena.sparql.core.TriplePath)4 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)4 BeforeClass (org.junit.BeforeClass)4 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)3 ContractTest (org.xenei.junit.contract.ContractTest)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Triple (org.apache.jena.graph.Triple)2 Dataset (org.apache.jena.query.Dataset)2 Date (java.util.Date)1 Trie (org.apache.jena.atlas.lib.Trie)1 SecuredPrefixMapping (org.apache.jena.permissions.graph.SecuredPrefixMapping)1 Query (org.apache.jena.query.Query)1 UpdateDeniedException (org.apache.jena.shared.UpdateDeniedException)1