org.eclipse.rdf4j.rio.ndjsonld.legacy.NDJSONLDParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rdf4j-rio-jsonld-legacy Show documentation
Show all versions of rdf4j-rio-jsonld-legacy Show documentation
Rio parser and writer implementation for the JSON-LD file format.
/*******************************************************************************
* Copyright (c) 2024 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/
package org.eclipse.rdf4j.rio.ndjsonld.legacy;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.input.BOMInputStream;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.rio.jsonld.legacy.JSONLDParser;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.github.jsonldjava.utils.JsonUtils;
/**
* Introduce a parser capable of parsing Newline Delimited JSON-LD, where each line is a serialized JSON-LD record. The
* format is inspired by Newline Delimited JSON formathttp://ndjson.org/. Even though each line is a separate
* JSON-LD document, the whole document is treated as a single RDF document, having one single BNodes context to
* preserve BNodes identifiers.
*
* @author Desislava Hristova
*/
public class NDJSONLDParser extends JSONLDParser {
/**
* Default constructor
*/
public NDJSONLDParser() {
super();
}
/**
* Creates a RDF4J NDJSONLD Parser using the given {@link ValueFactory} to create new {@link Value}s.
*
* @param valueFactory The ValueFactory to use
*/
public NDJSONLDParser(final ValueFactory valueFactory) {
super(valueFactory);
}
@Override
public RDFFormat getRDFFormat() {
return RDFFormat.NDJSONLD;
}
@Override
protected Object getJSONObject(InputStream in, Reader reader, JsonFactory factory) throws IOException {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy