本文整理汇总了Java中org.apache.jena.util.FileManager类的典型用法代码示例。如果您正苦于以下问题:Java FileManager类的具体用法?Java FileManager怎么用?Java FileManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileManager类属于org.apache.jena.util包,在下文中一共展示了FileManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LocalGraph
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public LocalGraph(String filename) {
// create an empty model
model = ModelFactory.createDefaultModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null) {
throw new IllegalArgumentException("File: " + filename + " not found");
}
// read the RDF N-Triple file
model.read(in, null, "N-TRIPLE");
namespacesToNames = new HashMap<String, Set<String>>();
}
示例2: initializeJenaFileManager
import org.apache.jena.util.FileManager; //导入依赖的package包/类
private void initializeJenaFileManager() {
if (! jenaFileManagerInitialized) {
// Only initialize once to avoid adding the same locators
// (but no need to synchronize, the occassional extra should be ok)
jenaFileManagerInitialized = true;
// So that it can find our location-mapping.n3
// and the OWLs in classpath /org.apache.taverna.prov.owl/
FileManager.get().addLocatorClassLoader(getClass().getClassLoader());
Model mapping = ModelFactory.createDefaultModel();
InputStream mappingStream = getClass().getResourceAsStream("/location-mapping.n3");
mapping.read(mappingStream, "", "N3");
FileManager.get().setLocationMapper(new LocationMapper(mapping));
OntDocumentManager.getInstance().setFileManager(FileManager.get());
}
}
示例3: main
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public static void main(String[] args) {
VotingSystemData votingSystemData = new VotingSystemData();
URL fileURL = VotingSystemData.class.getClassLoader().getResource(
"data/app_voting_codes_v2.txt");
System.out.println(fileURL.getFile());
File file = new File(fileURL.getFile());
VoteModel voteModel = votingSystemData.generateData(file, FileManager
.get().loadModel("/Users/andrea/Documents/workspaceMars/clodg2/eswc2016.rdf"));
try {
OutputStream adminModelOut = new FileOutputStream(
"rdf/voting_admin.ttl");
voteModel.getAdminModel().write(adminModelOut, "TURTLE");
OutputStream publicModelOut = new FileOutputStream(
"rdf/voting_public.ttl");
voteModel.getPublicModel().write(publicModelOut, "TURTLE");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: main
import org.apache.jena.util.FileManager; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
// Model model =
// FileManager.get().loadModel("out/eswc_data_final_swdf.rdf");
Model model = FileManager.get().loadModel("out/twitterWidget.rdf");
Model model2 = ModelFactory.createDefaultModel();
OutputStream out = null;
try {
out = new FileOutputStream("./out/eswc.json");
model2.setNsPrefixes(model.getNsPrefixMap());
model2.add(model);
// model2.write(out);
// model2.write(out, "RDF/JSON") ;
model2.write(out, "JSON-LD");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例5: readModel
import org.apache.jena.util.FileManager; //导入依赖的package包/类
/**
* read RDF model from file/URL
*
* @param fileNameOrUri file name or URI to be read
* @return Model that contains the data in the fileNameOrUri
*/
public static Model readModel(String fileNameOrUri) {
long startTime = System.currentTimeMillis();
Model model = ModelFactory.createDefaultModel();
try (InputStream in = FileManager.get().open(fileNameOrUri)) {
if (fileNameOrUri.contains(".ttl") || fileNameOrUri.contains(".n3")) {
logger.info("Opening Turtle file");
model.read(in, null, "TTL");
} else if (fileNameOrUri.contains(".rdf")) {
logger.info("Opening RDFXML file");
model.read(in, null);
} else if (fileNameOrUri.contains(".nt")) {
logger.info("Opening N-Triples file");
model.read(in, null, "N-TRIPLE");
} else {
logger.info("Content negotiation to get RDFXML from " + fileNameOrUri);
model.read(fileNameOrUri);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
logger.info("Loading " + fileNameOrUri + " is done in " + (System.currentTimeMillis() - startTime) + "ms.");
return model;
}
示例6: buildBaseDataset
import org.apache.jena.util.FileManager; //导入依赖的package包/类
private Dataset buildBaseDataset() {
Dataset jenaData;
if (StringUtils.isNotBlank(jenaConfig.getAssemblerFile())) {
LOGGER.debug("Building dataset from assembler file {}", jenaConfig.getAssemblerFile());
jenaData = DatasetFactory.assemble(jenaConfig.getAssemblerFile(), jenaConfig.getAssemblerDataset());
} else if (StringUtils.isNotBlank(jenaConfig.getTdbPath())) {
LOGGER.debug("Building dataset from TDB data at {}", jenaConfig.getTdbPath());
jenaData = TDBFactory.createDataset(jenaConfig.getTdbPath());
} else {
LOGGER.debug("Building dataset from ontology URI {}", jenaConfig.getOntologyUri());
FileManager fileManager = FileManager.get();
Model model = fileManager.loadModel(jenaConfig.getOntologyUri());
// Build the base dataset backed by the model loaded from the URI
jenaData = DatasetFactory.create(model);
}
return jenaData;
}
示例7: initstore
import org.apache.jena.util.FileManager; //导入依赖的package包/类
protected boolean initstore() {
if (conn != null) {
try {
ResultSet tables = conn.getMetaData().getTables(null, null, null, new String[]{"TABLE"});
boolean exists = tables.next();
tables.close();
if (!exists) {
startTransaction();
String schema = FileManager.get().readWholeFileAsUTF8(DATABASE_SCHEMA);
Statement s = conn.createStatement();
for (String statement : schema.split(";")) {
String sql = statement.trim();
if (!sql.isEmpty() && ! sql.startsWith("--")) {
s.execute(statement);
}
}
commit();
}
return ! exists;
} catch (Exception e) {
log.error("Failed to access security database", e);
}
}
return false;
}
示例8: validate
import org.apache.jena.util.FileManager; //导入依赖的package包/类
@POST
@Consumes({"text/plain"})
public Response validate(@Context HttpHeaders hh, InputStream body) {
MultivaluedMap<String, String> parameters = new MultivaluedStringMap( uriInfo.getQueryParameters() );
if ( parameters.get(Parameters.VALIDATE) != null ) {
if (body != null) {
for (String uri : FileManager.get().readWholeFileAsUTF8(body).split("\\s")) {
parameters.add(Parameters.VALIDATE, uri);
}
}
Command command = Registry.get().make(Operation.Validate, uriInfo.getPath(), parameters);
command.setRequestor(getRequestor(request));
return command.execute();
} else {
throw new WebApiException(Response.Status.BAD_REQUEST, "No operations supported on text/plain other than validate");
}
}
示例9: doForwardingTest
import org.apache.jena.util.FileManager; //导入依赖的package包/类
private void doForwardingTest() {
// Skip test unless we are running in a set up with accessible configuration
if (new File(PROXY_CONFIG).canWrite()) {
assertEquals(201, postFileStatus("test/bw-forward.ttl", REG1));
assertEquals(404, getResponse(REG1 + "/eabw/ukc2102-03600").getStatus());
assertEquals(204, post(REG1 + "/_eabw?update&status=stable").getStatus());
assertEquals(200, getResponse(REG1 + "/eabw/ukc2102-03600").getStatus());
Model m = getModelResponse(REG1 + "/eabw/ukc2102-03600");
Resource bw = m.getResource("http://environment.data.gov.uk/id/bathing-water/ukc2102-03600");
assertEquals("Spittal", RDFUtil.getStringValue(bw, SKOS.prefLabel));
// convert forwarding to proxying, will only actually function if nginx is up and test doesn't require that
assertEquals(204, invoke("PATCH", "test/bw-proxy-patch.ttl", REG1 + "/eabw").getStatus());
String proxyConfig = FileManager.get().readWholeFileAsUTF8(PROXY_CONFIG);
assertTrue(proxyConfig.contains("location /reg1/eabw"));
assertTrue(proxyConfig.contains("proxy_pass http://environment.data.gov.uk/doc/bathing-water/"));
// Switch batch to forwarding mode to check switching off proxy works
assertEquals(204, invoke("PATCH", "test/bw-forward-patch.ttl", REG1 + "/eabw").getStatus());
proxyConfig = FileManager.get().readWholeFileAsUTF8(PROXY_CONFIG);
assertFalse(proxyConfig.contains("location /reg1/eabw"));
assertEquals(200, getResponse(REG1 + "/eabw/ukc2102-03600").getStatus());
}
}
示例10: testBasicFacets
import org.apache.jena.util.FileManager; //导入依赖的package包/类
@Test
public void testBasicFacets() {
FacetService service = new FacetService();
service.setSpecFile("test/facets/dataset-facets.ttl");
List<FacetSpec> facetSpecs = service.getSpecList();
assertEquals(2, facetSpecs.size());
FacetSpec spec = facetSpecs.get(0);
assertEquals("Type", spec.getName());
assertEquals("type", spec.getVarname());
assertEquals("<http://purl.org/linked-data/registry#itemClass>", spec.getPropertyPath());
Model testData = FileManager.get().loadModel("test/facets/facet-test.ttl");
// check(service, testData, null, 4);
check(service, testData, "type=<http://example.com/test#type1>", 2);
check(service, testData, "type=<http://example.com/test#type2>", 2);
check(service, testData, "type=<http://example.com/test#type3>", 1);
check(service, testData, "category=<http://example.com/test#cat2>", 2);
check(service, testData, "type=<http://example.com/test#type1>|category=<http://example.com/test#cat2>", 1);
}
示例11: main
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public static void main (String args[]) {
// create an empty model
Model model1 = ModelFactory.createDefaultModel();
Model model2 = ModelFactory.createDefaultModel();
// use the class loader to find the input file
InputStream in1 = FileManager.get().open(inputFileName1);
if (in1 == null) {
throw new IllegalArgumentException( "File: " + inputFileName1 + " not found");
}
InputStream in2 = FileManager.get().open(inputFileName2);
if (in2 == null) {
throw new IllegalArgumentException( "File: " + inputFileName2 + " not found");
}
// read the RDF/XML files
model1.read( in1, "" );
model2.read( in2, "" );
// merge the graphs
Model model = model1.union(model2);
// print the graph as RDF/XML
model.write(System.out, "RDF/XML-ABBREV");
System.out.println();
}
示例12: main
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public static void main (String args[]) {
// create an empty model
Model model = ModelFactory.createDefaultModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException( "File: " + inputFileName + " not found");
}
// read the RDF/XML file
model.read( in, "");
// select all the resources with a VCARD.FN property
ResIterator iter = model.listResourcesWithProperty(VCARD.FN);
if (iter.hasNext()) {
System.out.println("The database contains vcards for:");
while (iter.hasNext()) {
System.out.println(" " + iter.nextResource()
.getRequiredProperty(VCARD.FN)
.getString() );
}
} else {
System.out.println("No vcards were found in the database");
}
}
示例13: checkAgainstExpected
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public static void checkAgainstExpected(String templateFile, String dataFile, String loadDirs, String resultFile) throws IOException {
Model m = convert(templateFile, dataFile, loadDirs);
assertNotNull(m);
String DUMMY = "http://example.com/DONOTUSE/";
Model expected = FileManager.get().loadModel(resultFile, DUMMY, "Turtle");
expected = RDFUtil.mapNamespace(expected, DUMMY, "");
boolean same = m.isIsomorphicWith(expected);
// boolean rev = expected.isIsomorphicWith(m);
if (!same) {
System.err.println("Result mismatch, result was:");
m.write(System.err, "Turtle");
System.err.println("Expected:");
expected.write(System.err, "Turtle");
}
assertTrue( same );
}
示例14: readModel
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public static Model readModel(String fileNameOrUri)
{
long startTime = System.currentTimeMillis();
Model model = ModelFactory.createDefaultModel();
java.io.InputStream in = FileManager.get().open( fileNameOrUri ); ;
if (in == null) {
throw new IllegalArgumentException(
"File: " + fileNameOrUri + " not found");
}
if(fileNameOrUri.contains(".ttl") || fileNameOrUri.contains(".n3")){
logger.info("Opening Turtle file");
model.read(in, null, "TTL");
}else if(fileNameOrUri.contains(".rdf")){
logger.info("Opening RDFXML file");
model.read(in, null);
}else if(fileNameOrUri.contains(".nt")){
logger.info("Opening N-Triples file");
model.read(in, null, "N-TRIPLE");
}else{
logger.info("Content negotiation to get RDFXML from " + fileNameOrUri);
model.read(fileNameOrUri);
}
logger.info("Loading " + fileNameOrUri + " is done in " + (System.currentTimeMillis()-startTime) + "ms.");
return model;
}
示例15: readModel
import org.apache.jena.util.FileManager; //导入依赖的package包/类
public static Model readModel(String fileNameOrUri)
{
long startTime = System.currentTimeMillis();
Model model=ModelFactory.createDefaultModel();
java.io.InputStream in = FileManager.get().open( fileNameOrUri );
if (in == null) {
throw new IllegalArgumentException(
"File: " + fileNameOrUri + " not found");
}
if(fileNameOrUri.contains(".ttl") || fileNameOrUri.contains(".n3")){
logger.info("Opening Turtle file");
model.read(in, null, "TTL");
}else if(fileNameOrUri.contains(".rdf")){
logger.info("Opening RDFXML file");
model.read(in, null);
}else if(fileNameOrUri.contains(".nt")){
logger.info("Opening N-Triples file");
model.read(in, null, "N-TRIPLE");
}else{
logger.info("Content negotiation to get RDFXML from " + fileNameOrUri);
model.read(fileNameOrUri);
}
logger.info("Loading " + fileNameOrUri + " is done in " + (System.currentTimeMillis()-startTime) + "ms.");
return model;
}