it.uniroma2.art.semanticturkey.extension.impl.rdflifter.rdfdeserializer.RDFDeserializingLifter Maven / Gradle / Ivy
package it.uniroma2.art.semanticturkey.extension.impl.rdflifter.rdfdeserializer;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.repository.util.RDFLoader;
import org.eclipse.rdf4j.rio.ParserConfig;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFHandler;
import it.uniroma2.art.semanticturkey.extension.extpts.rdflifter.LifterContext;
import it.uniroma2.art.semanticturkey.extension.extpts.rdflifter.LiftingException;
import it.uniroma2.art.semanticturkey.extension.extpts.rdflifter.RDFLifter;
import it.uniroma2.art.semanticturkey.extension.extpts.reformattingexporter.ClosableFormattedResource;
import it.uniroma2.art.semanticturkey.utilities.RDF4JUtilities;
/**
* An {@link RDFLifter} that deserializes RDF data according to the provided serialization format
*
* @author Manuel Fiorelli
*/
public class RDFDeserializingLifter implements RDFLifter {
@Override
public void lift(ClosableFormattedResource sourceFormattedResource, String format,
RDFHandler targetRDFHandler, LifterContext lifterContext) throws LiftingException, IOException {
if (format == null) {
throw new LiftingException("RDF format was not specified");
}
RDFFormat rdfFormat = RDF4JUtilities.getRDFFormat(format);
RDFLoader rdfLoader = new RDFLoader(new ParserConfig(), SimpleValueFactory.getInstance());
try (InputStream is = sourceFormattedResource.getInputStream()) {
rdfLoader.load(is, "", rdfFormat, targetRDFHandler);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy