本文整理匯總了Java中org.openrdf.rio.Rio.getParserFormatForFileName方法的典型用法代碼示例。如果您正苦於以下問題:Java Rio.getParserFormatForFileName方法的具體用法?Java Rio.getParserFormatForFileName怎麽用?Java Rio.getParserFormatForFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.rio.Rio
的用法示例。
在下文中一共展示了Rio.getParserFormatForFileName方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: VocabBuilder
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public VocabBuilder(String filename, RDFFormat format) throws IOException, RDFParseException {
Path file = Paths.get(filename);
if (!Files.exists(file)) throw new FileNotFoundException(filename);
if (format == null) {
format = Rio.getParserFormatForFileName(filename);
log.trace("detected input format from filename {}: {}", filename, format);
}
try (final InputStream inputStream = Files.newInputStream(file)) {
log.trace("Loading input file");
model = Rio.parse(inputStream, "", format);
}
//import
Set<Resource> owlOntologies = model.filter(null, RDF.TYPE, OWL.ONTOLOGY).subjects();
if (!owlOntologies.isEmpty()) {
setPrefix(owlOntologies.iterator().next().stringValue());
}
}
示例3: getTypes
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
/**
* Return a set of all mime types that are acceptable by the importer.
* @return a set of all mime types that are acceptable by the importer.
*/
@GET
@Path("/types")
@Produces("application/json")
public List<String> getTypes(@QueryParam("filename") String filename) {
if(filename == null)
return new ArrayList<String>(importService.getAcceptTypes());
else {
List<String> result = new ArrayList<String>();
RDFFormat format = Rio.getParserFormatForFileName(filename);
if(format != null) {
result.addAll(format.getMIMETypes());
}
return result;
}
}
示例4: NanopubImpl
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public NanopubImpl(URL url) throws MalformedNanopubException, OpenRDFException, IOException {
HttpResponse response = getNanopub(url);
Header contentTypeHeader = response.getFirstHeader("Content-Type");
RDFFormat format = RDFFormat.TRIG;
if (contentTypeHeader != null) {
format = Rio.getParserFormatForMIMEType(contentTypeHeader.getValue());
}
if (format == null || !format.supportsContexts()) {
format = Rio.getParserFormatForFileName(url.toString(), RDFFormat.TRIG);
}
if (!format.supportsContexts()) {
format = RDFFormat.TRIG;
}
readStatements(response.getEntity().getContent(), format, "");
init();
}
示例5: insertDataFile
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private void insertDataFile(URL dataFile, String defaultNamespace) throws Exception {
RDFFormat format = Rio.getParserFormatForFileName(dataFile.getFile());
SailRepositoryConnection conn = repository.getConnection();
try {
conn.add(dataFile, defaultNamespace, format);
} finally {
closeQuietly(conn);
}
}
示例6: 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;
}
示例7: getFormat
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public RDFFormat getFormat(RDFFormat defaultFormat) {
RDFFormat format = Rio.getParserFormatForMIMEType(getMimetype());
if (format == null) {
format = Rio.getParserFormatForFileName(getFilename(), defaultFormat);
}
return format;
}
示例8: parseStatements
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private Model parseStatements(File file) throws IOException, RDFParseException {
FileInputStream inputStream = new FileInputStream(file);
RDFFormat rdfFormat = Rio.getParserFormatForFileName(file.getName());
Model model = Rio.parse(inputStream, file.toURI().toString(), rdfFormat);
inputStream.close();
return model;
}
示例9: writeRDF
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private static void writeRDF(final Stream<Record> records, final File file)
throws RDFHandlerException, IOException {
final RDFFormat format = Rio.getParserFormatForFileName(file.getAbsolutePath());
final OutputStream stream = IO.write(file.getAbsolutePath());
try {
final RDFWriter writer = Rio.createWriter(format, stream);
writer.startRDF();
writer.handleNamespace("rdf", RDF.NAMESPACE);
writer.handleNamespace("rdfs", RDFS.NAMESPACE);
writer.handleNamespace("owl", OWL.NAMESPACE);
writer.handleNamespace("ks", KS.NAMESPACE);
writer.handleNamespace("nwr", NWR.NAMESPACE);
writer.handleNamespace("nif", NIF.NAMESPACE);
writer.handleNamespace("nfo", NFO.NAMESPACE);
writer.handleNamespace("nie", NIE.NAMESPACE);
writer.handleNamespace("sem", SEM.NAMESPACE);
writer.handleNamespace("time", TIME.NAMESPACE);
records.toHandler(new Handler<Record>() {
private int records = 0;
private long triples = 0;
@Override
public void handle(final Record record) throws Throwable {
if (record == null || this.records > 0 && this.records % 1000 == 0) {
LOGGER.info(this.records + " records, " + this.triples
+ " triples processed");
}
if (record != null) {
final List<Statement> statements = Record.encode(Stream.create(record),
ImmutableSet.of()).toList();
writer.handleComment(record.getID().toString());
for (final Statement statement : statements) {
writer.handleStatement(statement);
}
++this.records;
this.triples += statements.size();
}
}
});
writer.endRDF();
} finally {
stream.close();
}
}
示例10: main
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public static void main(final String... args) {
try {
LogManager.getLogManager().reset();
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
// Parse command line
final CommandLine cmd = CommandLine
.parser()
.withName("kv-index")
.withOption("c", "component",
"the component (s,p,o,c) to use for partitioning quads (default: s)",
"COMP", CommandLine.Type.STRING, true, false, false)
.withOption("r", "recursive", "whether to recurse into input directories")
.withOption("o", "output", "output file name", "FILE", CommandLine.Type.FILE,
true, false, true)
.withHeader(
"Read RDF quads, split them into partitions by component "
+ "and index the partitions in a binary file for fast lookup")
.parse(args);
// Extract options
final StatementComponent component = StatementComponent.forLetter(cmd.getOptionValue(
"c", String.class, "s").charAt(0));
final boolean recursive = cmd.hasOption("r");
final File output = cmd.getOptionValue("o", File.class);
final List<File> files = cmd.getArgs(File.class);
// Expand file list if recursive
final Set<String> locations = Sets.newHashSet();
for (final File file : files) {
locations.add(file.getAbsolutePath());
if (recursive && file.isDirectory()) {
for (final File child : Files.fileTreeTraverser().preOrderTraversal(file)) {
if (Rio.getParserFormatForFileName(file.getAbsolutePath()) != null) {
locations.add(child.getAbsolutePath());
}
}
}
}
// Build the indexer
final RDFHandler indexer = indexer(output, component);
// Run the indexer
RDFProcessors.read(true, true, null, null,
locations.toArray(new String[locations.size()])).apply(RDFSources.NIL,
indexer, 1);
} catch (final Throwable ex) {
// Display error information and terminate
CommandLine.fail(ex);
}
}
示例11: process
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public static void process(File file, NanopubHandler npHandler)
throws IOException, RDFParseException, RDFHandlerException, MalformedNanopubException {
RDFFormat format = Rio.getParserFormatForFileName(file.getName(), RDFFormat.TRIG);
process(format, file, npHandler);
}
示例12: init
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private void init() throws IOException {
count = 0;
outFormat = Rio.getParserFormatForFileName(outputFile.getName());
if (outputFile.getName().endsWith(".gz")) {
writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile)), Charset.forName("UTF-8"));
} else {
writer = new OutputStreamWriter(new FileOutputStream(outputFile), Charset.forName("UTF-8"));
}
indexCreator = new SimpleIndexCreator() {
@Override
public void handleIncompleteIndex(NanopubIndex npi) {
try {
writer.write(NanopubUtils.writeToString(npi, outFormat) + "\n\n");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@Override
public void handleCompleteIndex(NanopubIndex npi) {
System.out.println("Index URI: " + npi.getUri());
try {
writer.write(NanopubUtils.writeToString(npi, outFormat) + "\n\n");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
};
indexCreator.setBaseUri(baseUri);
if (iTitle != null) {
indexCreator.setTitle(iTitle);
}
if (iDesc != null) {
indexCreator.setDescription(iDesc);
}
for (String creator : iCreators) {
indexCreator.addCreator(creator);
}
for (String sa : seeAlso) {
indexCreator.addSeeAlsoUri(new URIImpl(sa));
}
}
示例13: run
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private void run() throws Exception {
init();
for (File f : inputFiles) {
if (f.getName().endsWith(".txt")) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(f));
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) continue;
// To allow for other content in the file, ignore everything after the first blank space:
if (line.contains(" ")) line = line.substring(0, line.indexOf(" "));
indexCreator.addElement(new URIImpl(line));
}
} finally {
if (br != null) br.close();
}
} else {
RDFFormat format = Rio.getParserFormatForFileName(f.getName());
MultiNanopubRdfHandler.process(format, f, new NanopubHandler() {
@Override
public void handleNanopub(Nanopub np) {
if (useSubindexes && IndexUtils.isIndex(np)) {
try {
indexCreator.addSubIndex(IndexUtils.castToIndex(np));
} catch (MalformedNanopubException ex) {
throw new RuntimeException(ex);
}
} else {
indexCreator.addElement(np);
}
count++;
if (count % 100 == 0) {
System.err.print(count + " nanopubs...\r");
}
}
});
}
}
for (String e : elements) {
indexCreator.addElement(new URIImpl(e));
}
for (String s : subindexes) {
indexCreator.addSubIndex(new URIImpl(s));
}
if (supersededIndex != null) {
indexCreator.setSupersededIndex(new URIImpl(supersededIndex));
}
indexCreator.finalizeNanopub();
writer.close();
}
示例14: run
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private void run() throws IOException, RDFHandlerException, MalformedNanopubException {
if (showReport) {
exceptions = new ArrayList<>();
}
if (outputFile == null) {
if (format == null) {
format = "trig";
}
rdfFormat = Rio.getParserFormatForFileName("file." + format);
} else {
rdfFormat = Rio.getParserFormatForFileName(outputFile.getName());
if (outputFile.getName().endsWith(".gz")) {
outputStream = new GZIPOutputStream(new FileOutputStream(outputFile));
} else {
outputStream = new FileOutputStream(outputFile);
}
}
if (errorFile != null) {
errorStream = new PrintStream(errorFile);
}
FetchIndex fetchIndex = null;
for (String nanopubId : nanopubIds) {
if (getIndex || getIndexContent) {
fetchIndex = new FetchIndex(nanopubId, outputStream, rdfFormat, getIndex, getIndexContent);
fetchIndex.setProgressListener(new FetchIndex.Listener() {
@Override
public void progress(int count) {
System.err.print(count + " nanopubs...\r");
}
@Override
public void exceptionHappened(Exception ex, String serverUrl, String artifactCode) {
if (showReport) {
exceptions.add(ex);
}
if (errorStream != null) {
String exString = ex.toString().replaceAll("\\n", "\\\\n");
errorStream.println(serverUrl + " " + artifactCode + " " + exString);
}
}
});
fetchIndex.run();
count = fetchIndex.getNanopubCount();
} else {
outputNanopub(nanopubId, get(nanopubId));
}
}
if (outputStream != System.out) {
outputStream.close();
System.err.println(count + " nanopubs retrieved and saved in " + outputFile);
}
if (errorStream != null) {
errorStream.close();
}
if (showReport && fetchIndex != null) {
System.err.println("Number of retries: " + exceptions.size());
System.err.println("Used servers:");
List<ServerInfo> usedServers = fetchIndex.getServers();
final FetchIndex fi = fetchIndex;
Collections.sort(usedServers, new Comparator<ServerInfo>() {
@Override
public int compare(ServerInfo o1, ServerInfo o2) {
return fi.getServerUsage(o2) - fi.getServerUsage(o1);
}
});
int usedServerCount = 0;
for (ServerInfo si : usedServers) {
if (fetchIndex.getServerUsage(si) > 0) usedServerCount++;
System.err.format("%8d %s%n", fetchIndex.getServerUsage(si), si.getPublicUrl());
}
System.err.format("Number of servers used: " + usedServerCount);
}
}