@Override @SuppressWarnings("unchecked") public Iterator<String> getFieldNames() { return (Iterator<String>)IteratorUtils.transformedIterator( model.predicates().iterator(), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUR_TO_STRING_TRANSFORMER); }
@Override @SuppressWarnings("unchecked") public Iterator<String> getFieldNames() { return (Iterator<String>)IteratorUtils.transformedIterator( model.predicates().iterator(), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUR_TO_STRING_TRANSFORMER); }
public Set<RDFProperty> getRDFProperties() { Set<RDFProperty> set = new HashSet<RDFProperty>(); for (URI pred : model.filter(self, null, null).predicates()) { set.add(new RDFProperty(model, pred)); } return set; }
public Set<RDFProperty> getRDFProperties() { Set<RDFProperty> set = new HashSet<RDFProperty>(); for (URI pred : model.filter(self, null, null).predicates()) { set.add(new RDFProperty(model, pred)); } return set; }
.predicates())) { if (excludedProperties.contains(pred)) { continue;
@Override public Set makeEmptySet() { return new LinkedHashModel().filter(createURI("test1"), null, createURI("test2")).predicates(); }
@Test public void testUriWithEscapeCharactersShouldFailToParse() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); String nt = "<http://example/\\n> <http://example/p> <http://example/o> ."; try { ntriplesParser.parse(new StringReader(nt), NTRIPLES_TEST_URL); fail("Should have failed to parse invalid N-Triples uri with space"); } catch (RDFParseException ignored) { } assertEquals(0, model.size()); assertEquals(0, model.subjects().size()); assertEquals(0, model.predicates().size()); assertEquals(0, model.objects().size()); }
@Test public void testUriWithSpaceShouldFailToParse() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); String nt = "<http://example/ space> <http://example/p> <http://example/o> ."; try { ntriplesParser.parse(new StringReader(nt), NTRIPLES_TEST_URL); fail("Should have failed to parse invalid N-Triples uri with space"); } catch (RDFParseException ignored) { } assertEquals(0, model.size()); assertEquals(0, model.subjects().size()); assertEquals(0, model.predicates().size()); assertEquals(0, model.objects().size()); }
@Test public void testNTriplesFile() throws Exception { RDFParser ntriplesParser = createRDFParser(); ntriplesParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); InputStream in = this.getClass().getResourceAsStream(NTRIPLES_TEST_FILE); try { ntriplesParser.parse(in, NTRIPLES_TEST_URL); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage()); } finally { in.close(); } assertEquals(30, model.size()); assertEquals(28, model.subjects().size()); assertEquals(1, model.predicates().size()); assertEquals(23, model.objects().size()); }
public static Map<String,Metadata> parseRDFJSON(InputStream data) throws ParseException { try { Model model = Rio.parse(data, "", RDFFormat.RDFJSON); // convert Sesame Model into a map to Metadata objects Map<String,Metadata> result = new HashMap<String, Metadata>(); for(Resource subject : model.subjects()) { Metadata m = new Metadata(subject.stringValue()); for(org.openrdf.model.URI property : model.filter(subject, null, null).predicates()) { Set<RDFNode> propValue = new HashSet<RDFNode>(); for(Value value : model.filter(subject, property, null).objects()) { propValue.add(parseRDFJSONNode(value)); } m.put(property.stringValue(),propValue); } result.put(subject.stringValue(),m); } return result; } catch (IOException e) { throw new ParseException("could not parse JSON data",e); } catch(RDFParseException e) { throw new ParseException("could not parse JSON data",e); } catch(UnsupportedRDFormatException e) { throw new ParseException("could not parse JSON data",e); } }
public static Map<String,Metadata> parseRDFJSON(InputStream data) throws ParseException { try { Model model = Rio.parse(data, "", RDFFormat.RDFJSON); // convert Sesame Model into a map to Metadata objects Map<String,Metadata> result = new HashMap<String, Metadata>(); for(Resource subject : model.subjects()) { Metadata m = new Metadata(subject.stringValue()); for(org.openrdf.model.URI property : model.filter(subject, null, null).predicates()) { Set<RDFNode> propValue = new HashSet<RDFNode>(); for(Value value : model.filter(subject, property, null).objects()) { propValue.add(parseRDFJSONNode(value)); } m.put(property.stringValue(),propValue); } result.put(subject.stringValue(),m); } return result; } catch (IOException e) { throw new ParseException("could not parse JSON data",e); } catch(RDFParseException e) { throw new ParseException("could not parse JSON data",e); } catch(UnsupportedRDFormatException e) { throw new ParseException("could not parse JSON data",e); } }
@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()); }
private void assertModel(final Model parseTsv) { Assert.assertFalse(parseTsv.isEmpty()); Assert.assertEquals(4, parseTsv.subjects().size()); Assert.assertEquals(6, parseTsv.predicates().size()); Assert.assertEquals(9, parseTsv.objects().size()); }
for (final Resource nextSubject : graph.subjects()) { jg.writeObjectFieldStart(RDFJSONWriter.resourceToString(nextSubject)); for (final IRI nextPredicate : graph.filter(nextSubject, null, null).predicates()) { jg.writeArrayFieldStart(nextPredicate.stringValue()); for (final Value nextObject : graph.filter(nextSubject, nextPredicate, null).objects()) {