Search in sources :

Example 11 with ParserConfig

use of org.eclipse.rdf4j.rio.ParserConfig in project rdf4j by eclipse.

the class JSONLDInternalTripleCallbackTest method triplesTest.

@Test
public void triplesTest() throws JsonLdError, IOException {
    // String inputstring =
    // "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone Device\"}}";
    final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
    final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
    final Object input = JsonUtils.fromString(inputstring);
    final Model graph = new LinkedHashModel();
    final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
    final ParserConfig parserConfig = new ParserConfig();
    final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(new StatementCollector(graph), SimpleValueFactory.getInstance(), parserConfig, parseErrorListener, nodeID -> SimpleValueFactory.getInstance().createBNode(nodeID), () -> SimpleValueFactory.getInstance().createBNode());
    JsonLdProcessor.toRDF(input, callback);
    final Iterator<Statement> statements = graph.iterator();
    // contains only one statement (type)
    while (statements.hasNext()) {
        final Statement stmt = statements.next();
        System.out.println(stmt.toString());
        assertEquals("Output was not as expected", stmt.toString(), expectedString);
    }
    assertEquals(0, parseErrorListener.getFatalErrors().size());
    assertEquals(0, parseErrorListener.getErrors().size());
    assertEquals(0, parseErrorListener.getWarnings().size());
}
Also used : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Statement(org.eclipse.rdf4j.model.Statement) 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) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) Test(org.junit.Test)

Aggregations

ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)11 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)9 Test (org.junit.Test)8 Model (org.eclipse.rdf4j.model.Model)7 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)6 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)6 StringReader (java.io.StringReader)3 Statement (org.eclipse.rdf4j.model.Statement)3 RDFParser (org.eclipse.rdf4j.rio.RDFParser)3 ParseErrorLogger (org.eclipse.rdf4j.rio.helpers.ParseErrorLogger)3 Before (org.junit.Before)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IRI (org.eclipse.rdf4j.model.IRI)2 Literal (org.eclipse.rdf4j.model.Literal)2 NamespaceImpl (org.eclipse.rdf4j.model.impl.NamespaceImpl)2 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)2 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)2 RDFWriterTest (org.eclipse.rdf4j.rio.RDFWriterTest)2 QueryResultParseException (org.eclipse.rdf4j.query.resultio.QueryResultParseException)1