当前位置: 首页>>代码示例>>Java>>正文


Java ReadWrite类代码示例

本文整理汇总了Java中com.hp.hpl.jena.query.ReadWrite的典型用法代码示例。如果您正苦于以下问题:Java ReadWrite类的具体用法?Java ReadWrite怎么用?Java ReadWrite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReadWrite类属于com.hp.hpl.jena.query包,在下文中一共展示了ReadWrite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadData

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的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)) ;
}
 
开发者ID:fusepoolP3,项目名称:p3-osm-transformer,代码行数:24,代码来源:JenaTextConfig.java

示例2: TDBloading

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的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);

}
 
开发者ID:sisinflab,项目名称:lodreclib,代码行数:21,代码来源:RDFTripleExtractor.java

示例3: demoOfReadTransaction

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的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();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:17,代码来源:TDBManipulation.java

示例4: demoOfWriteTransaction

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的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();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:21,代码来源:TDBManipulation.java

示例5: findOffers

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
private Set<O> findOffers(final T request) {
  final Set<O> offers = new HashSet<>();

  dataset.begin(ReadWrite.READ);

  try {

    final Model model = dataset.getDefaultModel();

    try (QueryExecution qx = QueryExecutionFactory.create(getQuery(request, model), dataset)) {
      final ResultSet rs = qx.execSelect();
      while (rs.hasNext()) {
        offers.add(createOffer(rs.next()));
      }
    }

  } finally {
    dataset.end();
  }

  return offers;
}
 
开发者ID:ewie,项目名称:cobalt,代码行数:23,代码来源:CompatibleResourceFinder.java

示例6: addModel

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
/**
 * Validate a model, infer statements and add it to the dataset
 *
 * @param model the model to add
 *
 * @throws InvalidModelException when the model is invalid according to the ontology
 */
public void addModel(final Model model) throws InvalidModelException {
  // Expect each model's graph to be disjoint from all other model graphs. When that's not the case,
  // the union of all graphs may result in an invalid model, because one model could contain statements
  // incompatible with statements of another model.
  assertModel(model);

  inferPropertyNames(model);

  dataset.begin(ReadWrite.WRITE);
  try {
    dataset.getDefaultModel().add(model);
    dataset.commit();
  } finally {
    dataset.end();
  }
}
 
开发者ID:ewie,项目名称:cobalt,代码行数:24,代码来源:DatasetPopulator.java

示例7: addModel

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的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();
  }
}
 
开发者ID:ewie,项目名称:cobalt,代码行数:22,代码来源:DatasetPopulatorTest.java

示例8: inferMissingPropertyNames

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的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();
  }
}
 
开发者ID:ewie,项目名称:cobalt,代码行数:18,代码来源:DatasetPopulatorTest.java

示例9: test_rdfcreation_fb

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
@Test
public void test_rdfcreation_fb() throws SAXException, IOException, ParserConfigurationException, Exception {

    Document dataDoc = parser.parse(RdfFactoryTest.class.getResourceAsStream(
            "/data/fb-20121231.xml"), -1);

    RdfFactory factory = new RdfFactory(new RunConfig(domain));
    factory.createRdfs(dataDoc, testTdbDir);

    Dataset dataset = TDBFactory.createDataset(testTdbDir);
    dataset.begin(ReadWrite.READ);
    Model model = dataset.getDefaultModel();
    Assert.assertFalse("No RDF was generated. TDB directory: " + testTdbDir, model.isEmpty());

    dataset.end();
}
 
开发者ID:ekzhu,项目名称:xbrl2rdf,代码行数:17,代码来源:RdfFactoryTest.java

示例10: test_rdfcreation_msft

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
@Test
public void test_rdfcreation_msft() throws SAXException, IOException, ParserConfigurationException, Exception {

    Document dataDoc = parser.parse(RdfFactoryTest.class.getResourceAsStream(
            "/data/msft-20130630.xml"), -1);

    RdfFactory factory = new RdfFactory(new RunConfig(domain));
    factory.createRdfs(dataDoc, testTdbDir);

    Dataset dataset = TDBFactory.createDataset(testTdbDir);
    dataset.begin(ReadWrite.READ);
    Model model = dataset.getDefaultModel();
    Assert.assertFalse("No RDF was generated. TDB directory: " + testTdbDir, model.isEmpty());

    dataset.end();
}
 
开发者ID:ekzhu,项目名称:xbrl2rdf,代码行数:17,代码来源:RdfFactoryTest.java

示例11: isCachedGraph

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
public boolean isCachedGraph(Dataset dataset, String graphName){
    boolean isCached = false;
    dataset.begin(ReadWrite.READ);
    try {
        Iterator<String> inames = getDataset().listNames();
        while(inames.hasNext()){
            if( graphName.equals( inames.next() )) {
                 isCached = true;  
            }
        }
    }
    finally {
        dataset.end();
    }
    return isCached;
}
 
开发者ID:fusepoolP3,项目名称:p3-geo-enriching-transformer,代码行数:17,代码来源:SpatialDataEnhancer.java

