本文整理汇总了Java中org.eclipse.rdf4j.rio.Rio.getParserFormatForFileName方法的典型用法代码示例。如果您正苦于以下问题:Java Rio.getParserFormatForFileName方法的具体用法?Java Rio.getParserFormatForFileName怎么用?Java Rio.getParserFormatForFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.rio.Rio
的用法示例。
在下文中一共展示了Rio.getParserFormatForFileName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Initialize repository and load triples
*
* @throws IOException
*/
public void init() throws IOException {
LOG.debug("Initialize repository");
repo = new SailRepository(new MemoryStore());
repo.initialize();
Optional<RDFFormat> fmt = Rio.getParserFormatForFileName(path.toString());
if (!fmt.isPresent()) {
throw new IOException("Could not determine file type");
}
LOG.debug("Adding triples");
BufferedReader r = Files.newBufferedReader(path);
Date start = new Date();
RepositoryConnection con = repo.getConnection();
try {
con.add(r, BASE_URI, fmt.get());
} catch (RepositoryException cve) {
LOG.error("Error adding triples", cve);
}
LOG.info("{} triples loaded in {} ms",
con.size(), new Date().getTime() - start.getTime());
if(con.isEmpty()) {
LOG.error("No statements loaded");
close();
}
}
示例2: init
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
private void init(Result<Description> descriptionResult, Interpreter interpreter) {
if (descriptionResult.getContent().isPresent()) {
Description description = descriptionResult.getContent().get();
String mimeType = description.getDescribedByLink().getType().orElse(null);
Optional<RDFFormat> maybeFormat = Rio.getParserFormatForMIMEType(mimeType);
if (!maybeFormat.isPresent()) {
String filename = descriptionResult.getUri().toString();
maybeFormat = Rio.getParserFormatForFileName(filename);
}
if (maybeFormat.isPresent()) {
createDescriptionNode(description, maybeFormat.get(), interpreter);
} else {
rawContent = description.getRawContent();
}
}
}
示例3: getRdfFormat
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Tries to determine the RDF format of the given URL. If the format could not be determined,
* the default value of {@link RDFFormat#TURTLE} will be returned.
* @param url location of an RDF document.
* @return the resolved format of the RDF document, or {@code turtle} if the resolving failed.
* @throws IOException if an error occured during retrieval of the RDF document.
*/
private RDFFormat getRdfFormat(URL url) throws IOException {
Optional<RDFFormat> format = Rio.getParserFormatForFileName(url.getPath());
if (!format.isPresent()) {
URLConnection connection = url.openConnection();
connection.setRequestProperty(HttpHeaders.ACCEPT, CUSTOM_ACCEPT_HEADER);
format = Rio.getParserFormatForMIMEType(connection.getContentType());
}
return format.orElse(RDFFormat.TURTLE);
}
示例4: listStatus
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Override
protected List<FileStatus> listStatus(JobContext job) throws IOException {
List<FileStatus> filteredList = new ArrayList<>();
for (FileStatus fs : super.listStatus(job)) {
if (Rio.getParserFormatForFileName(fs.getPath().getName()) != null) {
filteredList.add(fs);
}
}
return filteredList;
}
示例5: main
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Main program
*
* @param args
*/
public static void main(String[] args) {
logger.info("-- START --");
if (args.length < 2) {
logger.error("No input or output file");
System.exit(-1);
}
Optional<RDFFormat> fmtin = Rio.getParserFormatForFileName(args[0]);
if(!fmtin.isPresent()) {
logger.error("No parser for input {}", args[0]);
System.exit(-2);
}
int code = 0;
Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
Serializer s = getSerializer();
s.setOutputFile(new File(args[1]));
try (RepositoryConnection con = repo.getConnection()) {
con.add(new File(args[0]), "http://data.gov.be", fmtin.get());
XMLStreamWriter w = s.getXMLStreamWriter();
w.writeStartDocument();
writeCatalog(w, con);
w.writeEndDocument();
w.close();
} catch (IOException|XMLStreamException|SaxonApiException ex) {
logger.error("Error converting", ex);
System.exit(-1);
} finally {
repo.shutDown();
}
}
示例6: main
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Main program
*
* @param args
*/
public static void main(String[] args) {
logger.info("-- START --");
if (args.length < 2) {
logger.error("No input or output file");
System.exit(-1);
}
Optional<RDFFormat> fmtin = Rio.getParserFormatForFileName(args[0]);
if(!fmtin.isPresent()) {
logger.error("No parser for input {}", args[0]);
System.exit(-2);
}
Optional<RDFFormat> fmtout = Rio.getWriterFormatForFileName(args[1]);
if(!fmtout.isPresent()) {
logger.error("No parser for output {}", args[1]);
System.exit(-3);
}
int code = 0;
Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
try (RepositoryConnection con = repo.getConnection()) {
con.add(new File(args[0]), "http://data.gov.be", fmtin.get());
// Various namespace prefixes
con.setNamespace(DCAT.PREFIX, DCAT.NAMESPACE);
con.setNamespace(DCTERMS.PREFIX, DCTERMS.NAMESPACE);
con.setNamespace(FOAF.PREFIX, FOAF.NAMESPACE);
con.setNamespace("vcard", "http://www.w3.org/2006/vcard/ns#");
con.setNamespace("locn", "http://www.w3.org/ns/locn#");
FileOutputStream fout = new FileOutputStream(new File(args[1]));
RDFWriter writer;
if (fmtout.get().equals(RDFFormat.RDFXML)) {
writer = new RDFXMLPrettyWriterFactory().getWriter(fout);
} else {
writer = Rio.createWriter(fmtout.get(), fout);
}
logger.info("Using writer {}", writer.getClass().getCanonicalName());
con.export(writer);
} catch (IOException ex) {
logger.error("Error converting", ex);
code = -1;
}
repo.shutDown();
System.exit(code);
}