use of org.openrdf.rio.helpers.StatementCollector in project vcell by virtualcell.
the class JDOM2Model method addJDOM.
public void addJDOM(Element element, String baseURI) throws IOException, RDFParseException, RDFHandlerException {
Document document = new Document((Element) element.clone());
StringWriter stringWriter = new StringWriter();
new XMLOutputter().output(document, stringWriter);
StringReader stringReader = new StringReader(stringWriter.getBuffer().toString());
RDFParser rdfParser = Rio.createParser(RDFFormat.RDFXML);
rdfParser.setRDFHandler(new StatementCollector(model));
rdfParser.parse(stringReader, baseURI);
}
use of org.openrdf.rio.helpers.StatementCollector in project vcell by virtualcell.
the class SesameRioUtil method createRDFParser.
public static RDFParser createRDFParser(Graph graph, Map<String, String> nsMap, RDFFormat format) {
RDFParser parser = Rio.createParser(format);
StatementCollector statementCollector = new StatementCollector(graph, nsMap);
parser.setRDFHandler(statementCollector);
return parser;
}
use of org.openrdf.rio.helpers.StatementCollector in project wikidata-query-rdf by wikimedia.
the class WikibaseRepository method fetchRdfForEntity.
/**
* Fetch the RDF for some entity.
*
* @throws RetryableException thrown if there is an error communicating with
* wikibase
*/
public Collection<Statement> fetchRdfForEntity(String entityId) throws RetryableException {
// TODO handle ?flavor=dump or whatever parameters we need
URI uri = uris.rdf(entityId);
long start = System.currentTimeMillis();
log.debug("Fetching rdf from {}", uri);
RDFParser parser = Rio.createParser(RDFFormat.TURTLE);
StatementCollector collector = new StatementCollector();
parser.setRDFHandler(new NormalizingRdfHandler(collector));
HttpGet request = new HttpGet(uri);
request.setConfig(configWithTimeout);
try {
try (CloseableHttpResponse response = client.execute(request)) {
if (response.getStatusLine().getStatusCode() == 404) {
// A delete/nonexistent page
return Collections.emptyList();
}
if (response.getStatusLine().getStatusCode() >= 300) {
throw new ContainedException("Unexpected status code fetching RDF for " + uri + ": " + response.getStatusLine().getStatusCode());
}
parser.parse(new InputStreamReader(response.getEntity().getContent(), Charsets.UTF_8), uri.toString());
}
} catch (UnknownHostException | SocketException | SSLHandshakeException e) {
// We want to bail on this, since it happens to be sticky for some reason
throw new RuntimeException(e);
} catch (IOException e) {
throw new RetryableException("Error fetching RDF for " + uri, e);
} catch (RDFParseException | RDFHandlerException e) {
throw new ContainedException("RDF parsing error for " + uri, e);
}
log.debug("Done in {} ms", System.currentTimeMillis() - start);
return collector.getStatements();
}
use of org.openrdf.rio.helpers.StatementCollector in project incubator-rya by apache.
the class RyaAccumuloSailFactoryTest method testCreateFromTemplateName.
@Test
public void testCreateFromTemplateName() throws Exception {
LocalRepositoryManager repoman = new LocalRepositoryManager(Files.createTempDir());
repoman.initialize();
try (InputStream templateStream = RepositoryConfig.class.getResourceAsStream("RyaAccumuloSail.ttl")) {
String template = IOUtils.toString(templateStream);
final ConfigTemplate configTemplate = new ConfigTemplate(template);
final Map<String, String> valueMap = ImmutableMap.<String, String>builder().put("Repository ID", "RyaAccumuloSail").put("Repository title", "RyaAccumuloSail Store").put("Rya Accumulo user", "root").put("Rya Accumulo password", "").put("Rya Accumulo instance", "dev").put("Rya Accumulo zookeepers", "zoo1,zoo2,zoo3").put("Rya Accumulo is mock", "true").build();
final String configString = configTemplate.render(valueMap);
// final Repository systemRepo = this.state.getManager().getSystemRepository();
final Graph graph = new LinkedHashModel();
final RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
rdfParser.setRDFHandler(new StatementCollector(graph));
rdfParser.parse(new StringReader(configString), RepositoryConfigSchema.NAMESPACE);
final Resource repositoryNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
final RepositoryConfig repConfig = RepositoryConfig.create(graph, repositoryNode);
repConfig.validate();
repoman.addRepositoryConfig(repConfig);
Repository r = repoman.getRepository("RyaAccumuloSail");
r.initialize();
}
}
use of org.openrdf.rio.helpers.StatementCollector in project eol-globi-data by jhpoelen.
the class LinkerTrustyNanoPubsTest method toTrigString.
private String toTrigString(InputStream rdfIn) throws IOException, RDFParseException, RDFHandlerException {
TriGParser rdfParser = new TriGParser();
Model model = new LinkedHashModel();
rdfParser.setRDFHandler(new StatementCollector(model));
rdfParser.parse(rdfIn, "http://example.com");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Rio.write(model, out, RDFFormat.TRIG);
return new String(out.toByteArray(), "UTF-8");
}
Aggregations