示例12: SPARQLModelIndex

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
/** Create an index using your own model saving you the time needed to import the model when using an endpoint.
 * If you only have an endpoint or want to index a subset of the triples,
 * use the static methods {@link #createIndex(String, String, List)}, {@link #createClassIndex(String, String)} or {@link #createPropertyIndex(String, String)}.
 * All triples (uri,rdfs:label,label) will be put into the index.
 * @param model the jena model containing the rdf:label statements that you want to index. Changes to the model after the construtor call are probably not indexed.
 * @param minSimilarity Between 0 (maximum fuzzyness) and 1f (no fuzzy matching).
 */
public SPARQLModelIndex(Model model,float minSimilarity)
{
	this.minSimilarity=minSimilarity;
	Dataset ds1 = DatasetFactory.createMem() ;

	EntityDefinition entDef = new EntityDefinition("uri", "text", RDFS.label) ;
	// Lucene, in memory.
	Directory dir =  new RAMDirectory();
	// Join together into a dataset
	dataset = TextDatasetFactory.createLucene(ds1, dir, entDef);
	//		ds.setDefaultModel(model);


	synchronized(model)
	{
		dataset.begin(ReadWrite.WRITE);
		try {
			dataset.getDefaultModel().add(model);
			dataset.commit();
		} finally {
			dataset.end();
		}
	}
	//		this.model = model;
}
 
开发者ID:AKSW,项目名称:rdfindex,代码行数:33,代码来源:SPARQLModelIndex.java

示例13: getInstances

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
private void getInstances() {
	File metricFile = new File(
			System.getProperty("user.dir") + "/sparql/queries/getInstances.sparql");

	List<String> lines = null;

	try {
		lines = Files.readAllLines(metricFile.toPath());
	} catch (IOException ex) {
		Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
	}
	String queryString = "";
	for (String line : lines) {
		queryString += line + System.lineSeparator();
	}
	ParameterizedSparqlString pss = new ParameterizedSparqlString();
	pss.setCommandText(queryString);
	pss.setLiteral("typename", typename);
	data.begin(ReadWrite.READ);
	List<QuerySolution> rlist = null;
	try (QueryExecution qe = QueryExecutionFactory.create(pss.asQuery(), data)) {
		ResultSet results = qe.execSelect();
		rlist = ResultSetFormatter.toList(results);
	} catch (Exception e) {
		JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
		e.printStackTrace();
	}
	instances = new String[rlist.size()];
	for(int j = 0; j < rlist.size(); j++){
		instances[j] = rlist.get(j).getLiteral("iname").getString();
	}
	data.end();
}
 
开发者ID:MarcelH91,项目名称:WikiOnto,代码行数:34,代码来源:DissolveGUI.java

示例14: getSubtypes

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
private void getSubtypes() {
	File metricFile = new File(
			System.getProperty("user.dir") + "/sparql/queries/getSubtypes.sparql");

	List<String> lines = null;

	try {
		lines = Files.readAllLines(metricFile.toPath());
	} catch (IOException ex) {
		Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
	}
	String queryString = "";
	for (String line : lines) {
		queryString += line + System.lineSeparator();
	}
	ParameterizedSparqlString pss = new ParameterizedSparqlString();
	pss.setCommandText(queryString);
	pss.setLiteral("typename", typename);
	data.begin(ReadWrite.READ);
	List<QuerySolution> rlist = null;
	try (QueryExecution qe = QueryExecutionFactory.create(pss.asQuery(), data)) {
		ResultSet results = qe.execSelect();
		rlist = ResultSetFormatter.toList(results);
	} catch (Exception e) {
		JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
		e.printStackTrace();
	}
	data.end();
	subtypes= new String[rlist.size()];
	for(int j = 0; j < rlist.size(); j++){
		subtypes[j] = rlist.get(j).getLiteral("sname").getString();
	}
}
 
开发者ID:MarcelH91,项目名称:WikiOnto,代码行数:34,代码来源:DissolveGUI.java

示例15: getDistantEntities

import com.hp.hpl.jena.query.ReadWrite; //导入依赖的package包/类
private void getDistantEntities(){
	File metricFile = new File(
			System.getProperty("user.dir") + "/sparql/smells/SemanticallyDistantEntity.sparql");

	List<String> lines = null;

	try {
		lines = Files.readAllLines(metricFile.toPath());
	} catch (IOException ex) {
		Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null, ex);
	}
	String queryString = "";
	for (String line : lines) {
		queryString += line + System.lineSeparator();
	}
	
	data.begin(ReadWrite.READ);
	List<QuerySolution> rlist = null;
	Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
	try (QueryExecution qe = QueryExecutionFactory.create(query, data)) {
		ResultSet results = qe.execSelect();
		rlist = ResultSetFormatter.toList(results);
	} catch (Exception e) {
		JOptionPane.showMessageDialog(null, "Writting to textarea failed!");
		e.printStackTrace();
	}
	instances = new String[rlist.size()];
	for(int j = 0; j < rlist.size(); j++){
		instances[j] = rlist.get(j).getLiteral("entityname").getString();
	}
	data.end();
}
 
开发者ID:MarcelH91,项目名称:WikiOnto,代码行数:33,代码来源:SemDistGUI.java


注:本文中的com.hp.hpl.jena.query.ReadWrite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。