use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class TestTurtleParser method testParseBNodes.
@Test
public void testParseBNodes() throws Exception {
String data = prefixes + " [ :p :o1,:2 ] . ";
parser.parse(new StringReader(data), baseURI);
assertTrue(errorCollector.getWarnings().isEmpty());
assertTrue(errorCollector.getErrors().isEmpty());
assertTrue(errorCollector.getFatalErrors().isEmpty());
assertFalse(statementCollector.getStatements().isEmpty());
assertEquals(2, statementCollector.getStatements().size());
for (Statement st : statementCollector.getStatements()) {
System.out.println(st);
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class Rio method write.
/**
* Writes the given statements to the given {@link RDFHandler}.
* <p>
* If the collection is a {@link Model}, its namespaces will also be written.
*
* @param model
* A collection of statements, such as a {@link Model}, to be written.
* @throws RDFHandlerException
* Thrown if there is an error writing the statements.
*/
public static void write(Iterable<Statement> model, RDFHandler writer) throws RDFHandlerException {
writer.startRDF();
if (model instanceof NamespaceAware) {
for (Namespace nextNamespace : ((NamespaceAware) model).getNamespaces()) {
writer.handleNamespace(nextNamespace.getPrefix(), nextNamespace.getName());
}
}
for (final Statement st : model) {
writer.handleStatement(st);
}
writer.endRDF();
}
use of org.eclipse.rdf4j.model.Statement 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());
}
use of org.eclipse.rdf4j.model.Statement in project timbuctoo by HuygensING.
the class NquadsUdParser method parseQuad.
private int parseQuad(int character) throws IOException, RDFParseException, RDFHandlerException {
boolean ignoredAnError = false;
try {
character = parseSubject(character);
character = skipWhitespace(character);
character = parsePredicate(character);
character = skipWhitespace(character);
character = parseObject(character);
character = skipWhitespace(character);
// Context is not required
if (character != '.') {
character = parseContext(character);
character = skipWhitespace(character);
}
if (character == -1) {
throwEOFException();
} else if (character != '.') {
reportFatalError("Expected '.', found: " + new String(Character.toChars(character)));
}
character = assertLineTerminates(character);
} catch (RDFParseException rdfpe) {
if (getParserConfig().isNonFatalError(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES)) {
reportError(rdfpe, NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES);
ignoredAnError = true;
} else {
throw rdfpe;
}
}
character = skipLine(character);
if (!ignoredAnError) {
Statement st = createStatement(subject, predicate, object, context);
if (rdfHandler != null) {
rdfHandler.handleStatement(st);
}
}
subject = null;
predicate = null;
object = null;
context = null;
return character;
}
Aggregations