use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class StatementCollectorTest method testStatementCollectorCollectionModel.
/**
* Test method for
* {@link org.eclipse.rdf4j.rio.helpers.StatementCollector#StatementCollector(java.util.Collection)} .
*/
@Test
public final void testStatementCollectorCollectionModel() throws Exception {
Model testList = new LinkedHashModel();
StatementCollector collector = new StatementCollector(testList);
// Actual variable is exactly the same, although it could be theoretically
// wrapped and still be consistent
assertTrue(testList == collector.getStatements());
assertNotNull(collector.getNamespaces());
assertTrue(testList.getNamespaces().isEmpty());
assertTrue(collector.getNamespaces().isEmpty());
collector.handleNamespace("ns1", "http://example.org/ns1#");
assertFalse(testList.getNamespaces().isEmpty());
assertFalse(collector.getNamespaces().isEmpty());
assertTrue(collector.getNamespaces().containsKey("ns1"));
assertTrue(collector.getNamespaces().containsValue("http://example.org/ns1#"));
assertTrue(testList.getNamespaces().iterator().next().getPrefix().equals("ns1"));
assertTrue(testList.getNamespaces().iterator().next().getName().equals("http://example.org/ns1#"));
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class StatementCollectorTest method testStatementCollectorCollectionModelMapIndependent.
/**
* Test method for
* {@link org.eclipse.rdf4j.rio.helpers.StatementCollector#StatementCollector(java.util.Collection, java.util.Map)}
* .
*/
@Test
public final void testStatementCollectorCollectionModelMapIndependent() throws Exception {
Model testList = new LinkedHashModel();
Map<String, String> testNamespaces = new LinkedHashMap<String, String>();
StatementCollector collector = new StatementCollector(testList, testNamespaces);
// Actual variable is exactly the same, although it could be theoretically
// wrapped and still be consistent
assertTrue(testList == collector.getStatements());
assertTrue(testNamespaces == collector.getNamespaces());
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class Rio method parse.
/**
* Adds RDF data from a {@link Reader} to a {@link Model}, optionally to one or more named contexts.
* <b>Note: using a Reader to upload byte-based data means that you have to be careful not to destroy the
* data's character encoding by enforcing a default character encoding upon the bytes. If possible, adding
* such data using an InputStream is to be preferred.</b>
*
* @param reader
* A Reader from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param settings
* The {@link ParserConfig} containing settings for configuring the parser.
* @param valueFactory
* The {@link ValueFactory} used by the parser to create statements.
* @param errors
* The {@link ParseErrorListener} used by the parser to signal errors, including errors that do not
* generate an {@link RDFParseException}.
* @param contexts
* The contexts to add the data to. If one or more contexts are specified the data is added to
* these contexts, ignoring any context information in the data itself.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the reader.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(Reader reader, String baseURI, RDFFormat dataFormat, ParserConfig settings, ValueFactory valueFactory, ParseErrorListener errors, Resource... contexts) throws IOException, RDFParseException, UnsupportedRDFormatException {
Model result = new LinkedHashModel();
RDFParser parser = createParser(dataFormat, valueFactory);
parser.setParserConfig(settings);
parser.setParseErrorListener(errors);
parser.setRDFHandler(new ContextStatementCollector(result, valueFactory, contexts));
// LinkedHashModel and ContextStatementCollector should not throw
// RDFHandlerException exceptions
parser.parse(reader, baseURI);
return result;
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.
the class Rio method parse.
/**
* Adds RDF data from an {@link InputStream} to a {@link Model}, optionally to one or more named contexts.
*
* @param in
* An InputStream from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param settings
* The {@link ParserConfig} containing settings for configuring the parser.
* @param valueFactory
* The {@link ValueFactory} used by the parser to create statements.
* @param errors
* The {@link ParseErrorListener} used by the parser to signal errors, including errors that do not
* generate an {@link RDFParseException}.
* @param contexts
* The contexts to add the data to. If one or more contexts are supplied the method ignores
* contextual information in the actual data. If no contexts are supplied the contextual
* information in the input stream is used, if no context information is available the data is
* added without any context.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the input stream.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(InputStream in, String baseURI, RDFFormat dataFormat, ParserConfig settings, ValueFactory valueFactory, ParseErrorListener errors, Resource... contexts) throws IOException, RDFParseException, UnsupportedRDFormatException {
Model result = new LinkedHashModel();
RDFParser parser = createParser(dataFormat, valueFactory);
parser.setParserConfig(settings);
parser.setParseErrorListener(errors);
parser.setRDFHandler(new ContextStatementCollector(result, valueFactory, contexts));
// LinkedHashModel and ContextStatementCollector should not throw
// RDFHandlerException exceptions
parser.parse(in, baseURI);
return result;
}
use of org.eclipse.rdf4j.model.impl.LinkedHashModel 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());
}
Aggregations