Package org.openrdf.rio

Examples of org.openrdf.rio.RDFWriter


        if(serializer == null) {
            log.warn("could not find serializer for MIME type {}",mimeType);
            throw new UnsupportedExporterException("No serializer for mime type "+mimeType);
        }
        // HINT: This method might be executed outside a transaction!
        RDFWriter handler = Rio.createWriter(serializer,outputStream);
        try {
            RepositoryConnection connection = sesameService.getConnection();
            try {
                if(context == null) {
                    connection.exportStatements(null,null,null,true,handler);
View Full Code Here


            log.warn("could not find serializer for MIME type {}",mimeType);
            throw new UnsupportedExporterException("No serializer for mime type "+mimeType);
        }

        // HINT: This method might be executed outside a transaction!
        RDFWriter handler = Rio.createWriter(serializer,writer);
        try {
            RepositoryConnection connection = sesameService.getConnection();
            try {
                if(context == null) {
                    connection.exportStatements(resource,null,null,true,handler);
View Full Code Here

        if(serializer == null) {
            log.warn("could not find serializer for MIME type {}",mimeType);
            throw new UnsupportedExporterException("No serializer for mime type "+mimeType);
        }
        // HINT: This method might be executed outside a transaction!
        RDFWriter handler = Rio.createWriter(serializer,outputStream);
        try {
            RepositoryConnection connection = sesameService.getConnection();
            try {
                if(context == null) {
                    connection.exportStatements(resource,null,null,true,handler);
View Full Code Here

                //create response serialisation
                StreamingOutput entity = new StreamingOutput() {
                    @Override
                    public void write(OutputStream output) throws IOException, WebApplicationException {
                        RDFWriter writer = Rio.createWriter(serializer, output);
                        try {
                            RepositoryConnection con = versioningService.getSnapshot(date);
                            URI subject = con.getValueFactory().createURI(resource.stringValue());
                            try {
                                con.exportStatements(subject,null,null,true,writer);
View Full Code Here

        DEFINED_WORDS = new HashSet<String>();

        int associationCount = 0;
        OutputStream out = new FileOutputStream(ntriplesFile);
        try {
            RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, out);
            writer.startRDF();
            try {
                BufferedReader b = new BufferedReader(new FileReader(srConciseFile));
                try {
                    String line;
                    while (null != (line = b.readLine())) {
                        if (0 == line.length()) {
                            break;
                        }

                        String subjectWord = normalizeWord(line);

                        // There should be an even number of lines in this file.
                        line = b.readLine();

                        if (isNormalWord(subjectWord)) {
                            String[] cells = line.trim().split("[|]");

                            int totalWeight = 0;

                            for (int i = 1; i < cells.length; i += 2) {
                                totalWeight += Integer.valueOf(cells[i]);
                            }

                            for (int i = 0; i < cells.length; i += 2) {
                                String objectWord = cells[i];
                                float weight = Float.valueOf(cells[i + 1]) / totalWeight;

                                associate(subjectWord, objectWord, weight, writer);
                                associationCount++;
                            }
                        } else {
                            System.err.println(subjectWord + " could not be normalized. No association created.");
                        }
                    }
                } finally {
                    b.close();
                }
            } finally {
                writer.endRDF();
            }
        } finally {
            out.close();
        }
View Full Code Here

        int associationCount = 0;
        int fileCount = 0;
        OutputStream out = new FileOutputStream(ntriplesFile);
        try {
            RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, out);
            writer.startRDF();
            try {
                for (File f : appendixADirectory.listFiles(filter)) {
                    fileCount++;
                    BufferedReader b = new BufferedReader(new FileReader(f));
                    try {
                        // Skip the four header lines
                        for (int i = 0; i < 4; i++) {
                            b.readLine();
                        }

                        String line;
                        while (null != (line = b.readLine())) {
                            // If we've reached the footer, we're done with this file.
                            if (line.startsWith("<")) {
                                break;
                            }

                            String[] cells = line.split(", ");
                            String subjectWord = cells[0];
                            String objectWord = cells[1];
                            float weight = Float.valueOf(cells[5]);

                            associate(subjectWord, objectWord, weight, writer);

                            associationCount++;
                        }
                    } finally {
                        b.close();
                    }
                }
            } finally {
                writer.endRDF();
            }
        } finally {
            out.close();
        }
View Full Code Here

    public static SesameOutputAdapter createOutputAdapter(
            final OutputStream out,
            final RDFFormat format)
            throws RippleException {
        RDFWriter writer;

        try {
            // Note: a comment by Jeen suggests that a new writer should be created
            //       for each use:
            //       http://www.openrdf.org/forum/mvnforum/viewthread?thread=785#3159
View Full Code Here

     * @throws RDFHandlerException
     */
    private InputStream writeJSONLD(Model statements) throws RDFHandlerException {
        final StringWriter writer = new StringWriter();

        final RDFWriter jsonldWriter = new SesameJSONLDWriter(writer);
        jsonldWriter.startRDF();
        for (final Namespace prefix : statements.getNamespaces()) {
            jsonldWriter.handleNamespace(prefix.getPrefix(), prefix.getName());
        }
        for (final Statement nextStatement : statements) {
            jsonldWriter.handleStatement(nextStatement);
        }
        jsonldWriter.endRDF();

        // System.out.println(writer.toString());

        return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
    }
View Full Code Here

        Literal plainLit = vf.createLiteral("plain", XMLSchema.STRING);

        Statement st1 = vf.createStatement(uri1, uri2, plainLit);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
        rdfWriter.getWriterConfig().set(JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT);
        rdfWriter.handleNamespace("ex", exNs);
        rdfWriter.startRDF();
        rdfWriter.handleStatement(st1);
        rdfWriter.endRDF();

        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        RDFParser rdfParser = rdfParserFactory.getParser();
        ParserConfig config = new ParserConfig();
        config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
View Full Code Here

                    StreamingOutput entity = new StreamingOutput() {
                        @Override
                        public void write(OutputStream output) throws IOException, WebApplicationException {
                            // FIXME: This method is executed AFTER the @Transactional!
                            RDFWriter writer = Rio.createWriter(serializer,output);
                            try {
                                RepositoryConnection connection = sesameService.getConnection();
                                try {
                                    connection.begin();
                                    connection.exportStatements(subject,null,null,true,writer);
View Full Code Here

TOP

Related Classes of org.openrdf.rio.RDFWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.