本文整理匯總了Java中org.openrdf.rio.Rio.createParser方法的典型用法代碼示例。如果您正苦於以下問題:Java Rio.createParser方法的具體用法?Java Rio.createParser怎麽用?Java Rio.createParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.rio.Rio
的用法示例。
在下文中一共展示了Rio.createParser方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseConfig
import org.openrdf.rio.Rio; //導入方法依賴的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;
}
示例2: toStatements
import org.openrdf.rio.Rio; //導入方法依賴的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();
}
示例3: buildIndex
import org.openrdf.rio.Rio; //導入方法依賴的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();
}
}
示例4: parseFile
import org.openrdf.rio.Rio; //導入方法依賴的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;
}
示例5: processNsMap
import org.openrdf.rio.Rio; //導入方法依賴的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();
}
}
示例6: extract
import org.openrdf.rio.Rio; //導入方法依賴的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);
}
}
示例7: createParser
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public RDFParser createParser(RDFFormat rioFormat) {
return Rio.createParser(rioFormat);
/*
if (this.equals(NQUADS)) {
return new NQuadsParser();
}
else {
return Rio.createParser(rioFormat);
}
*/
}
示例8: extractMetadata
import org.openrdf.rio.Rio; //導入方法依賴的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;
}
示例9: RDFBlueprintsHandler
import org.openrdf.rio.Rio; //導入方法依賴的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);
}
示例10: testGetStatements
import org.openrdf.rio.Rio; //導入方法依賴的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();
}
示例11: parseAsList
import org.openrdf.rio.Rio; //導入方法依賴的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;
}
示例12: parseRdf
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public static Model parseRdf(String rdfResource) throws RDFParseException,
RDFHandlerException, IOException {
InputStream inStream = new ByteArrayInputStream(rdfResource.getBytes());
RDFParser parser = Rio.createParser(RDFFormat.N3);
Model graph = new LinkedHashModel();
parser.setRDFHandler(new StatementCollector(graph));
parser.parse(inStream, "http://test/");
return graph;
}
示例13: injectTriples
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Override
public void injectTriples(TripleSink sink) throws IOException {
try {
Collector collector = new Collector();
RDFParser parser =Rio.createParser(this.format);
parser.setRDFHandler(collector);
parser.parse(new StringReader(this.content), this.base);
SesameModelParser tripleParser=new SesameModelParser(collector.getNamespaces());
for(Statement st:collector.getStatements()) {
sink.addTriple(tripleParser.parseStatement(st));
}
} catch (OpenRDFException e) {
throw new IOException(e);
}
}
示例14: parseRdf
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private Graph parseRdf(String config, ValueFactory vf, RDFFormat lang) {
Graph graph = new GraphImpl(vf);
RDFParser rdfParser = Rio.createParser(lang, vf);
rdfParser.setRDFHandler(new StatementCollector(graph));
try {
rdfParser.parse(new StringReader(config), RepositoryConfigSchema.NAMESPACE);
} catch (Exception e) {
throw new SesameManagerException("Could not parse rdf: " + e);
}
return graph;
}
示例15: parseChangeSet
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private Model parseChangeSet(String rdfChangeSet, RDFFormat rdfFormat) throws IOException, OpenRDFException {
RDFParser rdfParser = Rio.createParser(rdfFormat);
Model changeSet = new TreeModel();
StatementCollector collector = new StatementCollector(changeSet);
rdfParser.setRDFHandler(collector);
rdfParser.parse(new StringReader(rdfChangeSet), "");
return changeSet;
}