/** * Create a parser for the given format, turning off some of the stricter configuration settings so we * can handle more messy data without errors. * @param format * @return */ private RDFParser createParser(RDFFormat format) { RDFParser parser = Rio.createParser(format); parser.getParserConfig().addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES); parser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); parser.getParserConfig().addNonFatalError(BasicParserSettings.NORMALIZE_DATATYPE_VALUES); return parser; }
/** * Create a parser for the given format, turning off some of the stricter configuration settings so we * can handle more messy data without errors. * @param format * @return */ private RDFParser createParser(RDFFormat format) { RDFParser parser = Rio.createParser(format); parser.getParserConfig().addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES); parser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); parser.getParserConfig().addNonFatalError(BasicParserSettings.NORMALIZE_DATATYPE_VALUES); return parser; }
public SparqlSession(HttpClient client, ExecutorService executor) { this.httpClient = client; this.httpContext = new HttpClientContext(); this.executor = executor; valueFactory = SimpleValueFactory.getInstance(); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); CookieStore cookieStore = new BasicCookieStore(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109); // parser used for processing server response data should be lenient parserConfig.addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES); parserConfig.addNonFatalError(BasicParserSettings.VERIFY_LANGUAGE_TAGS); }
/** * Test method for * {@link org.openrdf.rio.ParserConfig#addNonFatalError(org.openrdf.rio.RioSetting)} * . */ @Test public final void testAddNonFatalError() { ParserConfig testConfig = new ParserConfig(); assertTrue(testConfig.getNonFatalErrors().isEmpty()); testConfig.addNonFatalError(BasicParserSettings.PRESERVE_BNODE_IDS); assertTrue(testConfig.getNonFatalErrors().contains(BasicParserSettings.PRESERVE_BNODE_IDS)); }
/** * Test method for {@link org.openrdf.rio.ParserConfig#getNonFatalErrors()}. */ @Test public final void testGetNonFatalErrors() { ParserConfig testConfig = new ParserConfig(); assertTrue(testConfig.getNonFatalErrors().isEmpty()); testConfig.addNonFatalError(BasicParserSettings.PRESERVE_BNODE_IDS); assertFalse(testConfig.getNonFatalErrors().isEmpty()); }
@Deprecated @Override public void setStopAtFirstError(boolean stopAtFirstError) { getParserConfig().set(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES, stopAtFirstError); if (!stopAtFirstError) { getParserConfig().addNonFatalError(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES); } else { // TODO: Add a ParserConfig.removeNonFatalError function to avoid // this Set<RioSetting<?>> set = new HashSet<RioSetting<?>>(getParserConfig().getNonFatalErrors()); set.remove(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES); getParserConfig().setNonFatalErrors(set); } }
/** * Test method for * {@link org.openrdf.rio.ParserConfig#isNonFatalError(org.openrdf.rio.RioSetting)} * . */ @Test public final void testIsNonFatalError() { ParserConfig testConfig = new ParserConfig(); assertTrue(testConfig.getNonFatalErrors().isEmpty()); assertFalse(testConfig.isNonFatalError(BasicParserSettings.PRESERVE_BNODE_IDS)); testConfig.addNonFatalError(BasicParserSettings.PRESERVE_BNODE_IDS); assertTrue(testConfig.isNonFatalError(BasicParserSettings.PRESERVE_BNODE_IDS)); }
/** * Test method for {@link org.openrdf.rio.ParserConfig#stopAtFirstError()}. * Test specifically for SES-1947 */ @Test public final void testStopAtFirstError() { ParserConfig testConfig = new ParserConfig(); assertTrue(testConfig.stopAtFirstError()); testConfig.addNonFatalError(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES); assertFalse(testConfig.stopAtFirstError()); }
@Test public void testExceptionHandlingWithoutStopAtFirstError() throws Exception { String data = "invalid nt"; RDFParser ntriplesParser = createRDFParser(); ntriplesParser.getParserConfig().addNonFatalError(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES); ntriplesParser.getParserConfig().set(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES, Boolean.TRUE); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); ntriplesParser.parse(new StringReader(data), NTRIPLES_TEST_URL); assertEquals(0, model.size()); assertEquals(0, model.subjects().size()); assertEquals(0, model.predicates().size()); assertEquals(0, model.objects().size()); }
/** * Tests whether an known language with the message no fail. */ @Test public final void testKnownLanguageWithMessageNoFailCase1() throws Exception { Model expectedModel = getTestModel(KNOWN_LANGUAGE_VALUE, KNOWN_LANGUAGE_TAG); InputStream input = getKnownLanguageStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an known language with the correct settings will both * generate no message and not fail when addNonFatalError is called with the * given setting. */ @Test public final void testKnownLanguageNoMessageNoFailCase4() throws Exception { Model expectedModel = getTestModel(KNOWN_LANGUAGE_VALUE, KNOWN_LANGUAGE_TAG); InputStream input = getKnownLanguageStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, false); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an known datatype with the correct settings will both * generate no message and not fail when addNonFatalError is called with the * given setting. */ @Test public final void testKnownDatatypeNoMessageNoFailCase4() throws Exception { Model expectedModel = getTestModel(KNOWN_DATATYPE_VALUE, KNOWN_DATATYPE_URI); InputStream input = getKnownDatatypeStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, false); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an unknown datatype with the message no fail. */ @Test public final void testUnknownDatatypeWithMessageNoFailCase1() throws Exception { Model expectedModel = getTestModel(UNKNOWN_DATATYPE_VALUE, UNKNOWN_DATATYPE_URI); InputStream input = getUnknownDatatypeStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); testParser.parse(input, BASE_URI); assertErrorListener(0, 1, 0); assertModel(expectedModel); }
/** * Tests whether an known datatype with the message no fail. */ @Test public final void testKnownDatatypeWithMessageNoFailCase1() throws Exception { Model expectedModel = getTestModel(KNOWN_DATATYPE_VALUE, KNOWN_DATATYPE_URI); InputStream input = getKnownDatatypeStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an unknown language with the message no fail. */ @Test public final void testUnknownLanguageWithMessageNoFailCase1() throws Exception { Model expectedModel = getTestModel(UNKNOWN_LANGUAGE_VALUE, UNKNOWN_LANGUAGE_TAG); InputStream input = getUnknownLanguageStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES); testParser.parse(input, BASE_URI); assertErrorListener(0, 1, 0); assertModel(expectedModel); }
/** * Tests whether an unknown datatype with the correct settings will both * generate no message and not fail when addNonFatalError is called with the * given setting. */ @Test public final void testUnknownDatatypeNoMessageNoFailCase4() throws Exception { Model expectedModel = getTestModel(UNKNOWN_DATATYPE_VALUE, UNKNOWN_DATATYPE_URI); InputStream input = getUnknownDatatypeStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, false); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an known language with the message no fail. */ @Test public final void testKnownLanguageWithMessageNoFailCase2() throws Exception { Model expectedModel = getTestModel(KNOWN_LANGUAGE_VALUE, KNOWN_LANGUAGE_TAG); InputStream input = getKnownLanguageStream(expectedModel); testParser.getParserConfig().useDefaults(); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an unknown datatype with the message no fail. */ @Test public final void testUnknownDatatypeWithMessageNoFailCase2() throws Exception { Model expectedModel = getTestModel(UNKNOWN_DATATYPE_VALUE, UNKNOWN_DATATYPE_URI); InputStream input = getUnknownDatatypeStream(expectedModel); testParser.getParserConfig().useDefaults(); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); testParser.parse(input, BASE_URI); assertErrorListener(0, 1, 0); assertModel(expectedModel); }
/** * Tests whether an known datatype with the message no fail. */ @Test public final void testKnownDatatypeWithMessageNoFailCase2() throws Exception { Model expectedModel = getTestModel(KNOWN_DATATYPE_VALUE, KNOWN_DATATYPE_URI); InputStream input = getKnownDatatypeStream(expectedModel); testParser.getParserConfig().useDefaults(); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); }
/** * Tests whether an unknown language with the message no fail. */ @Test public final void testUnknownLanguageWithMessageNoFailCase2() throws Exception { Model expectedModel = getTestModel(UNKNOWN_LANGUAGE_VALUE, UNKNOWN_LANGUAGE_TAG); InputStream input = getUnknownLanguageStream(expectedModel); testParser.getParserConfig().useDefaults(); testParser.getParserConfig().set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true); testParser.getParserConfig().addNonFatalError(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES); testParser.parse(input, BASE_URI); assertErrorListener(0, 1, 0); assertModel(expectedModel); }