Search in sources :

Example 1 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class JSONLDWriterBackgroundTest method testRoundTripNamespaces.

@Test
public void testRoundTripNamespaces() throws Exception {
    String exNs = "http://example.org/";
    IRI uri1 = vf.createIRI(exNs, "uri1");
    IRI uri2 = vf.createIRI(exNs, "uri2");
    Literal plainLit = vf.createLiteral("plain", XMLSchema.STRING);
    Statement st1 = vf.createStatement(uri1, uri2, plainLit);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
    rdfWriter.getWriterConfig().set(JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT);
    rdfWriter.handleNamespace("ex", exNs);
    rdfWriter.startRDF();
    rdfWriter.handleStatement(st1);
    rdfWriter.endRDF();
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    RDFParser rdfParser = rdfParserFactory.getParser();
    ParserConfig config = new ParserConfig();
    config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
    config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true);
    rdfParser.setParserConfig(config);
    rdfParser.setValueFactory(vf);
    Model model = new LinkedHashModel();
    rdfParser.setRDFHandler(new StatementCollector(model));
    rdfParser.parse(in, "foo:bar");
    assertEquals("Unexpected number of statements, found " + model.size(), 1, model.size());
    assertTrue("missing namespaced statement", model.contains(st1));
    if (rdfParser.getRDFFormat().supportsNamespaces()) {
        assertTrue("Expected at least one namespace, found " + model.getNamespaces().size(), model.getNamespaces().size() >= 1);
        assertEquals(exNs, model.getNamespace("ex").get().getName());
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) ByteArrayInputStream(java.io.ByteArrayInputStream) Statement(org.eclipse.rdf4j.model.Statement) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Literal(org.eclipse.rdf4j.model.Literal) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) RDFWriterTest(org.eclipse.rdf4j.rio.RDFWriterTest) Test(org.junit.Test)

Example 2 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class ModelsTest method setUp.

@Before
public void setUp() {
    model1 = new LinkedHashModel();
    model2 = new LinkedHashModel();
    foo = VF.createIRI("http://example.org/foo");
    bar = VF.createIRI("http://example.org/bar");
    baz = VF.createBNode();
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Before(org.junit.Before)

Example 3 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RepositoryConfigUtil method updateRepositoryConfigs.

/**
 * Update the specified RepositoryConnection with the specified set of RepositoryConfigs. This will
 * overwrite all existing configurations in the Repository that have a Repository ID occurring in these
 * RepositoryConfigs. Note: this method does NOT commit the updates on the connection.
 *
 * @param con
 *        the repository connection to perform the update on
 * @param configs
 *        The RepositoryConfigs that should be added to or updated in the Repository. The
 *        RepositoryConfig's ID may already occur in the Repository, in which case all previous
 *        configuration data for that Repository will be cleared before the RepositoryConfig is added.
 * @throws RepositoryException
 * @throws RepositoryConfigException
 */
@Deprecated
public static void updateRepositoryConfigs(RepositoryConnection con, RepositoryConfig... configs) throws RepositoryException, RepositoryConfigException {
    ValueFactory vf = con.getRepository().getValueFactory();
    con.begin();
    for (RepositoryConfig config : configs) {
        Resource context = getContext(con, config.getID());
        if (context != null) {
            con.clear(context);
        } else {
            context = vf.createBNode();
        }
        con.add(context, RDF.TYPE, REPOSITORY_CONTEXT);
        Model graph = new LinkedHashModel();
        config.export(graph);
        con.add(graph, context);
    }
    con.commit();
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 4 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class TriGParserCustomTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    vf = SimpleValueFactory.getInstance();
    settingsNoVerifyLangTag = new ParserConfig();
    settingsNoVerifyLangTag.set(BasicParserSettings.VERIFY_LANGUAGE_TAGS, false);
    errors = new ParseErrorCollector();
    parser = Rio.createParser(RDFFormat.TRIG);
    statementCollector = new StatementCollector(new LinkedHashModel());
    parser.setRDFHandler(statementCollector);
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) Before(org.junit.Before)

Example 5 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RDFXMLParserCustomTest method testEntityExpansionNoSecureProcessing.

/**
 * Test with Secure processing setting off.
 * <p>
 * IMPORTANT: Only turn this on to verify it is still working, as there is no way to safely perform this
 * test.
 * <p>
 * WARNING: This test will cause an OutOfMemoryException when it eventually fails, as it will eventually
 * fail.
 *
 * @throws Exception
 */
@Ignore
@Test(timeout = 10000)
public void testEntityExpansionNoSecureProcessing() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).set(XMLParserSettings.SECURE_PROCESSING, false).setParseErrorListener(errorCollector);
    try {
        // IMPORTANT: This will not use the entity limit
        aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity expansions in this document; this is the limit imposed by the"));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)30 Model (org.eclipse.rdf4j.model.Model)23 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)11 Test (org.junit.Test)11 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)7 ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)6 Statement (org.eclipse.rdf4j.model.Statement)5 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)5 Literal (org.eclipse.rdf4j.model.Literal)4 Before (org.junit.Before)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 IRI (org.eclipse.rdf4j.model.IRI)3 Resource (org.eclipse.rdf4j.model.Resource)3 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)2 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)2 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2