本文整理匯總了Java中com.hp.hpl.jena.query.Dataset.commit方法的典型用法代碼示例。如果您正苦於以下問題:Java Dataset.commit方法的具體用法?Java Dataset.commit怎麽用?Java Dataset.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.Dataset
的用法示例。
在下文中一共展示了Dataset.commit方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadData
import com.hp.hpl.jena.query.Dataset; //導入方法依賴的package包/類
/**
* Import the data into the data set. When a new data set is imported the old data is deleted.
* @param dataset
* @param file
*/
public void loadData(Dataset dataset, String file){
log.info("Start loading") ;
long startTime = System.nanoTime() ;
dataset.begin(ReadWrite.WRITE) ;
try {
Model m = dataset.getDefaultModel() ;
log.info("Number of triples before loading: " + m.size());
RDFDataMgr.read(m, file) ;
log.info("Number of triples after loading: " + m.size());
dataset.commit() ;
}
finally {
dataset.end() ;
}
long finishTime = System.nanoTime() ;
double time = (finishTime-startTime)/1.0e6 ;
log.info(String.format("Finish loading - %.2fms", time)) ;
}
示例2: demoOfWriteTransaction
import com.hp.hpl.jena.query.Dataset; //導入方法依賴的package包/類
private static void demoOfWriteTransaction(Dataset dataset) {
dataset.begin(ReadWrite.WRITE);
Model model = dataset.getDefaultModel();
ModelUtils.fillModel(model, FOAF_BASE_URI, FOAF_SCHEMA_FilePath);
// insert foaf:me rdf:type foaf:Person
Resource me = model.createResource(FOAF_BASE_URI + "me");
Property rdfType = model.getProperty(Constants.RDF_TYPE_URL);
Resource FOAFPersonClass = model.getResource(FOAF_BASE_URI + "Person");
model.add(me, rdfType, FOAFPersonClass);
// model.write(System.out);// for debug
model.close();// closing the model to flush
dataset.commit();
dataset.end();
}
示例3: loadDataset
import com.hp.hpl.jena.query.Dataset; //導入方法依賴的package包/類
/**
* Create a transactional in-memory dataset and load data from a given URI.
* <p/>
* The dataset returned by {@link RDFDataMgr#loadDataset(String)} is not transactional.
*
* @param uri URI of data to load
*
* @return a new dataset
*/
public static Dataset loadDataset(final String uri) {
final Dataset ds = TDBFactory.createDataset();
ds.begin(ReadWrite.WRITE);
try {
RDFDataMgr.read(ds, uri);
ds.commit();
} finally {
ds.end();
}
return ds;
}
示例4: onCreate
import com.hp.hpl.jena.query.Dataset; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rdfread_write);
TextView textView = (TextView) findViewById(R.id.rdfTextView);
textView.setMovementMethod(new ScrollingMovementMethod());
// create tdb dataset
File directory = new File(getFilesDir(), "tdb_dataset");
directory.delete();
directory.mkdir();
Dataset dataset = TDBFactory.createDataset(directory.getAbsolutePath()) ;
dataset.begin(ReadWrite.WRITE);
Model model = dataset.getDefaultModel();
// read a turtle file from assets and write them into a tdb backed model
try {
InputStream skos_ttl = getAssets().open("skos.ttl");
RDFDataMgr.read(model, skos_ttl, Lang.TURTLE);
skos_ttl.close();
InputStream geosparql_rdf_xml = getAssets().open("geosparql_vocab_all.rdf");
RDFDataMgr.read(model, geosparql_rdf_xml, Lang.RDFXML);
geosparql_rdf_xml.close();
} catch (IOException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
// add some example data
String personURI = "http://somewhere/JohnSmith";
String fullName = "John Smith";
Resource johnSmith = model.createResource(personURI);
johnSmith.addProperty(VCARD.FN, fullName);
dataset.commit();
dataset.end();
// read from tdb and print triples
dataset.begin(ReadWrite.READ);
Query query = QueryFactory.create("SELECT * WHERE { ?s ?p ?o } LIMIT 2");
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
String resultString = ResultSetFormatter.asText(results);
Log.d(TAG, resultString);
StringWriter dump = new StringWriter();
RDFDataMgr.write(dump, dataset, RDFFormat.JSONLD_PRETTY);
dataset.end();
dataset.close();
textView.setText(dump.toString());
}
示例5: main
import com.hp.hpl.jena.query.Dataset; //導入方法依賴的package包/類
public static void main(String[] args)
{
Dataset dataset = TDBFactory.createDataset("/opt/fogcutter/quoddy/jenastore/triples");
dataset.begin(ReadWrite.WRITE);
// Get model inside the transaction
Model tdbModel = dataset.getDefaultModel();
Property rdfsLabel = tdbModel.createProperty("http://www.w3.org/2000/01/rdf-schema#", "label");
ResIterator resIter = tdbModel.listSubjectsWithProperty(rdfsLabel, "baseOntologyLoaded");
if( resIter.hasNext() )
{
System.out.println( "our ontology is already loaded, do nothing..." );
}
else
{
System.out.println( "Our ontology is NOT loaded, loading now..." );
OntModel onto = null;
try
{
onto = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, tdbModel);
// Load our Ontology from the OWL file on disk
onto.read("file:ontology/sys_ontology.owl", "TURTLE");
tdbModel.add(onto);
dataset.commit();
}
finally
{
if( dataset != null )
{
dataset.end();
}
}
}
}
示例6: main
import com.hp.hpl.jena.query.Dataset; //導入方法依賴的package包/類
public static void main(String[] args)
{
Dataset dataset = TDBFactory.createDataset( "jenastore/triples" );
dataset.begin(ReadWrite.WRITE);
RDFDataMgr.read(dataset, "file:/development/presentations/trijug_semantic/JenaTutorial/data/input/rdfxml/customers.rdf.xml", Lang.RDFXML);
dataset.commit();
dataset.end();
dataset.close();
}