Search in sources :

Example 6 with IRIxResolver

use of org.apache.jena.irix.IRIxResolver in project jena by apache.

the class TestIRIxRIOT method irix_ttl_resolver_2.

// Turtle with directly set resolver, non-standard setup. No base, no resolve, no relative IRIs.
@Test
public void irix_ttl_resolver_2() {
    // Resolver:: no base, no relative IRIs, no resolving -> error.
    IRIxResolver resolver = IRIxResolver.create().noBase().resolve(false).allowRelative(false).build();
    testTTL("<relative>", resolver, 1, 0);
}
Also used : IRIxResolver(org.apache.jena.irix.IRIxResolver) Test(org.junit.Test)

Example 7 with IRIxResolver

use of org.apache.jena.irix.IRIxResolver in project jena by apache.

the class TestIRIxRIOT method irix_ttl_resolver_0.

// Turtle with directly set resolver, non-standard setup. no base, resolve, no relative IRIs
@Test
public void irix_ttl_resolver_0() {
    // Resolver:: default is allowRelative(true)
    IRIxResolver resolver = IRIxResolver.create().noBase().build();
    testTTL("<relative>", resolver, 0, 1);
}
Also used : IRIxResolver(org.apache.jena.irix.IRIxResolver) Test(org.junit.Test)

Example 8 with IRIxResolver

use of org.apache.jena.irix.IRIxResolver in project jena by apache.

the class TestParserFactory method ntriples_01.

@Test
public void ntriples_01() {
    {
        String s = "<x> <p> <q> .";
        CatchParserOutput sink = parseCapture(s, Lang.NT);
        assertEquals(1, sink.startCalled);
        assertEquals(1, sink.finishCalled);
        assertEquals(1, sink.triples.size());
        assertEquals(0, sink.quads.size());
        Triple t = SSE.parseTriple("(<x> <p> <q>)");
        assertEquals(t, last(sink.triples));
    }
    // Old style, direct to LangRIOT -- very deprecated.
    // NQ version tests that relative URIs remain relative.
    Tokenizer tokenizer = TokenizerText.create().fromString("<x> <p> <q> .").build();
    CatchParserOutput sink = new CatchParserOutput();
    IRIxResolver resolver = IRIs.relativeResolver();
    ParserProfile profile = makeParserProfile(IRIs.relativeResolver(), null, false);
    LangRIOT parser = RiotParsers.createParserNTriples(tokenizer, sink, profile);
    parser.parse();
    assertEquals(1, sink.startCalled);
    assertEquals(1, sink.finishCalled);
    assertEquals(1, sink.triples.size());
    assertEquals(0, sink.quads.size());
    assertEquals(SSE.parseTriple("(<x> <p> <q>)"), last(sink.triples));
}
Also used : Triple(org.apache.jena.graph.Triple) Tokenizer(org.apache.jena.riot.tokens.Tokenizer) IRIxResolver(org.apache.jena.irix.IRIxResolver) Test(org.junit.Test)

Example 9 with IRIxResolver

use of org.apache.jena.irix.IRIxResolver in project jena by apache.

the class RDFParser method makeParserProfile.

// See also RiotLib.profile but this version has RDFParser specific features.
private ParserProfile makeParserProfile(Lang lang) {
    boolean resolve = resolveURIs;
    boolean allowRelative = false;
    boolean checking$ = strict;
    String baseStr = baseURI;
    // Per language tweaks.
    if (sameLang(NTRIPLES, lang) || sameLang(NQUADS, lang)) {
        baseStr = null;
        if (!strict) {
            allowRelative = true;
            checking$ = checking.orElseGet(() -> false);
        } else
            resolve = false;
    } else {
        if (!strict)
            checking$ = checking.orElseGet(() -> true);
        // Setting the resolver directly overrides this.
        if (baseStr == null && resolve)
            baseStr = IRIs.getBaseStr();
    }
    if (sameLang(RDFJSON, lang))
        // The JSON-LD subsystem handles this.
        resolve = false;
    IRIxResolver parserResolver = (resolver != null) ? resolver : IRIxResolver.create().base(baseStr).resolve(resolve).allowRelative(allowRelative).build();
    PrefixMap prefixMap = PrefixMapFactory.create();
    ParserProfileStd parserFactory = new ParserProfileStd(factory, errorHandler, parserResolver, prefixMap, context, checking$, strict);
    return parserFactory;
}
Also used : IRIxResolver(org.apache.jena.irix.IRIxResolver)

Aggregations

IRIxResolver (org.apache.jena.irix.IRIxResolver)9 Test (org.junit.Test)7 Triple (org.apache.jena.graph.Triple)1 IRIx (org.apache.jena.irix.IRIx)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1 Tokenizer (org.apache.jena.riot.tokens.Tokenizer)1