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


Java StmtIterator.hasNext方法代码示例

本文整理汇总了Java中org.apache.jena.rdf.model.StmtIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java StmtIterator.hasNext方法的具体用法?Java StmtIterator.hasNext怎么用?Java StmtIterator.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jena.rdf.model.StmtIterator的用法示例。


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

示例1: testLoads

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Test
public void testLoads() throws Exception {

  // cleanup earlier run. Can't delete dirs on windows after use.
  FileUtils.deleteDirectory(new File("tempTDB"));

  Model m = ModelLoader.loadModelToMem("Playpen2.ttl");
  assertTrue(m != null);
  Model mc = ModelLoader.loadModelToMem(m);
  assertTrue(mc != null);

  Model mtdb = ModelLoader.loadModelToTdb("Playpen2.ttl", "urn:mymodel", "tempTDB");
  assertTrue(mtdb != null);
  StmtIterator it = mtdb.listStatements();
  int nStmts = 0;
  while (it.hasNext()) {
    System.out.println(it.nextStatement().toString());
    nStmts++;
  }
  // this will fail on windows
  FileUtils.deleteDirectory(new File("tempTDB"));
  assertTrue(nStmts > 0);
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:24,代码来源:ModelLoaderTests.java

示例2: compareModels

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private boolean compareModels(String resourceName, Model expModel, Model carwledModel) {
    StmtIterator iterator = expModel.listStatements();
    Statement statement;
    boolean modelsAreEqual = true;
    while (iterator.hasNext()) {
        statement = iterator.next();
        if (!carwledModel.contains(statement)) {
            LOGGER.error("The crawled model of \"" + resourceName + "\" does not contain the expected statement "
                    + statement.toString());
            modelsAreEqual = false;
        }
    }
    iterator = carwledModel.listStatements();
    while (iterator.hasNext()) {
        statement = iterator.next();
        if (!expModel.contains(statement)) {
            LOGGER.error("The crawled model of \"" + resourceName + "\" contains the unexpected statement "
                    + statement.toString());
            modelsAreEqual = false;
        }
    }
    return modelsAreEqual;
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:24,代码来源:ScenarioBasedTest.java

示例3: run

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public void run() {
    sink.openSinkForUri(uri);
    StmtIterator iterator = model.listStatements();
    int count = 0;
    while (iterator.hasNext()) {
        sink.addTriple(uri, iterator.next().asTriple());
        try {
            Thread.sleep(WAITING_TIME_BETWEEN_TRIPLES);
        } catch (InterruptedException e) {
            e.printStackTrace();
            Assert.fail(e.getLocalizedMessage());
        }
        ++count;
    }
    sink.closeSinkForUri(uri);
    LOGGER.debug("wrote " + count + " triples for " + uri.getUri().toString());
    writingFinishedMutex.release();
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:20,代码来源:FileBasedSinkTest.java

示例4: sortStatementsByHash

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * Sort statements by hash
 * 
 * @param stmtIterator
 *            Iterator which is used to get the statements
 * @return List of statements sorted by hash
 */
@Deprecated
protected List<Statement> sortStatementsByHash(StmtIterator stmtIterator) {
	IntObjectOpenHashMap<Statement> map = new IntObjectOpenHashMap<Statement>();
	Statement s;
	while (stmtIterator.hasNext()) {
		s = stmtIterator.next();
		map.put(s.hashCode(), s);
	}
	int keys[] = new int[map.assigned];
	int pos = 0;
	for (int i = 0; i < map.allocated.length; ++i) {
		if (map.allocated[i]) {
			keys[pos] = map.keys[i];
			++pos;
		}
	}
	Arrays.sort(keys);
	List<Statement> result = new ArrayList<Statement>(keys.length);
	for (int i = 0; i < keys.length; ++i) {
		result.add(map.get(keys[i]));
	}
	return result;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:31,代码来源:AbstractSelector.java

示例5: DBpediaGenderDictionary

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public DBpediaGenderDictionary() {
	Model model = ModelFactory.createDefaultModel();

	Literal maleLit = model.createLiteral(VALUE_MALE, "en");
	Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");

	RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
	StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
	while (iter.hasNext()) {
		Statement st = iter.next();
		Literal lit = st.getObject().asLiteral();
		if (lit.equals(maleLit)) {
			male.add(st.getSubject().getURI());
		} else if (lit.equals(femaleLit)) {
			female.add(st.getSubject().getURI());
		}
	}
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:19,代码来源:DBpediaGenderDictionary.java

示例6: activate

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public void activate(final Collection<JenaPosLengthInjectMatch> matches) throws IOException {
	final Model model = driver.getModel();
	final Property lengthProperty = model.getProperty(BASE_PREFIX + LENGTH);

	for (final JenaPosLengthInjectMatch match : matches) {
		final Resource segment = match.getSegment();
		final Selector selector = new SimpleSelector(segment, lengthProperty, (RDFNode) null);
		final StmtIterator oldStatements = model.listStatements(selector);
		if (!oldStatements.hasNext()) {
			continue;

		}
		final Statement oldStatement = oldStatements.next();
		model.remove(oldStatement);
		final Statement newStatement = model.createLiteralStatement(segment, lengthProperty, 0);
		model.add(newStatement);
	}
}
 
开发者ID:FTSRG,项目名称:trainbenchmark,代码行数:20,代码来源:JenaTransformationInjectPosLength.java

示例7: activate

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public void activate(final Collection<JenaPosLengthMatch> matches) throws IOException {
	final Model model = driver.getModel();
	final Property lengthProperty = model.getProperty(BASE_PREFIX + LENGTH);

	for (final JenaPosLengthMatch match : matches) {
		final Resource segment = match.getSegment();
		final int length = match.getLength().getInt();
		final int newLength = -length + 1;

		final Selector selector = new SimpleSelector(segment, lengthProperty, (RDFNode) null);
		final StmtIterator statementsToRemove = model.listStatements(selector);
		if (statementsToRemove.hasNext()) {
			final Statement oldStatement = statementsToRemove.next();
			model.remove(oldStatement);
		}
		
		final Statement newStatement = model.createLiteralStatement(segment, lengthProperty, newLength);
		model.add(newStatement);
	}
}
 
开发者ID:FTSRG,项目名称:trainbenchmark,代码行数:22,代码来源:JenaTransformationRepairPosLength.java

示例8: deleteOutgoingEdges

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public void deleteOutgoingEdges(final Collection<Resource> vertices, final String edgeType) throws IOException {
	final Property property = model.getProperty(RdfConstants.BASE_PREFIX + edgeType);

	for (final Resource vertex : vertices) {
		final Selector selector = new SimpleSelector(vertex, property, (RDFNode) null);

		final StmtIterator edges = model.listStatements(selector);

		final List<Statement> statementsToRemove = new ArrayList<>();
		while (edges.hasNext()) {
			final Statement edge = edges.next();
			statementsToRemove.add(edge);
		}

		for (final Statement statement : statementsToRemove) {
			model.remove(statement);
		}
	}
}
 
开发者ID:FTSRG,项目名称:trainbenchmark,代码行数:20,代码来源:JenaDriver.java

示例9: mergeData

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public void mergeData(Model mainConferenceModel) {
	StmtIterator stmtIterator = dataModel.listStatements();
	while (stmtIterator.hasNext()) {
		Statement stmt = stmtIterator.next();
		RDFNode object = stmt.getObject();
		if (object.isLiteral()) {
			if (!mainConferenceModel.contains(stmt.getSubject(),
					stmt.getPredicate(), (RDFNode) null)) {
				mainConferenceModel.add(stmt);
			}
		} else {
			if (!mainConferenceModel.contains(stmt))
				mainConferenceModel.add(stmt);
		}
	}
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:17,代码来源:DataHandler.java

示例10: addValueNodes

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public static void addValueNodes(RDFNode focusNode, Resource path, Collection<RDFNode> results) {
	if(path.isURIResource()) {
		if(focusNode instanceof Resource) {
			StmtIterator it = focusNode.getModel().listStatements((Resource)focusNode, JenaUtil.asProperty(path), (RDFNode)null);
			while(it.hasNext()) {
				results.add(it.next().getObject());
			}
		}
	}
	else {
		String pathString = SHACLPaths.getPathString(path);
		String queryString = "SELECT DISTINCT ?value { $this " + pathString + " ?value }";
		Query query = ARQFactory.get().createQuery(path.getModel(), queryString);
		try(QueryExecution qexec = ARQFactory.get().createQueryExecution(query, focusNode.getModel())) {
			QuerySolutionMap qs = new QuerySolutionMap();
			qs.add("this", focusNode);
			qexec.setInitialBinding(qs);
			ResultSet rs = qexec.execSelect();
			while(rs.hasNext()) {
				results.add(rs.next().get("value"));
			}
		}
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:25,代码来源:SHACLPaths.java

示例11: getParameters

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public List<SHParameter> getParameters() {
	List<SHParameter> results = new LinkedList<SHParameter>();
	StmtIterator it = null;
	JenaUtil.setGraphReadOptimization(true);
	try {
		Set<Resource> classes = JenaUtil.getAllSuperClasses(this);
		classes.add(this);
		for(Resource cls : classes) {
			it = cls.listProperties(SH.parameter);
			while(it.hasNext()) {
				Resource param = it.next().getResource();
				results.add(param.as(SHParameter.class));
			}
		}
	}
	finally {
		if (it != null) {
			it.close();
		}
		JenaUtil.setGraphReadOptimization(false);
	}
	return results;
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:25,代码来源:SHParameterizableImpl.java

示例12: drop

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/** Drop RDF resource into XML.
 * The Gloze instance should be pre-initialised with the relevant XML schema.
 * @param resource resource representing the root of the XML document
 * @return XML Document
 */

public Document drop(Resource resource) throws Exception {
	Document doc = XMLUtility.newDocument();
	Context ctx = new Context(new URI(resource.getURI()), xmlns, resource.getModel(),schemaMap,this);
	
	if (ctx.toXML(doc, resource)) return doc;

	GlozeURL.logger.warn("drop: no schema mapping for resource: "+resource);
	StmtIterator si = resource.listProperties();
	if (!si.hasNext()) 
		GlozeURL.logger.warn("because no properties, is gloze.uri correctly defined?");
	else while (si.hasNext()) {
		Property p = si.nextStatement().getPredicate();
		// skip eg. RDF:type
		if (p.getNameSpace().equals(RDF.getURI())) continue;
		GlozeURL.logger.warn("because no matching property: "+p.getURI());
	}
	// try no-schema mapping
	GlozeURL.logger.info("using no-schema mapping");
	XMLBean.noSchemaToXML(doc,resource,ctx);
	return doc;
}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:28,代码来源:GlozeURL.java

示例13: saveInternal

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private void saveInternal(R2RResourceObject robj, SaveType saveType) throws Exception {
	startTransaction();
	LOG.log(Level.INFO, "Saving " + robj + ", Type " + saveType);
	for (Resource resource : robj.getResources()) {
		if (SaveType.SAVE.equals(saveType)) {
			sparqlClient.deleteSubject(resource.getURI());				
		}
		else if (SaveType.UPDATE.equals(saveType)) {
			// only delete the properties that this resource has maxCardinalityRestrictions on
			// do as set so that we do not do the same thing more than once
			Set<String> deletes = new HashSet<String>();
			StmtIterator si = resource.listProperties();
			while (si.hasNext()) {
				Property prop = si.next().getPredicate();
				if (robj.hasMaxCardinalityRestriction(prop.getURI())) {
					deletes.add("DELETE WHERE { <" + resource.getURI() + ">  <" + prop.getURI() + "> ?o }");
				}
			}
			sparqlClient.update(new ArrayList<String>(deletes));
		}
		sparqlClient.add(resource);		
	}
	endTransaction();
}
 
开发者ID:CTSIatUCSF,项目名称:Crosslinks,代码行数:25,代码来源:SparqlPersistance.java

示例14: sendData

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * Will send a {@link org.apache.jena.rdf.model.Model} 
 */
public void sendData(Model m) throws Exception {
	int sendedSize=0;
	//split Model into small parts
	StmtIterator sti = m.listStatements();
	while(sti.hasNext()){
		Model send = ModelFactory.createDefaultModel();
		send.setNsPrefixes(m.getNsPrefixMap());
		while(sendedSize < maxSize){
			Statement stmt = sti.next();
			send.add(stmt);
			sendedSize+=1;
		}
		sendDataSnippet(RabbitMQUtils.getData(send));
	}
	
}
 
开发者ID:dice-group,项目名称:IGUANA,代码行数:20,代码来源:AbstractDataGenerator.java

示例15: getchangedResourceTypeModel

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private Model getchangedResourceTypeModel(Resource r,String oldClassName, String newClassName, final Model subModel) {
    Model resultModel = ModelFactory.createDefaultModel();
    String sparqlQueryString= "CONSTRUCT {?s ?p ?o} WHERE {<" + r.getURI() +"> ?p ?o. ?s ?p ?o} " ;
    QueryFactory.create(sparqlQueryString);
    QueryExecution qexec = QueryExecutionFactory.create(sparqlQueryString, subModel);
    Model instanceMode = qexec.execConstruct();

    StmtIterator sItr = instanceMode.listStatements(); 
    while(sItr.hasNext()){
        Statement stmt = sItr.nextStatement();
        if(stmt.getPredicate().equals(RDF.type) && stmt.getObject().toString().equals(oldClassName)){
            resultModel.add(r, RDF.type,  ResourceFactory.createResource(newClassName));
        }else if(!stmt.getPredicate().equals(RDF.type)){
            resultModel.add(stmt);
        }
    }
    return resultModel;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:19,代码来源:ClassSplitModifier.java


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