Search in sources :

Example 6 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf-transform by AtesComp.

the class PreviewRDFRecordVisitor method visit.

public boolean visit(Project theProject, Record theRecord) {
    // Test for end of sample...
    if (this.iLimit > 0 && this.iCount >= this.iLimit) {
        // ...stop visitation process
        return true;
    }
    try {
        if (Util.isDebugMode())
            PreviewRDFRecordVisitor.logger.info("DEBUG: Visiting Record: " + theRecord.recordIndex + " on count: " + this.iCount);
        ParsedIRI baseIRI = this.getRDFTransform().getBaseIRI();
        RepositoryConnection theConnection = this.getModel().getConnection();
        ValueFactory theFactory = theConnection.getValueFactory();
        List<ResourceNode> listRoots = this.getRDFTransform().getRoots();
        for (ResourceNode root : listRoots) {
            root.createStatements(baseIRI, theFactory, theConnection, theProject, theRecord);
            if (Util.isDebugMode()) {
                PreviewRDFRecordVisitor.logger.info("DEBUG:   " + "Root: " + root.getNodeName() + "(" + root.getNodeType() + ")  " + "Size: " + theConnection.size());
            }
        }
        this.iCount += 1;
        // Flush all statements...
        this.flushStatements();
    } catch (RepositoryException ex) {
        PreviewRDFRecordVisitor.logger.error("Connection Issue: ", ex);
        if (Util.isVerbose() || Util.isDebugMode())
            ex.printStackTrace();
        // ...stop visitation process
        return true;
    } catch (RDFHandlerException ex) {
        PreviewRDFRecordVisitor.logger.error("Flush Issue: ", ex);
        if (Util.isVerbose() || Util.isDebugMode())
            ex.printStackTrace();
        // ...stop visitation process
        return true;
    }
    return false;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ParsedIRI(org.eclipse.rdf4j.common.net.ParsedIRI) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) ResourceNode(com.google.refine.rdf.model.ResourceNode)

Example 7 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf-transform by AtesComp.

the class PreviewRDFRowVisitor method visit.

public boolean visit(Project theProject, int iRowIndex, Row theRow) {
    // Test for end of sample...
    if (this.iLimit > 0 && this.iCount >= this.iLimit) {
        // ...stop visitation process
        return true;
    }
    try {
        if (Util.isDebugMode())
            PreviewRDFRowVisitor.logger.info("DEBUG: Visiting Row: " + iRowIndex + " on count: " + this.iCount);
        ParsedIRI baseIRI = this.getRDFTransform().getBaseIRI();
        RepositoryConnection theConnection = this.getModel().getConnection();
        ValueFactory theFactory = theConnection.getValueFactory();
        List<ResourceNode> listRoots = this.getRDFTransform().getRoots();
        for (ResourceNode root : listRoots) {
            root.createStatements(baseIRI, theFactory, theConnection, theProject, iRowIndex);
            if (Util.isDebugMode()) {
                PreviewRDFRowVisitor.logger.info("DEBUG:   " + "Root: " + root.getNodeName() + "(" + root.getNodeType() + ")  " + "Size: " + theConnection.size());
            }
        }
        this.iCount += 1;
        this.flushStatements();
    } catch (RepositoryException ex) {
        PreviewRDFRowVisitor.logger.error("Connection Issue: ", ex);
        if (Util.isVerbose() || Util.isDebugMode())
            ex.printStackTrace();
        // ...stop visitation process
        return true;
    } catch (RDFHandlerException ex) {
        PreviewRDFRowVisitor.logger.error("Flush Issue: ", ex);
        if (Util.isVerbose() || Util.isDebugMode())
            ex.printStackTrace();
        // ...stop visitation process
        return true;
    }
    return false;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ParsedIRI(org.eclipse.rdf4j.common.net.ParsedIRI) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) ResourceNode(com.google.refine.rdf.model.ResourceNode)

Example 8 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project corese by Wimmics.

the class Rdf4jExperimentations method testRio.

@Test
public void testRio() throws IOException {
    InputStream input_stream = Rdf4jExperimentations.class.getResourceAsStream("peopleWork.ttl");
    CoreseModel model = new CoreseModel();
    RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
    rdfParser.setRDFHandler(new StatementCollector(model));
    try {
        rdfParser.parse(input_stream);
    } catch (IOException e) {
    // handle IO problems (e.g. the file could not be read)
    } catch (RDFParseException e) {
    // handle unrecoverable parse error
    } catch (RDFHandlerException e) {
    // handle a problem encountered by the RDFHandler
    } finally {
        try {
            input_stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    URL url_output = Rdf4jExperimentations.class.getResource("peopleWorkResult.ttl");
    FileOutputStream out = new FileOutputStream(url_output.getPath());
    try {
        Rio.write(model, out, RDFFormat.TURTLE);
    } finally {
        out.close();
    }
}
Also used : CoreseModel(fr.inria.corese.rdf4j.CoreseModel) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) InputStream(java.io.InputStream) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RDFParser(org.eclipse.rdf4j.rio.RDFParser) URL(java.net.URL) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 9 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project incubator-streampipes by apache.

the class Deployment method getDescriptionAsJsonLd.

@POST
@Path("/description/jsonld")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response getDescriptionAsJsonLd(@FormDataParam("config") String config, @FormDataParam("model") String model) {
    DeploymentConfiguration deploymentConfig = fromJson(config);
    NamedStreamPipesEntity element = getElement(deploymentConfig, model);
    try {
        return Response.ok(JsonLdUtils.asString(new JsonLdTransformer().toJsonLd(element))).build();
    } catch (RDFHandlerException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException | ClassNotFoundException | InvalidRdfException e) {
        return Response.serverError().build();
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) NamedStreamPipesEntity(org.apache.streampipes.model.base.NamedStreamPipesEntity) InvalidRdfException(io.fogsy.empire.core.empire.annotation.InvalidRdfException) DeploymentConfiguration(org.apache.streampipes.model.client.deployment.DeploymentConfiguration) InvocationTargetException(java.lang.reflect.InvocationTargetException) JsonLdTransformer(org.apache.streampipes.serializers.jsonld.JsonLdTransformer)

Example 10 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project ldp-coap-framework by sisinflab-swot.

the class CoAPLDPResourceManager method getFullResourceTuple.

private String getFullResourceTuple(String res, RDFFormat format) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        RDFWriter writer = Rio.createWriter(format, out);
        writer.startRDF();
        for (String prefix : ns.keySet()) {
            writer.handleNamespace(prefix, ns.get(prefix));
        }
        writeStatement(writer, res);
        writer.endRDF();
        return out.toString();
    } catch (RepositoryException e) {
        e.printStackTrace();
    } catch (RDFHandlerException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)99 IOException (java.io.IOException)51 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)24 Statement (org.eclipse.rdf4j.model.Statement)20 IRI (org.eclipse.rdf4j.model.IRI)19 Resource (org.eclipse.rdf4j.model.Resource)19 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)17 Value (org.eclipse.rdf4j.model.Value)12 RDFLoader (org.eclipse.rdf4j.repository.util.RDFLoader)10 AbstractRDFHandler (org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ParsedIRI (org.eclipse.rdf4j.common.net.ParsedIRI)8 BNode (org.eclipse.rdf4j.model.BNode)8 Literal (org.eclipse.rdf4j.model.Literal)8 RDFParser (org.eclipse.rdf4j.rio.RDFParser)8 HashSet (java.util.HashSet)7 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)7 LpException (com.linkedpipes.etl.executor.api.v1.LpException)5 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)5