Search in sources :

Example 6 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class RestRDFHelper method exportConceptHdl.

/**
 * Permet de retourner un concept au format défini en passant par un identifiant Handle
 * utilisé pour la négociation de contenu
 *
 * @param ds
 * @param handleId
 * @param format
 * @return
 */
public String exportConceptHdl(HikariDataSource ds, String handleId, String format) {
    RDFFormat rDFFormat = getRDFFormat(format);
    WriteRdf4j writeRdf4j = getConceptFromHandle(ds, handleId);
    if (writeRdf4j == null)
        return null;
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, rDFFormat);
    return out.toString();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 7 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class RestRDFHelper method exportConceptFromId.

/**
 * Permet de retourner un concept au format défini en passant par l'identifiant du concept
 * utilisé pour la négociation de contenu
 *
 * @param ds
 * @param idConcept
 * @param idTheso
 * @param format
 * @return
 */
public String exportConceptFromId(HikariDataSource ds, String idConcept, String idTheso, String format) {
    RDFFormat rDFFormat = getRDFFormat(format);
    WriteRdf4j writeRdf4j = getConceptFromId(ds, idConcept, idTheso);
    if (writeRdf4j == null)
        return null;
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, rDFFormat);
    return out.toString();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 8 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class RestRDFHelper method findNotation.

/**
 * Permet de retourner les concepts qui correspondent à la notation
 * utilisé pour la négociation de contenu
 *
 * @param ds
 * @param idTheso
 * @param format
 * @param value
 * @return
 */
public String findNotation(HikariDataSource ds, String idTheso, String value, String format) {
    RDFFormat rDFFormat = getRDFFormat(format);
    WriteRdf4j writeRdf4j = findNotation__(ds, value, idTheso);
    if (writeRdf4j == null)
        return null;
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, rDFFormat);
    return out.toString();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 9 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class RestRDFHelper method brancheOfConceptsDown.

/**
 * Fonction qui permet de récupérer une branche complète en partant d'un
 * concept et en allant jusqu'à la fin (vers le bas)
 *
 * @param ds
 * @param idConcept
 * @param idTheso
 * @param format
 * @return skos
 */
public String brancheOfConceptsDown(HikariDataSource ds, String idConcept, String idTheso, String format) {
    RDFFormat rDFFormat = getRDFFormat(format);
    WriteRdf4j writeRdf4j = brancheOfConceptsDown__(ds, idConcept, idTheso);
    if (writeRdf4j == null)
        return null;
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, rDFFormat);
    return out.toString();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat)

Example 10 with RDFFormat

use of org.eclipse.rdf4j.rio.RDFFormat in project opentheso by miledrousset.

the class exportConceptTest method exportConcept.

@Test
public void exportConcept() {
    String idTheso = "TH_1";
    String idArk = "26678/pcrtj2nMTJw5fg";
    String format = "text/turtle";
    RDFFormat rDFFormat = null;
    String extention = "";
    switch(format) {
        case "application/rdf+xml":
            rDFFormat = RDFFormat.RDFXML;
            extention = ".rdf";
            break;
        case "application/ld+json":
            rDFFormat = RDFFormat.JSONLD;
            extention = ".jsonld";
            break;
        case "text/turtle":
            rDFFormat = RDFFormat.TURTLE;
            extention = ".ttl";
            break;
        case "application/json":
            rDFFormat = RDFFormat.RDFJSON;
            extention = ".json";
            break;
    }
    WriteRdf4j writeRdf4j = loadExportHelper(idTheso, idArk);
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, rDFFormat);
    System.out.println(out.toString());
// file = new ByteArrayContent(out.toByteArray(), "application/xml", idTheso + " " + extention);
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Aggregations

RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)62 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IOException (java.io.IOException)17 WriteRdf4j (mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j)14 InputStream (java.io.InputStream)12 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)11 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)8 FileInputStream (java.io.FileInputStream)7 Model (org.eclipse.rdf4j.model.Model)6 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)6 RDFParser (org.eclipse.rdf4j.rio.RDFParser)5 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)5 Rdf2GoCore (de.knowwe.rdf2go.Rdf2GoCore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)4 ExportRdf4jHelper (mom.trd.opentheso.core.exports.rdf4j.ExportRdf4jHelper)4 IRI (org.eclipse.rdf4j.model.IRI)4 Statement (org.eclipse.rdf4j.model.Statement)4 Test (org.junit.Test)4