本文整理汇总了Java中org.openrdf.rio.RDFFormat.forFileName方法的典型用法代码示例。如果您正苦于以下问题:Java RDFFormat.forFileName方法的具体用法?Java RDFFormat.forFileName怎么用?Java RDFFormat.forFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.rio.RDFFormat
的用法示例。
在下文中一共展示了RDFFormat.forFileName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkFileParseable
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private static void checkFileParseable(@Nullable final File file,
@Nullable final String formatString) {
if (file == null) {
if (formatString == null) {
throw new IllegalArgumentException("Cannot detect RDF format "
+ "and compression of STDIN: please specify option -s");
}
return;
}
checkFileExist(file);
final RDFFormat defaultFormat = detectRDFFormat(formatString, null);
final Compression defaultCompression = detectCompression(formatString, null);
final RDFFormat format = RDFFormat.forFileName(file.getName());
if (format == null && defaultFormat == null) {
throw new IllegalArgumentException("Unknown RDF format for file " + file);
} else if (format != null && defaultFormat != null && !format.equals(defaultFormat)) {
System.err.println("Warning: detected RDF format for file " + file
+ " doesn't match specified format");
}
final Compression compression = Compression.forFileName(file.getName(), Compression.NONE);
if (defaultCompression != null && !compression.equals(defaultCompression)) {
System.err.println("Warning: detected compression format for file " + file
+ " doesn't match specified format");
}
}
示例2: FileDocumentIO
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
public FileDocumentIO(boolean validate) {
File file = SBOLUtils.setupFile();
String fileName = file.getName();
RDFFormat format = fileName.endsWith(".xml") ? RDFFormat.RDFXML
: RDFFormat.forFileName(fileName, RDFFormat.RDFXML);
// reader = SublimeSBOLFactory.createReader(format, validate);
// writer = SublimeSBOLFactory.createWriter(format, validate);
}
示例3: init
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
@Override
public synchronized void init() throws IOException, IllegalStateException {
Preconditions.checkState(!this.initialized && !this.closed);
this.initialized = true;
InputStream stream = null;
try {
if (this.fileSystem.exists(this.filePath)) {
stream = Files.readWithBackup(this.fileSystem, this.filePath);
final RDFFormat format = RDFFormat.forFileName(this.filePath.getName());
final List<Record> records = Record.decode(
RDFUtil.readRDF(stream, format, null, null, false),
ImmutableSet.of(KS.RESOURCE, KS.MENTION, KS.ENTITY, KS.CONTEXT), false)
.toList();
for (final Record record : records) {
final URI id = Preconditions.checkNotNull(record.getID());
final URI type = Preconditions.checkNotNull(record.getSystemType());
MemoryDataStore.this.tables.get(type).put(id, record);
}
MemoryDataStore.LOGGER.info("{} initialized, {} records loaded", this.getClass()
.getSimpleName(), records.size());
} else {
MemoryDataStore.LOGGER.info("{} initialized, no record loaded", this.getClass()
.getSimpleName());
}
} finally {
Util.closeQuietly(stream);
}
}
示例4: update
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private synchronized void update(final Map<URI, Map<URI, Record>> tables, final int revision)
throws IOException {
if (this.revision != revision) {
throw new IOException("Commit failed due to concurrent modifications " + this.revision
+ ", " + revision);
}
OutputStream stream = null;
try {
stream = Files.writeWithBackup(this.fileSystem, this.filePath);
final List<Record> records = Lists.newArrayList();
for (final URI type : tables.keySet()) {
records.addAll(tables.get(type).values());
}
final RDFFormat format = RDFFormat.forFileName(this.filePath.getName());
RDFUtil.writeRDF(stream, format, Data.getNamespaceMap(), null,
Record.encode(Stream.create(records), ImmutableSet.<URI>of()));
++this.revision;
this.tables = tables;
MemoryDataStore.LOGGER.info("MemoryDataStore updated, {} records persisted",
records.size());
} catch (final Throwable ex) {
MemoryDataStore.LOGGER.error("MemoryDataStore update failed", ex);
} finally {
Util.closeQuietly(stream);
}
}
示例5: loadRecords
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private static List<Record> loadRecords(final String resourceName) {
final InputStream in = ClientExample.class.getResourceAsStream(resourceName);
try {
final RDFFormat format = RDFFormat.forFileName(resourceName);
final Stream<Statement> stmt = RDFUtil.readRDF(in, format, null, null, false);
return Record.decode(stmt, ImmutableList.of(KS.RESOURCE, KS.MENTION), false).toList();
} finally {
Util.closeQuietly(in);
}
}
示例6: forFileName
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private RDFFormat forFileName(String path, RDFFormat fallback) {
RDFFormat format = RDFFormat.forFileName(path);
RDFParserRegistry registry = RDFParserRegistry.getInstance();
if (format != null && registry.has(format))
return format;
return fallback;
}
示例7: loadData
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
@CliCommand(value = LOAD_DATA_CMD, help = "Loads RDF Statement data from a local file to the connected Rya instance.")
public String loadData(
@CliOption(key = { "file" }, mandatory = true, help = "A local file containing RDF Statements that is to be loaded.")
final String file,
@CliOption(key = { "format" }, mandatory = false, help = "The format of the supplied RDF Statements file. [RDF/XML, N-Triples, Turtle, N3, TriX, TriG, BinaryRDF, N-Quads, JSON-LD, RDF/JSON, RDFa]")
final String format
) {
// Fetch the command that is connected to the store.
final ShellState shellState = state.getShellState();
final RyaClient commands = shellState.getConnectedCommands().get();
final Optional<String> ryaInstanceName = shellState.getRyaInstanceName();
try {
final long start = System.currentTimeMillis();
// If the provided path is relative, then make it rooted in the user's home.
Path rootedFile = Paths.get( file.replaceFirst("^~", System.getProperty("user.home")) );
RDFFormat rdfFormat = null;
// If a format was provided, then go with that.
if (format != null) {
rdfFormat = RDFFormat.valueOf(format);
if (rdfFormat == null) {
throw new RuntimeException("Unsupported RDF Statement data input format: " + format);
}
}
// Otherwise try to figure it out using the filename.
else if (rdfFormat == null) {
rdfFormat = RDFFormat.forFileName(rootedFile.getFileName().toString());
if (rdfFormat == null) {
throw new RuntimeException("Unable to detect RDF Statement data input format for file: " + rootedFile);
} else {
consolePrinter.println("Detected RDF Format: " + rdfFormat);
consolePrinter.flush();
}
}
commands.getLoadStatementsFile().loadStatements(ryaInstanceName.get(), rootedFile, rdfFormat);
final String seconds = new DecimalFormat("0.0##").format((System.currentTimeMillis() - start) / 1000.0);
return "Loaded the file: '" + file + "' successfully in " + seconds + " seconds.";
} catch (final RyaClientException | IOException e) {
log.error("Error", e);
throw new RuntimeException("Can not load the RDF Statement data. Reason: " + e.getMessage(), e);
}
}
示例8: fromFile
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
@Override
public void fromFile(final Path statementsPath, final String visibilities) throws RyaStreamsException {
requireNonNull(statementsPath);
requireNonNull(visibilities);
if(!statementsPath.toFile().exists()) {
throw new RyaStreamsException("Could not load statements at path '" + statementsPath + "' because that " +
"does not exist. Make sure you've entered the correct path.");
}
// Create an RDF Parser whose format is derived from the statementPath's file extension.
final RDFFormat format = RDFFormat.forFileName(statementsPath.getFileName().toString());
final RDFParser parser = Rio.createParser(format);
// Set a handler that writes the statements to the specified kafka topic.
parser.setRDFHandler(new RDFHandlerBase() {
@Override
public void startRDF() throws RDFHandlerException {
log.trace("Starting loading statements.");
}
@Override
public void handleStatement(final Statement stmnt) throws RDFHandlerException {
final VisibilityStatement visiStatement = new VisibilityStatement(stmnt, visibilities);
producer.send(new ProducerRecord<>(topic, visiStatement));
}
@Override
public void endRDF() throws RDFHandlerException {
producer.flush();
log.trace("Done.");
}
});
// Do the parse and load.
try {
parser.parse(Files.newInputStream(statementsPath), "");
} catch (RDFParseException | RDFHandlerException | IOException e) {
throw new RyaStreamsException("Could not load the RDF file's Statements into Rya Streams.", e);
}
}
示例9: detectRDFFormat
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private static RDFFormat detectRDFFormat(@Nullable final String string,
final RDFFormat fallback) {
return string == null ? fallback : RDFFormat.forFileName("dummy." + string.trim(),
fallback);
}
示例10: readRDFHelper
import org.openrdf.rio.RDFFormat; //导入方法依赖的package包/类
private static void readRDFHelper(@Nullable final File file, @Nullable final RDFFormat format,
@Nullable final Map<String, String> namespaces, @Nullable final String base,
final boolean preserveBNodes, @Nullable final Compression compression,
final RDFHandler handler) throws IOException, RDFParseException, RDFHandlerException {
// Detect file format
RDFFormat actualFormat = format;
if (actualFormat == null) {
if (file == null) {
throw new IllegalArgumentException("Cannot detect RDF format of STDIN");
}
actualFormat = RDFFormat.forFileName(file.getName());
}
// Detect file compression
Compression actualCompression = compression;
if (actualCompression == null) {
actualCompression = file == null ? Compression.NONE : Compression.forFileName(
file.getName(), Compression.NONE);
}
// Perform parsing, wrapping possible exceptions so to report the file name
InputStream stream = null;
try {
stream = file == null ? System.in : actualCompression.read(Data.getExecutor(), file);
readRDF(stream, actualFormat, namespaces, base, preserveBNodes, handler);
} catch (final Throwable ex) {
final String message = "Parsing of " + (file == null ? "STDIN" : file)
+ " using format " + actualFormat + " and compression " + actualCompression
+ " failed: " + ex.getMessage();
if (ex instanceof IOException) {
throw new IOException(message, ex);
} else if (ex instanceof RDFParseException) {
throw new RDFParseException(message, ex);
} else if (ex instanceof RDFHandlerException) {
throw new RDFHandlerException(message, ex);
}
throw new RuntimeException(message, ex);
} finally {
if (stream != System.in) {
Util.closeQuietly(stream);
}
}
}