本文整理汇总了Java中org.openrdf.rio.RDFParser类的典型用法代码示例。如果您正苦于以下问题:Java RDFParser类的具体用法?Java RDFParser怎么用?Java RDFParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RDFParser类属于org.openrdf.rio包,在下文中一共展示了RDFParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToGraphstore
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
/**
* Helper method for handleAdd.
*/
private void addToGraphstore(
RepositoryConnection conn,
InputStream in,
String base,
RDFFormat format,
Resource dctx,
boolean chunked) throws IOException, RDFParseException,
RDFHandlerException, RepositoryException {
if (chunked) {
RDFParser parser = getRDFParser(format);
parser.setRDFHandler(
new ChunkedCommitHandler(conn, chunksize, dctx));
parser.parse(in, base);
} else {
if (dctx != null) {
conn.add(in, base, format, dctx);
} else {
conn.add(in, base, format);
}
}
}
示例2: parseConfig
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
protected Graph parseConfig(File file) throws SailConfigException, IOException {
RDFFormat format = Rio.getParserFormatForFileName(file.getAbsolutePath());
if (format==null)
throw new SailConfigException("Unsupported file format: " + file.getAbsolutePath());
RDFParser parser = Rio.createParser(format);
Graph model = new GraphImpl();
parser.setRDFHandler(new StatementCollector(model));
InputStream stream = new FileInputStream(file);
try {
parser.parse(stream, file.getAbsolutePath());
} catch (Exception e) {
throw new SailConfigException("Error parsing file!");
}
stream.close();
return model;
}
示例3: getModel
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
public static Model getModel( InsightManager im, User user ) {
Model statements = new LinkedHashModel();
int idx = 0;
RDFParser parser = new TurtleParser();
StatementCollector coll = new StatementCollector();
parser.setRDFHandler( coll );
try ( InputStream is = IEngine.class.getResourceAsStream( "/models/sempers.ttl" ) ) {
parser.parse( is, SEMPERS.BASE_URI );
}
catch ( Exception e ) {
log.warn( "could not include sempers.ttl ontology in statements", e );
}
statements.addAll( coll.getStatements() );
ValueFactory vf = new ValueFactoryImpl();
for ( Perspective p : im.getPerspectives() ) {
statements.addAll( getStatements( p, user ) );
statements.add( new StatementImpl( p.getId(), OLO.index,
vf.createLiteral( idx++ ) ) );
}
return statements;
}
示例4: toStatements
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
public static Iterator<Statement> toStatements(Iterator<Row> iterator)
throws RDFParseException, RDFHandlerException, IOException {
if (!iterator.hasNext()) {
return Collections.emptyIterator();
}
Set<Statement> ret = new HashSet<Statement>();
RDFParser rdfParser = Rio.createParser(RDFFormat.BINARY);
StatementCollector collector = new StatementCollector(ret);
rdfParser.setRDFHandler(collector);
while (iterator.hasNext()) {
toStatements(
rdfParser,
Bytes.getArray(iterator.next().getBytes(
DATA_TABLE_ATTRIBUTE_3)));
}
return Collections.unmodifiableSet(ret).iterator();
}
示例5: buildIndex
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
public void buildIndex(String inputFilename) {
solrClient.init();
DnbTitleHandler handler = new DnbTitleHandler(solrClient);
RDFParser rdfParser = Rio.createParser(RDFFormat.RDFXML);
rdfParser.setRDFHandler(handler);
try (InputStream in = new FileInputStream(inputFilename)) {
rdfParser.parse(in, "http://dnb.de");
} catch (Exception e) {
log.error("Error parsing " + inputFilename, e);
} finally {
solrClient.commit();
solrClient.optimize();
solrClient.destroy();
}
}
示例6: parseFile
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
public Model parseFile(InputStream configurationFile, RDFFormat format,
String defaultNamespace) throws Exception {
final Graph graph = new GraphImpl();
RDFParser parser = Rio.createParser(format);
org.openrdf.model.Model myGraph = new org.openrdf.model.impl.LinkedHashModel();
/*
* RDFHandler handler = new RDFHandler() { public void endRDF() throws
* RDFHandlerException { }
*
* public void handleComment(String arg0) throws RDFHandlerException { }
*
* public void handleNamespace(String arg0, String arg1) throws
* RDFHandlerException { }
*
* public void handleStatement(Statement statement) throws
* RDFHandlerException { graph.add(statement); }
*
* public void startRDF() throws RDFHandlerException { } };
*/
parser.setRDFHandler(new StatementCollector(myGraph));
parser.parse(configurationFile, defaultNamespace);
return myGraph;
}
示例7: processNsMap
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
private void processNsMap() throws Exception {
InputStream in = new FileInputStream("downloads/nsmap.ttl");
RDFParser p = Rio.createParser(RDFFormat.TURTLE);
p.setRDFHandler(new RDFHandlerBase() {
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
processNsMapStatement(st);
}
});
try {
p.parse(in, baseUri);
} finally {
in.close();
}
}
示例8: process
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
private static void process(RDFFormat format, InputStream in, File file, NanopubHandler npHandler)
throws IOException, RDFParseException, RDFHandlerException, MalformedNanopubException {
RDFParser p = NanopubUtils.getParser(format);
p.setRDFHandler(new MultiNanopubRdfHandler(npHandler));
try {
p.parse(new InputStreamReader(in, Charset.forName("UTF-8")), "");
} catch (RuntimeException ex) {
if ("wrapped MalformedNanopubException".equals(ex.getMessage()) &&
ex.getCause() instanceof MalformedNanopubException) {
throw (MalformedNanopubException) ex.getCause();
} else {
throw ex;
}
} finally {
in.close();
}
}
示例9: readStatements
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
private void readStatements(InputStream in, RDFFormat format, String baseUri)
throws MalformedNanopubException, OpenRDFException, IOException {
try {
RDFParser p = NanopubUtils.getParser(format);
p.setRDFHandler(new RDFHandlerBase() {
@Override
public void handleNamespace(String prefix, String uri) throws RDFHandlerException {
nsPrefixes.add(prefix);
ns.put(prefix, uri);
}
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
statements.add(st);
}
});
p.parse(new InputStreamReader(in, Charset.forName("UTF-8")), baseUri);
} finally {
in.close();
}
}
示例10: extract
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
@Override
public void extract(RDFHandler handler, ExtractContext context) throws ExtractException {
try {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("PREFIX skos:<http://www.w3.org/2004/02/skos/core#> CONSTRUCT {?concept <").append(config.getLinkProperty()).append("> ?link } WHERE { ?concept a skos:Concept. ");
queryBuilder.append("?concept <").append(config.getLinkProperty()).append("> ?link. }");
logger.info(queryBuilder.toString());
URL url = PPTApi.getServiceUrl(config.getApiConfig().getServer(), "PoolParty/sparql/"+config.getApiConfig().getUriSupplement()+"?format=application/rdf%2Bxml&query="+URLEncoder.encode(queryBuilder.toString(), "UTF-8"));
URLConnection connection = url.openConnection();
config.getApiConfig().getAuthentication().visit(connection);
RDFParser parser = Rio.createParser(RDFFormat.RDFXML);
parser.setRDFHandler(handler);
parser.parse(connection.getInputStream(), "");
} catch (Exception ex) {
throw new ExtractException(ex);
}
}
示例11: createParser
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
public RDFParser createParser(RDFFormat rioFormat) {
return Rio.createParser(rioFormat);
/*
if (this.equals(NQUADS)) {
return new NQuadsParser();
}
else {
return Rio.createParser(rioFormat);
}
*/
}
示例12: extractMetadata
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
/**
* Parse the files harvested from PoolParty and extract the
* metadata.
* @param pPprojectId The PoolParty project id.
* @return The results of the metadata extraction.
*/
public final HashMap<String, Object> extractMetadata(
final String pPprojectId) {
Path dir = Paths.get(ToolkitFileUtils.getMetadataOutputPath(
pPprojectId));
HashMap<String, Object> results = new HashMap<String, Object>();
ConceptHandler conceptHandler = new ConceptHandler();
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(dir)) {
for (Path entry: stream) {
conceptHandler.setSource(entry.getFileName().toString());
RDFFormat format = Rio.getParserFormatForFileName(
entry.toString());
RDFParser rdfParser = Rio.createParser(format);
rdfParser.setRDFHandler(conceptHandler);
FileInputStream is = new FileInputStream(entry.toString());
logger.debug("Reading RDF:" + entry.toString());
rdfParser.parse(is, entry.toString());
}
} catch (DirectoryIteratorException
| IOException
| RDFParseException
| RDFHandlerException ex) {
results.put(TaskStatus.EXCEPTION,
"Exception in extractMetadata while Parsing RDF");
logger.error("Exception in extractMetadata while Parsing RDF:",
ex);
return results;
}
results.putAll(conceptHandler.getMetadata());
results.put("concept_count", Integer.toString(
conceptHandler.getCountedConcepts()));
return results;
}
示例13: RDFBlueprintsHandler
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
public RDFBlueprintsHandler(final ModifiableHadoopConfiguration configuration) throws IOException {
// exclude fragments which are most likely to interfere in a Titan/Faunus pipeline
reservedFragments = new HashSet<String>();
reservedFragments.add("label");
//reservedFragments.add("type");
reservedFragments.add("id");
faunusConf = configuration;
rdfConf = faunusConf.getInputConf(ROOT_NS);
this.baseURI = rdfConf.get(RDF_BASE_URI);
this.useFragments = rdfConf.get(RDF_USE_LOCALNAME);
this.literalAsProperty = rdfConf.get(RDF_LITERAL_AS_PROPERTY);
for (final String property : rdfConf.get(RDF_AS_PROPERTIES)) {
this.asProperties.add(property.trim());
}
if (!rdfConf.has(RDF_FORMAT)) {
throw new RuntimeException("RDF format is required. Set " + ConfigElement.getPath(TitanHadoopConfiguration.INPUT_CONF_NS) + "." + RDF_FORMAT.getName());
}
Syntax syntax = rdfConf.get(RDF_FORMAT);
RDFFormat format = syntax.getRDFFormat();
Preconditions.checkNotNull(format);
this.parser = Rio.createParser(format);
this.parser.setRDFHandler(this);
this.parser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE);
}
示例14: testGetStatements
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
/**
* test get Statemetns.
* @throws Exception The test would fails if Exception occurs
*/
@Test
public void testGetStatements() throws Exception {
//insert some statments first
for (final String tripleAsString : _data) {
final Statement triple = parseNX(tripleAsString).iterator().next();
TRIPLE_STORE.addData(triple);
}
//test get the statements
String uri = BASE_URI + Protocol.REPOSITORIES + "/" + REPO_ID + "/" + Protocol.STATEMENTS;
File tmp = WebTestUtils.tmpFile();
final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp);
final HttpServletRequest request = mockHttpRequest(uri, METHOD_GET);
when(request.getParameter(Protocol.SUBJECT_PARAM_NAME)).thenReturn(DEVICE);
when(request.getParameter(Protocol.ACCEPT_PARAM_NAME)).thenReturn(MIMETYPE_RDF_XML);
when(request.getCharacterEncoding()).thenReturn(UTF_8);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getOutputStream()).thenReturn(servletOutputStream);
GetMethod method = new GetMethod(uri);
RDFFormat format = RDFFormat.RDFXML;
RDFParser parser = Rio.createParser(format, valueFactory);
parser.setParserConfig(parser.getParserConfig());
StatementCollector collector = new StatementCollector();
parser.setRDFHandler(collector);
_classUnderTest.service(request, response);
parser.parse(new FileInputStream(tmp), method.getURI().getURI());
assertTrue(!collector.getStatements().isEmpty());
verify(response).setStatus(HttpServletResponse.SC_OK);
servletOutputStream.close();
}
示例15: parseAsList
import org.openrdf.rio.RDFParser; //导入依赖的package包/类
/**
* Parses the incoming RDF stream according with a given format.
*
* @param stream
* the RDF (input) stream.
* @param format
* the {@link RDFFormat} that will be used for parsing.
* @return a {@link List} with collected statements.
*/
public static List<Statement> parseAsList(final InputStream stream, final RDFFormat format) {
final List<Statement> statements = new ArrayList<Statement>();
try {
final RDFParser parser = Rio.createParser(format, VALUE_FACTORY);
parser.setRDFHandler(new StatementCollector(statements));
parser.parse(stream, "");
} catch (final Exception exception) {
LOGGER.error(MessageCatalog._00029_RDF_PARSE_FAILURE, exception);
}
return statements;
}