本文整理汇总了Java中org.apache.jena.riot.RDFDataMgr.loadModel方法的典型用法代码示例。如果您正苦于以下问题:Java RDFDataMgr.loadModel方法的具体用法?Java RDFDataMgr.loadModel怎么用?Java RDFDataMgr.loadModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.riot.RDFDataMgr
的用法示例。
在下文中一共展示了RDFDataMgr.loadModel方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAll
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Build all properties for each class contained in a specification file.<br>
* <br>
* Specification file contains tab-separated rows as:<br>
* [ClassName][TAB][JSON example URL]
*
* @param specFile
* @param outFile
* @throws IOException
* @throws JSONException
*/
public void buildAll(String specFile, String inFile, String outFile) throws JSONException, IOException {
logger.info("Started.");
String base = System.getProperty("user.dir") + "/";
FileOutputStream file = new FileOutputStream(new File(base + outFile));
logger.info("user.dir = "+base);
logger.info("Opening RDF file: "+base + inFile);
Model m = RDFDataMgr.loadModel(base + inFile, Lang.RDFXML);
Scanner in = new Scanner(new File(specFile));
while (in.hasNextLine()) {
String[] line = in.nextLine().split("\t");
build(line[0], line[1], m);
}
in.close();
logger.info("Writing to file "+outFile+ "...");
m.write(file);
file.close();
logger.info("Done.");
}
示例2: getBaseFromFile
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Gets the {@link JenaBase} from the given {@link IFile}.
*
* @param file
* the {@link IFile}
* @return the {@link JenaBase} from the given {@link IFile} if nay, <code>null</code> otherwise
*/
private JenaBase getBaseFromFile(IFile file) {
JenaBase res = null;
final Lang lang = EXTENSION_TO_LANG.get(file.getFileExtension());
if (lang != null) {
try {
final Model model = RDFDataMgr.loadModel(file.getLocation().toFile().getAbsolutePath(), lang);
if (!model.isEmpty()) {
res = new JenaBase(model, file.getFullPath().toString());
}
// CHECKSTYLE:OFF
} catch (Exception e) {
// CHECKSTYLE:ON
Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
UNABLE_TO_LOAD_SEMANTIC_BASE_FROM + file.getLocation().toString(), e));
}
}
return res;
}
示例3: mainTDB
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void mainTDB(String...argv) throws IOException {
DatasetGraphTDB dsg = ((DatasetGraphTransaction)TDBFactory.createDatasetGraph()).get() ;
String DIR = "testing/Inf" ;
String DATA_FILE = DIR+"/rdfs-data.ttl" ;
String VOCAB_FILE = DIR+"/rdfs-vocab.ttl" ;
String RULES_FILE = DIR+"/rdfs-min.rules" ;
Model vocab = RDFDataMgr.loadModel(VOCAB_FILE) ;
Model data = RDFDataMgr.loadModel(DATA_FILE) ;
String rules = FileUtils.readWholeFileAsUTF8(RULES_FILE) ;
rules = rules.replaceAll("#[^\\n]*", "") ;
// TDB
InferenceSetupRDFS_TDB setup = new InferenceSetupRDFS_TDB(vocab, dsg, false) ;
//Graph graph = new GraphRDFS(setup, data.getGraph()) ;
}
示例4: expand
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void expand() throws IOException {
boolean combined = false ;
String DIR = "testing/Inf" ;
String DATA_FILE = "data.ttl" ;
String VOCAB_FILE = "vocab.ttl" ;
String RULES_FILE = DIR+"/rdfs-min.rules" ;
Model vocab = RDFDataMgr.loadModel(VOCAB_FILE) ;
Model data = RDFDataMgr.loadModel(DATA_FILE) ;
String rules = FileUtils.readWholeFileAsUTF8(RULES_FILE) ;
rules = rules.replaceAll("#[^\\n]*", "") ;
InferenceSetupRDFS setup = new InferenceSetupRDFS(vocab, combined) ;
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
InfModel m = ModelFactory.createInfModel(reasoner, vocab, data);
// Expansion Graph
Graph graphExpanded = Factory.createDefaultGraph() ;
StreamRDF stream = StreamRDFLib.graph(graphExpanded) ;
// Apply inferences.
stream = new InferenceProcessorStreamRDF(stream, setup) ;
sendToStream(data.getGraph(), stream) ;
RDFDataMgr.write(System.out, graphExpanded, Lang.TTL) ;
}
示例5: loadClassList
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* @param path
* @return
*/
public static HashMap<String, List<Resource>> loadClassList(String path) {
HashMap<String, List<Resource>> res = new HashMap<>();
// load specification file
Model model = RDFDataMgr.loadModel(path);
// get all graphs
Iterator<Statement> statIt = model.listStatements((Resource) null,
ResourceFactory.createProperty("http://aksw.org/deduplication/relatedGraph"), (RDFNode) null);
while(statIt.hasNext()) {
Statement s = statIt.next();
Resource dataset = s.getSubject();
String graph = s.getObject().as(Resource.class).getURI();
// get all classes for each graph
ArrayList<Resource> classes = new ArrayList<>();
Iterator<RDFNode> nodeIt = model.listObjectsOfProperty(dataset, ResourceFactory.createProperty("http://aksw.org/deduplication/requiredClasses"));
while(nodeIt.hasNext()) {
Resource c = nodeIt.next().as(Resource.class);
classes.add(c);
}
res.put(graph, classes);
}
return res;
}
示例6: loadModelToMem
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Fetch a model at the specified URI, load, and return a memory-backed Jena model.
* @param rdfUri
* @return
*/
public static Model loadModelToMem(String rdfUri) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(rdfUri));
if (logger.isDebugEnabled()) {
logger.debug("Model load URI: {}", rdfUri);
}
return RDFDataMgr.loadModel(rdfUri);
}
示例7: loadDevicePrototype
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public void loadDevicePrototype(URI uri) {
try {
Model model = RDFDataMgr.loadModel(uri.toASCIIString(), RDFLanguages.TURTLE);
store.save(model);
} catch (Throwable ex) {
logger.error(ex.getMessage(), ex);
}
}
示例8: getElement
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @see org.eclipse.mylyn.docs.intent.mapping.ide.connector.IFileConnectorDelegate#getElement(org.eclipse.mylyn.docs.intent.mapping.ide.resource.IFileLocation)
*/
public Object getElement(IFileLocation location) {
final IFile file = (IFile)super.getElement(location);
final Lang lang = EXTENSION_TO_LANG.get(file.getFileExtension());
final Model res = RDFDataMgr.loadModel(file.getLocation().toFile().getAbsolutePath(), lang);
return res;
}
示例9: testTurtle
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testTurtle() throws Exception {
Model m = RDFDataMgr.loadModel("/scratch/WORK2/jena/testModels/test.ttl", Lang.TTL);
FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/ttlAsTriple.triple");
RDFDataMgr.write(fw, m, Lang.NTRIPLES);
}
示例10: validate
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public Model validate(String dataFile, String schemaFile) throws Exception {
log.info("Reading data file " + dataFile);
Model dataModel = RDFDataMgr.loadModel(dataFile); // loadModel(dataFile);
log.info("Reading shapes file " + schemaFile);
Model shapesModel = RDFDataMgr.loadModel(schemaFile);
return validate(dataModel,shapesModel);
}
示例11: plain
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void plain(String...argv) throws IOException {
String DIR = "testing/Inf" ;
// String DATA_FILE = DIR+"/rdfs-data.ttl" ;
// String VOCAB_FILE = DIR+"/rdfs-vocab.ttl" ;
// String RULES_FILE = DIR+"/rdfs-min.rules" ;
String DATA_FILE = "data.ttl" ;
String VOCAB_FILE = "vocab.ttl" ;
String RULES_FILE = DIR+"/rdfs-min.rules" ;
Model vocab = RDFDataMgr.loadModel(VOCAB_FILE) ;
Model data = RDFDataMgr.loadModel(DATA_FILE) ;
String rules = FileUtils.readWholeFileAsUTF8(RULES_FILE) ;
rules = rules.replaceAll("#[^\\n]*", "") ;
InferenceSetupRDFS setup = new InferenceSetupRDFS(vocab, false) ;
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
InfModel m = ModelFactory.createInfModel(reasoner, vocab, data);
inf = m.getGraph() ;
g_rdfs2 = new GraphRDFS(setup, data.getGraph()) ;
//g_rdfs3 = new GraphRDFS3(setup, data.getGraph()) ;
//test(null, null, node("T2")) ;
test(node("T"), null, null ) ;
// Expansion
//InferenceProcessorRDFS proc = new InferenceProcessorRDFS(setup) ;
}
示例12: main2
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static void main2(String ...args) {
setup();
// Patch Log Server
FileOps.exists(PLOG_DIR);
FileOps.clearAll(PLOG_DIR);
PatchLogServer patchLogServer = PatchLogServer.server(PLOG_PORT, PLOG_DIR);
try { patchLogServer.start(); }
catch (BindException ex) {
System.err.println("Can't start the patch log server: "+ex.getMessage());
System.exit(1);
}
// For high availability, need a load balancer that switches between the two Fuskei servers.
// Fuseki server 1
FusekiServer fuseki1 = fuseki1();
RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+"/ds1") ;
// Fuseki server 2
FusekiServer fuseki2 = fuseki2();
RDFConnection conn2 = RDFConnectionFactory.connect("http://localhost:"+F2_PORT+"/ds2") ;
// Some data (data.ttl is in src/main/resources).
Model model = RDFDataMgr.loadModel("data.ttl");
conn1.put(model);
// Kill fuseki1.
fuseki1.stop();
// And fetch data.
Model model2 = conn2.fetch();
System.out.println();
RDFDataMgr.write(System.out, model2, Lang.NT);
System.out.println();
// Remove a triple via conn2.
conn2.update("PREFIX ex: <http://example.org/> DELETE DATA { ex:s ex:p ex:o }");
// Restart Fuseki1.
fuseki1 = fuseki1();
// Not necesary.
// conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+"/ds1") ;
Model model1 = conn1.fetch();
System.out.println();
// Data in Fuseki1. One less triple.
RDFDataMgr.write(System.out, model1, Lang.NT);
System.out.println();
}
示例13: testPlanExecution
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testPlanExecution() throws Exception {
String query = IOUtils.toString(SPARQLGenerate.getStreamManager().open(new LookUpRequest("query.rqg", SPARQLGenerate.MEDIA_TYPE)), "UTF-8");
long start0 = System.currentTimeMillis();
long start = start0;
SPARQLGenerateQuery q = (SPARQLGenerateQuery) QueryFactory.create(query, SPARQLGenerate.SYNTAX);
long now = System.currentTimeMillis();
log.info("needed " + (now - start) + " to parse query");
start = now;
// create generation plan
PlanFactory factory = new PlanFactory();
RootPlan plan = factory.create(q);
Dataset ds = SPARQLGenerateUtils.loadDataset(exampleDir);
now = System.currentTimeMillis();
log.info("needed " + (now - start) + " to get ready");
start = now;
// execute plan
Model output = plan.exec(ds);
now = System.currentTimeMillis();
log.info("executed plan in " + (now - start));
start = now;
log.info("total needed " + (now - start0));
// write output
String fileName = exampleDir.toString() + "/output.ttl";
FileWriter out = new FileWriter(fileName);
try {
output.write(out, "TTL");
// StringWriter sw = new StringWriter();
// output.write(sw, "TTL");
// log.debug("output is " + sw.toString());
} finally {
try {
out.close();
} catch (IOException closeException) {
log.error("Error while writing to file");
}
}
URI expectedOutputUri = exampleDir.toURI().resolve("expected_output.ttl");
Model expectedOutput = RDFDataMgr.loadModel(expectedOutputUri.toString(), Lang.TTL);
StringWriter sw = new StringWriter();
expectedOutput.write(sw, "TTL");
assertTrue(output.isIsomorphicWith(expectedOutput));
}