Search in sources :

Example 1 with RDFParserFactory

use of org.openrdf.rio.RDFParserFactory in project blueprints by tinkerpop.

the class SparqlRepositorySailGraph method ignoreDatatypesInAllParsers.

// wrap RDF parser factories such that they ignore invalid values in data-typed literals
// (e.g. a value of "fish" for an xsd:integer literal,
// or a value of 1995-01-01T00:00:00+02:00 for an xsd:gYear literal).
// The default behavior is to throw an exception when bad literals are encountered,
// resulting in failure.
private static void ignoreDatatypesInAllParsers() {
    RDFParserRegistry r = RDFParserRegistry.getInstance();
    Collection<RDFParserFactory> oldFactories = new LinkedList<RDFParserFactory>();
    Collection<RDFParserFactory> newFactories = new LinkedList<RDFParserFactory>();
    for (final RDFFormat f : r.getKeys()) {
        final RDFParserFactory pf = r.get(f);
        pf.getParser().setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);
        RDFParserFactory pfn = new RDFParserFactory() {

            public RDFFormat getRDFFormat() {
                return f;
            }

            public RDFParser getParser() {
                RDFParser p = pf.getParser();
                p.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);
                return p;
            }
        };
        oldFactories.add(pf);
        newFactories.add(pfn);
    }
    for (RDFParserFactory pf : oldFactories) {
        r.remove(pf);
    }
    for (RDFParserFactory pfn : newFactories) {
        r.add(pfn);
    }
}
Also used : RDFParserFactory(org.openrdf.rio.RDFParserFactory) RDFParser(org.openrdf.rio.RDFParser) RDFParserRegistry(org.openrdf.rio.RDFParserRegistry) LinkedList(java.util.LinkedList) RDFFormat(org.openrdf.rio.RDFFormat)

Aggregations

LinkedList (java.util.LinkedList)1 RDFFormat (org.openrdf.rio.RDFFormat)1 RDFParser (org.openrdf.rio.RDFParser)1 RDFParserFactory (org.openrdf.rio.RDFParserFactory)1 RDFParserRegistry (org.openrdf.rio.RDFParserRegistry)1