Search in sources :

Example 16 with LinkedHashModel

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

the class CustomTurtleParserTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    vf = ValueFactoryImpl.getInstance();
    settingsNoVerifyLangTag = new ParserConfig();
    settingsNoVerifyLangTag.set(BasicParserSettings.VERIFY_LANGUAGE_TAGS, false);
    errors = new ParseErrorCollector();
    parser = Rio.createParser(RDFFormat.TURTLE);
    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 17 with LinkedHashModel

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

the class CustomTurtleParserTest method testLiteralWithNewlines.

@Test
public void testLiteralWithNewlines() throws Exception {
    String namespace = "http://www.foo.com/bar#";
    String okLiteralString = "Literal \n without \n new line at the beginning. \n ";
    String errLiteralString = "\n Literal \n with \n new line at the beginning. \n ";
    IRI mySubject = vf.createIRI(namespace, "Subject");
    IRI myPredicate = vf.createIRI(namespace, "Predicate");
    Literal myOkObject = vf.createLiteral(okLiteralString);
    Literal myErrObject = vf.createLiteral(errLiteralString);
    StringWriter out = new StringWriter();
    Model model = new LinkedHashModel();
    model.add(mySubject, myPredicate, myOkObject);
    model.add(mySubject, myPredicate, myErrObject);
    Rio.write(model, out, RDFFormat.TURTLE);
    String str = out.toString();
    System.err.println(str);
    assertTrue("okLiteralString not found", str.contains(okLiteralString));
    assertTrue("errLiteralString not found", str.contains(errLiteralString));
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) StringWriter(java.io.StringWriter) Literal(org.eclipse.rdf4j.model.Literal) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Test(org.junit.Test)

Example 18 with LinkedHashModel

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

the class HTTPRepositoryConnection method add.

@Override
public void add(Statement st, Resource... contexts) throws RepositoryException {
    if (!isActive()) {
        // operation is not part of a transaction - just send directly
        OpenRDFUtil.verifyContextNotNull(contexts);
        final Model m = new LinkedHashModel();
        if (contexts.length == 0) {
            // if no context is specified in the method call, statement's own
            // context (if any) is used.
            m.add(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
        } else {
            m.add(st.getSubject(), st.getPredicate(), st.getObject(), contexts);
        }
        addModel(m);
    } else {
        super.add(st, contexts);
    }
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Example 19 with LinkedHashModel

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

the class ModelBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    model = new LinkedHashModel();
    testBuilder = new ModelBuilder(model);
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Before(org.junit.Before)

Example 20 with LinkedHashModel

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

the class QueryResults method asModel.

/**
 * Get a {@link Model} containing all elements obtained from the specified query result.
 *
 * @param iteration
 *        the source iteration to get the statements from. This can be a {@link GraphQueryResult}, a
 *        {@link RepositoryResult<Statement>}, or any other instance of {@link CloseableIteration
 *        <Statement>}
 * @return a {@link Model} containing all statements obtained from the specified source iteration.
 */
public static Model asModel(CloseableIteration<? extends Statement, ? extends RDF4JException> iteration) throws QueryEvaluationException {
    Model model = new LinkedHashModel();
    addAll(iteration, model);
    return model;
}
Also used : Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

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