本文整理匯總了Java中com.hp.hpl.jena.query.Dataset類的典型用法代碼示例。如果您正苦於以下問題:Java Dataset類的具體用法?Java Dataset怎麽用?Java Dataset使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Dataset類屬於com.hp.hpl.jena.query包,在下文中一共展示了Dataset類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyToTdb
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
private void copyToTdb() throws RepositoryException {
if ( !needsSave || null == tdbdir ) {
return;
}
final Dataset dataset = TDBFactory.createDataset( tdbdir.getAbsolutePath() );
try {
rc.export( new TdbExporter( dataset ) );
}
catch ( RepositoryException | RDFHandlerException e ) {
log.error( "Problem exporting data to TDB", e );
dataset.abort();
}
finally {
dataset.close();
}
}
示例2: getAllEntityEvents
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
static ArrayList<String> getAllEntityEvents (Dataset dataset, String entity) {
ArrayList<String> events = new ArrayList<String>();
Iterator<String> it = dataset.listNames();
while (it.hasNext()) {
String name = it.next();
if (!name.equals(instanceGraph) && (!name.equals(provenanceGraph))) {
Model namedModel = dataset.getNamedModel(name);
StmtIterator siter = namedModel.listStatements();
while (siter.hasNext()) {
Statement s = siter.nextStatement();
String object = getObjectValue(s).toLowerCase();
if (object.indexOf(entity.toLowerCase()) > -1) {
String subject = s.getSubject().getURI();
if (!events.contains(subject)) {
events.add(subject);
}
}
}
}
}
return events;
}
示例3: testSomeMethod2
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
@Test
public void testSomeMethod2() throws Exception {
Dataset ds = TDBFactory.createDataset("/scratch/WORK2/jena/dataset2/");
OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym1"));
OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym2"));
OntClass thing = model1.createClass("http://www.w3.org/2002/07/owl#Thing");
model1.createIndividual("http://example.com/onto1#VijayRaj", thing);
model2.createIndividual("http://example.;cegilovcom/onto2#VijayRaj", thing);
Model m = model1.union(model2);
FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/mergetestds.xml");
RDFDataMgr.write(fw, ds, RDFFormat.NQUADS_UTF8);
}
示例4: createMemDatasetFromCode
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
/**
* Creates an in-memory Jena TDB data set and Lucene index from code.
* @return
*/
public Dataset createMemDatasetFromCode(){
log.info("Construct an in-memory dataset with in-memory lucene index using code") ;
TextQuery.init();
// Build a text dataset by code.
// Here , in-memory base data and in-memory Lucene index
// Base data
Dataset jenads = DatasetFactory.createMem() ;
Property streetAddress = jenads.getDefaultModel().createProperty("http://schema.org/streetAddress");
// Define the index mapping
//EntityDefinition entDef = new EntityDefinition("uri", "text", RDFS.label.asNode()) ;
EntityDefinition entDef = new EntityDefinition("uri", "text", streetAddress.asNode()) ;
// Lucene, in memory.
Directory dir = new RAMDirectory();
// Join together into a dataset
Dataset ds = TextDatasetFactory.createLucene(jenads, dir, entDef) ;
return ds ;
}
示例5: createPersistentDatasetFromCode
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
/**
* Creates a persistent Jena TDB data set and Lucene index.
* @return
* @throws IOException
*/
public Dataset createPersistentDatasetFromCode() throws IOException{
log.info("Construct a persistent Jena data set with lucene index using code") ;
// Build a text dataset by code.
TextQuery.init();
// Remove old files and folders
deleteFiles(JENA_TDB_TEMP_FOLDER);
deleteFiles(LUCENE_INDEX_TEMP_FOLDER);
// Creates new folders
JENA_TDB_TEMP_FOLDER.mkdirs();
LUCENE_INDEX_TEMP_FOLDER.mkdirs();
// Creates persisted Jena data set and Lucene index
Dataset jenaDataset = TDBFactory.createDataset(JENA_TDB_TEMP_FOLDER.getAbsolutePath()) ;
// Lucene, persisted.
Directory luceneIndex = FSDirectory.open(LUCENE_INDEX_TEMP_FOLDER);
// Define the index mapping
EntityDefinition entDef = new EntityDefinition("uri", "text", RDFS.label.asNode()) ;
// Join together into a dataset
return TextDatasetFactory.createLucene(jenaDataset, luceneIndex, entDef) ;
}
示例6: 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)) ;
}
示例7: TDBloading
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
/**
* Load jena TDB
*/
private void TDBloading(){
logger.info("TDB loading");
// create model from tdb
Dataset dataset = TDBFactory.createDataset(tdbDirectory);
// assume we want the default model, or we could get a named model here
dataset.begin(ReadWrite.READ);
model = dataset.getDefaultModel();
dataset.end() ;
// if model is null load local dataset into jena TDB
if(model == null)
TDBloading(datasetFile);
}
示例8: demoOfUsingADirectory
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
static void demoOfUsingADirectory() {
// Make a TDB-backed dataset
String directory = TDB_DIR;
// read something
Dataset dataset = TDBFactory.createDataset(directory);
logger.debug("read tx start!!!");
demoOfReadTransaction(dataset);
logger.debug("read tx end!!!");
dataset.close();
// write something
dataset = TDBFactory.createDataset(directory);
logger.debug("write tx start!!!");
demoOfWriteTransaction(dataset);
logger.debug("write tx end!!!");
dataset.close();
// read again
dataset = TDBFactory.createDataset(directory);
logger.debug("read tx start!!!");
demoOfReadTransaction(dataset);
logger.debug("read tx end!!!");
dataset.close();
}
示例9: demoOfReadTransaction
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
private static void demoOfReadTransaction(Dataset dataset) {
dataset.begin(ReadWrite.READ);
// Get model inside the transaction
Model model = dataset.getDefaultModel();
// query the inserted facts
StringBuilder query = SPARQLUtils.getRegualrSPARQLPREFIX();
query.append("PREFIX foaf: <http://xmlns.com/foaf/0.1/>").append(Constants.NEWLINE);
query.append("SELECT DISTINCT ?person WHERE {?person rdf:type foaf:Person}");
SPARQLUtils.query(model, query.toString(), "?person");
model.close();// closing the model to flush
dataset.end();
}
示例10: 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();
}
示例11: retrievePlanLifecycleState
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
/**
* Retrieve the life cycle state for a plan stored in Fedora
*
* @param planId
* the id of the plan
* @param uriInfo
* the {@link javax.ws.rs.core.UriInfo} injected by JAX-RS for having the context
* path available
* @return the plan's current life cycle state
* @throws javax.jcr.RepositoryException
* if an error occurred while fetching the life cycle tate of
* the plan
*/
@GET
@Path("{id}")
public Response retrievePlanLifecycleState(@PathParam("id")
final String planId, @Context
UriInfo uriInfo) throws RepositoryException {
/* fetch the plan RDF from fedora */
final String planUri = "/" + Plans.PLAN_FOLDER + planId;
final FedoraObject plan = this.objectService.findOrCreateObject(this.session, planUri);
/* get the relevant information from the RDF dataset */
final IdentifierTranslator subjects = new DefaultIdentifierTranslator(); final Dataset data = plan.getPropertiesDataset(subjects);
final Model rdfModel = SerializationUtils.unifyDatasetModel(data);
final String lifecycle = rdfModel
.listStatements(subjects.getSubject(plan.getNode().getPath()), rdfModel.getProperty("http://scapeproject.eu/model#hasLifecycleState"),
(RDFNode) null).next().getObject().asLiteral().getString();
return Response.ok(lifecycle, MediaType.TEXT_PLAIN).build();
}
示例12: addModel
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
@Test
public void addModel() throws Exception {
final Dataset ds = TDBFactory.createDataset();
final DatasetPopulator dsp = new DatasetPopulator(ds);
final Model model = ModelFactory.createDefaultModel();
final Resource s = model.createResource();
final Property p = model.createProperty("urn:example:prop", "foo");
final Resource o = model.createResource();
model.add(s, p, o);
dsp.addModel(model);
ds.begin(ReadWrite.READ);
try {
assertTrue(ds.getDefaultModel().containsAll(model));
} finally {
ds.end();
}
}
示例13: inferMissingPropertyNames
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
@Test
public void inferMissingPropertyNames() throws Exception {
final Dataset ds = TDBFactory.createDataset();
final DatasetPopulator dsp = new DatasetPopulator(ds);
dsp.addModel(loadModel("infer-property-names/data.ttl"));
final Model x = loadModel("infer-property-names/expected.ttl");
ds.begin(ReadWrite.READ);
try {
final Model m = ds.getDefaultModel();
assertTrue(m.containsAll(x));
} finally {
ds.end();
}
}
示例14: findCompatiblePublicProperties
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
@Test
public void findCompatiblePublicProperties() {
final Dataset ds = loadDataset("compatibility/properties.ttl");
final CompatibleResourceFinder finder = new CompatibleResourceFinder(ds);
final Type y0 = type(0);
final Type y1 = type(1);
final Type y2 = type(2);
final Type y3 = type(3);
final Property p0 = property(0, y0);
final Property p1 = property(1, y1);
final Property p2 = property(2, y2);
final Property p3 = property(3, y3);
final Action a1 = action(widget(1, p1), p1);
final Action a2 = action(widget(2, p2), p2, p3);
final PublishedProperty pp1 = new PublishedProperty(p1, a1);
final PublishedProperty pp2 = new PublishedProperty(p2, a2);
final Set<PublishedProperty> xpps = setOf(pp1, pp2);
final Set<PublishedProperty> pps = finder.findCompatibleOffers(p0);
assertEquals(pps, xpps);
}
示例15: findCompatibleFunctionalities
import com.hp.hpl.jena.query.Dataset; //導入依賴的package包/類
@Test
public void findCompatibleFunctionalities() {
final Dataset ds = loadDataset("compatibility/functionalities.ttl");
final CompatibleResourceFinder finder = new CompatibleResourceFinder(ds);
final Functionality f0 = functionality(0);
final Functionality f1 = functionality(1);
final Functionality f2 = functionality(2);
final Action a1 = action(widget(1), f1);
final Action a2 = action(widget(2), f2);
final RealizedFunctionality rt1 = new RealizedFunctionality(f1, a1);
final RealizedFunctionality rt2 = new RealizedFunctionality(f2, a2);
final Set<RealizedFunctionality> xrts = setOf(rt1, rt2);
final Set<RealizedFunctionality> rts = finder.findCompatibleOffers(f0);
assertEquals(rts, xrts);
}