Package org.apache.any23.writer

Examples of org.apache.any23.writer.TripleHandler


                + ":bar : foo:bar .                           ";
        // The second argument of StringDocumentSource() must be a valid URI.
        /* 3 */DocumentSource source = new StringDocumentSource(content,
                "http://host.com/service");
        /* 4 */ByteArrayOutputStream out = new ByteArrayOutputStream();
        /* 5 */TripleHandler handler = new NTriplesWriter(out);
        try {
            /* 6 */runner.extract(source, handler);
        } finally {
            /* 7 */handler.close();
        }
        /* 8 */String nt = out.toString("UTF-8");

        /*
         * <http://example.org/ns#bar> <http://example.org/ns#>
View Full Code Here


        /* 2 */runner.setHTTPUserAgent("test-user-agent");
        /* 3 */HTTPClient httpClient = runner.getHTTPClient();
        /* 4 */DocumentSource source = new HTTPDocumentSource(httpClient,
                "http://dbpedia.org/resource/Trento");
        /* 5 */ByteArrayOutputStream out = new ByteArrayOutputStream();
        /* 6 */TripleHandler handler = new NTriplesWriter(out);
        try {
            /* 7 */runner.extract(source, handler);
        } finally {
            /* 8 */handler.close();
        }
        /* 9 */String n3 = out.toString("UTF-8");

        /*
         * <http://dbpedia.org/resource/Trent>
 
View Full Code Here

            protected int getSoTimeout() {
                return 2000;
            }
        });
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        TripleHandler handler = new NTriplesWriter(byteArrayOutputStream);
        TripleHandler rdfWriter = new IgnoreAccidentalRDFa(handler);
        ReportingTripleHandler reporting = new ReportingTripleHandler(rdfWriter);

        DocumentSource source = getDocumentSourceFromResource(
                "/html/rdfa/ansa_2010-02-26_12645863.html",
                "http://host.com/service");
View Full Code Here

        runner.setHTTPUserAgent("test-user-agent");
        HTTPClient httpClient = runner.getHTTPClient();
        DocumentSource source = new HTTPDocumentSource(httpClient,
                "http://products.semweb.bestbuy.com/y/products/7590289/");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        TripleHandler handler = new NTriplesWriter(out);
        runner.extract(source, handler);
        String n3 = out.toString("UTF-8");

        logger.debug("N3 " + n3);
        Assert.assertTrue(n3.length() > 0);
View Full Code Here

        final String content = FileUtils
                .readResourceContent("/html/rdfa/rdfa-issue186-1.xhtml");
        final DocumentSource source = new StringDocumentSource(content,
                "http://base.com");
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final TripleHandler handler = new NTriplesWriter(out);
        runner.extract(source, handler);
        String n3 = out.toString("UTF-8");
        logger.debug(n3);
    }
View Full Code Here

        final String content = FileUtils
                .readResourceContent("/html/rdfa/rdfa-issue186-2.xhtml");
        final DocumentSource source = new StringDocumentSource(content,
                "http://richard.cyganiak.de/");
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final TripleHandler handler = new NTriplesWriter(out);
        runner.extract(source, handler);
        final String n3 = out.toString("UTF-8");
        logger.debug(n3);
    }
View Full Code Here

        final String content = FileUtils
                .readResourceContent("/rdf/rdf-issue183.ttl");
        final DocumentSource source = new StringDocumentSource(content,
                "http://base.com");
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final TripleHandler handler = new NTriplesWriter(out);
        any23.extract(source, handler);
        handler.close();
        final String n3 = out.toString("UTF-8");

        logger.debug(n3);
        Assert.assertFalse(
                "Should not contain triple with http://vocab.sindice.net/date",
View Full Code Here

    public String getExampleOutput() throws IOException, ExtractionException {
        if (factory.getExampleInput() == null) {
            return null;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        TripleHandler writer = new TurtleWriter(out);
        new SingleDocumentExtraction(
                new StringDocumentSource(getExampleInput(), getExampleURI()),
                factory,
                writer).run();
        try {
            writer.close();
        } catch (TripleHandlerException e) {
            throw new ExtractionException("Error while closing the triple handler", e);
        }
        return out.toString("utf-8");
    }
View Full Code Here

            }
        }
    }

    private boolean initRdfWriter(String format, boolean report, boolean annotate) throws IOException {
        final WriterFactory factory = getFormatWriter(format);
        if (factory == null) {
            sendError(
                    400,
                    "Invalid format '" + format + "', try one of: [rdfxml, turtle, ntriples, nquads, trix, json]",
                    null,
                    null,
                    report
            );
            return false;
        }
        FormatWriter fw = factory.getRdfWriter(byteOutStream);
        fw.setAnnotated(annotate);
        outputMediaType = factory.getMimeType();
        List<TripleHandler> tripleHandlers = new ArrayList<TripleHandler>();
        tripleHandlers.add(new IgnoreAccidentalRDFa(fw));
        tripleHandlers.add(new CountingTripleHandler());
        rdfWriter = new CompositeTripleHandler(tripleHandlers);
        reporter = new ReportingTripleHandler(rdfWriter);
View Full Code Here

        } else if("json".equals(format)) {
            finalFormat = "json";
        } else {
            return null;
        }
        final WriterFactory writer = writerRegistry.getWriterByIdentifier(finalFormat);
        return writer;
    }
View Full Code Here

TOP

Related Classes of org.apache.any23.writer.TripleHandler

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.