本文整理汇总了Java中org.apache.jena.tdb.TDBFactory类的典型用法代码示例。如果您正苦于以下问题:Java TDBFactory类的具体用法?Java TDBFactory怎么用?Java TDBFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TDBFactory类属于org.apache.jena.tdb包,在下文中一共展示了TDBFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length != 3) {
System.err.println("Wrong arguments");
showUsage();
}
System.out.println("Model file : " + args[0]);
System.out.println("Model URI : " + args[1]);
System.out.println("Model tdb dir: " + args[2]);
Dataset dataset = TDBFactory.createDataset(args[2]);
try {
Model model = dataset.getNamedModel(args[1]);
TDBLoader.loadModel(model, args[0]);
} finally {
dataset.close();
}
}
示例2: loadOEModelToTdb
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
/**
* Fetch a model from Ontology Editor, load and return as TDB-backed Jena model.
*
* @param endpoint
* @param tDbDirectoryPath
* @return
* @throws OEConnectionException
* @throws IOException
*/
public static Model loadOEModelToTdb(OEModelEndpoint endpoint, String tDbDirectoryPath) throws IOException, OEConnectionException {
Preconditions.checkNotNull(endpoint);
Preconditions.checkArgument(!Strings.isNullOrEmpty(tDbDirectoryPath));
if (logger.isDebugEnabled()) {
logger.debug("OEModelEndpoint: {}", endpoint);
logger.debug("TDB Dir path : {}", tDbDirectoryPath);
}
String modelAsTTL = endpoint.fetchData();
Dataset dataset = TDBFactory.createDataset(tDbDirectoryPath);
Model model = dataset.getNamedModel(endpoint.modelIri);
model.read(new ByteArrayInputStream(modelAsTTL.getBytes()), "TTL");
return model;
}
示例3: init
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public void init(String db, String uri, String lucene) {
Dataset ds = TDBFactory.createDataset(db);
// Lucene configuration
try {
Directory luceneDir = FSDirectory.open(new File(lucene));
EntityDefinition entDef = new EntityDefinition("comment", "text", RDFS.comment);
// Set uid in order to remove index entries automatically
entDef.setUidField("uid");
StandardAnalyzer stAn = new StandardAnalyzer(Version.LUCENE_4_9);
dataset = TextDatasetFactory.createLucene(ds, luceneDir, entDef, stAn);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
baseURI = uri;
servers = new ArrayList<>();
tdQueue = new PriorityQueue<ThingDescription>();
loadTDQueue();
}
示例4: queryData
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static List<String> queryData(String query){
Dataset db = TDBFactory.createDataset("temp/dataset");
db.begin(ReadWrite.READ);
Model model = db.getDefaultModel();
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
List<String> answer = new ArrayList<String>();
while(results.hasNext()){
QuerySolution t = results.nextSolution();
RDFNode x = t.get("x");
String s = x.toString();
System.out.println(s);
answer.add(s.substring(7));
}
qexec.close();
db.close();
return answer;
}
示例5: mainTDB
import org.apache.jena.tdb.TDBFactory; //导入依赖的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()) ;
}
示例6: RelEx
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public RelEx() {
tokenizer = new Tokenizer();
model = ModelFactory.createDefaultModel();
model.setNsPrefix("rdfs", RDFS_NS);
model.setNsPrefix("rdf", RDF_NS);
model.setNsPrefix("owl", OWL_NS);
model.setNsPrefix("dbpedia", DBPEDIA_NS);
model.setNsPrefix("dbpedia-owl", DBPEDIA_OWL_NS);
model.setNsPrefix("schema", SCHEMA_NS);
model.setNsPrefix("wordnet-ontology", WORDNET_ONTOLOGY_NS);
model.setNsPrefix("wn31", WN31_NS);
final String wn31loc = System.getProperty("user.home") + "/wn31_tdb";
log.info("Initializing WordNet 3.1 TDB database at {}", wn31loc);
wn31tdb = TDBFactory.createDataset(wn31loc);
}
示例7: buildBaseDataset
import org.apache.jena.tdb.TDBFactory; //导入依赖的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;
}
示例8: initialise
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
@Override
public void initialise(Map<String, Object> configuration) throws PluginInitialisationException {
LOGGER.debug("Initialising ontology plugin: {}", PLUGIN_NAME);
if (!configuration.containsKey(ENABLED_CFGKEY)) {
LOGGER.info("No '{}' config key - assuming plugin disabled", ENABLED_CFGKEY);
} else {
enabled = (Boolean)configuration.get(ENABLED_CFGKEY);
if (enabled) {
if (!configuration.containsKey(TDB_PATH_CFGKEY)) {
throw new PluginInitialisationException("No " + TDB_PATH_CFGKEY + " specified - cannot create TDB dataset.");
} else {
this.dataset = TDBFactory.createDatasetGraph((String) configuration.get(TDB_PATH_CFGKEY));
}
}
}
}
示例9: main
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static void main(String... argv)
{
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1" ;
Dataset dataset = TDBFactory.createDataset(directory) ;
// Potentially expensive query.
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
// See http://incubator.apache.org/jena/documentation/query/app_api.html
Query query = QueryFactory.create(sparqlQueryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
try {
ResultSet results = qexec.execSelect() ;
for ( ; results.hasNext() ; )
{
QuerySolution soln = results.nextSolution() ;
int count = soln.getLiteral("count").getInt() ;
System.out.println("count = "+count) ;
}
} finally { qexec.close() ; }
// Close the dataset.
dataset.close();
}
示例10: main
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static void main(String... argv)
{
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1" ;
Dataset dataset = TDBFactory.createDataset(directory) ;
// Potentially expensive query.
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
// See http://incubator.apache.org/jena/documentation/query/app_api.html
Query query = QueryFactory.create(sparqlQueryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(results) ;
qexec.close() ;
dataset.close();
}
示例11: main
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static void main(String... argv)
{
DatasetGraphTransaction dsg = (DatasetGraphTransaction)TDBFactory.createDatasetGraph() ;
// Start READ transaction.
dsg.begin(ReadWrite.READ) ;
try
{
// Do some queries
String sparqlQueryString1 = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
execQuery(sparqlQueryString1, dsg) ;
} finally
{
dsg.end() ;
}
}
示例12: SemaphoreModel
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public SemaphoreModel(File tdbDirectory, String graphName, boolean resetTDB) throws IOException {
if (resetTDB && tdbDirectory.exists()) {
FileUtils.deleteDirectory(tdbDirectory);
}
Dataset dataset = TDBFactory.createDataset(tdbDirectory.getAbsolutePath());
if ((graphName == null) || (graphName.trim().length() == 0)) {
model = dataset.getNamedModel(graphName);
} else {
model = dataset.getDefaultModel();
}
setPrefixes();
}
示例13: loadModelToTdb
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
/**
* Fetch a model at the specified URI, load and return an TDB-backed Jena model.
*
* @param rdfUri
* @param modelId
* @param tDbDirectoryPath
* @return
*/
public static Model loadModelToTdb(String rdfUri, String modelId, String tDbDirectoryPath) {
if (logger.isDebugEnabled()) {
logger.debug("RDF URI : {}", rdfUri);
logger.debug("Model ID: {}", modelId);
logger.debug("TDB DIR: {}", tDbDirectoryPath);
}
Dataset dataset = TDBFactory.createDataset(tDbDirectoryPath);
Model model = dataset.getNamedModel(modelId);
TDBLoader.loadModel(model, rdfUri );
return model;
}
示例14: queryData2
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static Boolean queryData2(String query){
Dataset db = TDBFactory.createDataset("temp/dataset");
db.begin(ReadWrite.READ);
Model model = db.getDefaultModel();
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
List<String> answer = new ArrayList<String>();
Boolean t = (qexec.execAsk());
qexec.close();
db.close();
return t;
}
示例15: main
import org.apache.jena.tdb.TDBFactory; //导入依赖的package包/类
public static void main(String... args) {
//org.seaborne.delta.cmds.patchparse.main("/home/afs/tmp/X.rdfp");
org.seaborne.delta.cmds.rdf2patch.main("/home/afs/tmp/D.ttl");
System.exit(0);
// FileOps.ensureDir("DB");
// FileOps.clearAll("DB");
DatasetGraph dsg = TDBFactory.createDatasetGraph();
Txn.executeWrite(dsg, ()->{});
DatasetGraph dsg1 = new DatasetGraphOne(dsg.getDefaultGraph());
DatasetGraph dsg2 = RDFPatchOps.textWriter(dsg1, System.out);
Txn.executeWrite(dsg1, ()->{});
Txn.executeWrite(dsg2, ()->{});
}