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


Java StmtIterator.nextStatement方法代码示例

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


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

示例1: 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

示例2: destroy

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public Model destroy(Model subModel) {
    permutationTriplesCount = (long) Math.ceil(subModel.size() * permutationRatio);
    insertionTriplesCount   = (long) Math.ceil(subModel.size() * insertionRatio);
    deletionTriplesCount	= (long) Math.ceil(subModel.size() * deletionRatio);
    // to avoid leaving any triples
    substitutionTriplesCount=  subModel.size() - (permutationTriplesCount + insertionTriplesCount + deletionTriplesCount); 

    StmtIterator sItr = subModel.listStatements();

    while (sItr.hasNext()) {
        Statement stmt = sItr.nextStatement();	
        Statement misspelledStatement = misspelling(stmt); 
        destroyedModel.add(misspelledStatement);    
    }


    return destroyedModel;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:20,代码来源:InstanceMisspellingModifier.java

示例3: getChangedResourceTypeModel

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private Model getChangedResourceTypeModel(Resource r, List<String> oldClassNames, String newClassName, final Model startModel) {
    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, startModel);
    Model instanceMode = qexec.execConstruct();

    StmtIterator sItr = instanceMode.listStatements(); 
    while(sItr.hasNext()){
        Statement stmt = sItr.nextStatement();
        if(stmt.getPredicate().equals(RDF.type)){
            for(String oldClassName : oldClassNames){
                if(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,代码行数:23,代码来源:ClassMergeModifier.java

示例4: getSubModel

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * @param subModelSize
 * @param baseModelOffset
 * @return A sub model of the fromModel with size subModelSize and starting from offset baseModelOffset
 * @author Sherif
 */
protected Model getSubModel(Model inputModel, long subModelSize, long baseModelOffset) {
	Model subModel = ModelFactory.createDefaultModel();

	StmtIterator sItr = inputModel.listStatements();

	//skip statements tell the offset reached
	for(int i = 0 ; i < baseModelOffset ; i++){
		sItr.nextStatement();		
	}

	//Copy the sub-model
	for(int i = 0 ; i < subModelSize ; i++){
		Statement stat = sItr.nextStatement();	
		subModel.add(stat);
	}
	return subModel;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:24,代码来源:Modifier.java

示例5: renameClass

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * @param inputModel
 * @param oldClassName
 * @param newClassName
 * @return
 * @author Sherif
 */
public Model renameClass(final Model inputModel, String oldClassName,String newClassName) {
	Model result = ModelFactory.createDefaultModel();
	StmtIterator sItr = inputModel.listStatements();
	Resource oldClassURI = ResourceFactory.createResource(oldClassName);
	Resource newClassURI = ResourceFactory.createResource(newClassName);
       while(sItr.hasNext()){
           Statement stmt = sItr.nextStatement();
           if(stmt.getPredicate().equals(RDF.type) && stmt.getObject().equals(oldClassURI)){
               result.add(stmt.getSubject(), RDF.type, newClassURI);
           }else{
               result.add(stmt);
           }
       }
	return result;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:23,代码来源:Modifier.java

示例6: _renameClass

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * @param model
 * @param oldClassUri
 * @param newClassUri
 * @return
 * @author Sherif
 */
public Model _renameClass(Model model, String oldClassUri,String newClassUri) {
    Model result = model;
    Model inClassModel = ModelFactory.createDefaultModel();
    String sparqlQueryString = "CONSTRUCT {?s a <"+oldClassUri+">} WHERE {?s a <"+oldClassUri+">.}";
    QueryFactory.create(sparqlQueryString);
    QueryExecution qexec = QueryExecutionFactory.create(sparqlQueryString, model);
    inClassModel = qexec.execConstruct();
    result.remove(inClassModel);
    StmtIterator sItr = inClassModel.listStatements();
    
    RDFNode newClassURI = ResourceFactory.createResource(newClassUri);
    while(sItr.hasNext()){
        Statement stmt = sItr.nextStatement();
        result.add(stmt.getSubject(), RDF.type, newClassURI);
    }
    return result;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:25,代码来源:Modifier.java

示例7: destroy

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
@Override
public Model destroy(Model subModel) {
	System.out.println();
	long n = (subModel.size() %2 == 0) ? subModel.size():subModel.size()-1;
	System.out.println("Merging " + n + " triples.");

	StmtIterator sItr = subModel.listStatements();

	while (sItr.hasNext()) {
		Statement stat1 = sItr.nextStatement();	

		if(sItr.hasNext()){
			Statement stat2 = sItr.nextStatement();
			List<Statement> stmts = new ArrayList<Statement>(); 
			stmts.add(stat1);
			stmts.add(stat2);
			Statement mergedStatement = merge(stmts);
			destroyedModel.add(mergedStatement);
		}else{ // if a single property just return it
			destroyedModel.add(stat1);
		}
	}
	return destroyedModel;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:25,代码来源:InstanceMergeModifier.java

示例8: filterRdf

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * Parses the provided triples and filters it to just include statements with the
 * specified predicates.
 * @param triples
 * @param predicates
 * @return
 */
private String filterRdf(final String triples, final Property ... predicates) {
    try (CloseableDataset original = parseTriples(new ByteArrayInputStream(triples.getBytes()))) {
        final Model m = original.getDefaultModel();
        final StmtIterator it = m.listStatements();
        while (it.hasNext()) {
            final Statement stmt = it.nextStatement();
            boolean keep = false;
            for (Property p : predicates) {
                if (stmt.getPredicate().equals(p)) {
                    keep = true;
                    break;
                }
            }
            if (!keep) {
                it.remove();
            }
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        m.write(baos, "N3");
        return baos.toString();
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:30,代码来源:FedoraRelaxedLdpIT.java

示例9: testSimpleDiff

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

  Model model2 = hydrateAndModifySecondModel();
  String sparql = DiffToSparqlInsertUpdateBuilder.buildSparqlInsertUpdate(
      RDFDifferenceBuilder.buildDifference(model, model2));
  System.out.println(sparql);
  assertTrue(sparql.startsWith("DELETE"));

  Resource res2 = model2.createResource("http://example/com/Playpen2#foobarFoo");
  StmtIterator it = model2.listStatements(res2, prop1, (RDFNode) null);
  Statement stmt = it.nextStatement();
  assertTrue(stmt.getObject().asLiteral().getBoolean() == false);

  it = model2.listStatements(res2, prop2, (RDFNode) null);
  stmt = it.nextStatement();
  assertTrue(stmt.getObject().asLiteral().getLong() == 1);

  it = model2.listStatements(res2, prop3, (RDFNode) null);
  stmt = it.nextStatement();
  XSDDateTime date = (XSDDateTime) stmt.getObject().asLiteral().getValue();

  it = model2.listStatements(res2, prop4, (RDFNode) null);
  stmt = it.nextStatement();
  Literal lit = stmt.getObject().asLiteral();
  String val = lit.getLexicalForm();
  String dataType = lit.getDatatype().getURI();
  assertTrue(val.equals("2017-01-01"));
  assertTrue(dataType.equals(XSDDatatype.XSDdate.getURI()));

  it = model2.listStatements(res2, prop5, (RDFNode) null);
  stmt = it.nextStatement();
  assertTrue(stmt.getObject().asLiteral().getString().equals("http://www.google.com"));
  assertTrue(stmt.getObject().asLiteral().getDatatype().getURI().equals(XSDDatatype.XSDanyURI.getURI()));

}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:37,代码来源:DiffToSparqlInsertUpdateBuilderTests.java

示例10: hydrateAndModifySecondModel

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

  StmtIterator it = model2.listStatements(newConceptRes, null, (RDFNode) null);
  List<Statement> toDelete = Lists.newArrayList();
  while (it.hasNext()) {
    Statement stmt = it.nextStatement();
    toDelete.add(stmt);
  }
  model2.remove(toDelete);

  Resource foobarFooRes = model2.createResource("http://example/com/Playpen2#foobarFoo");
  foobarFooRes.addProperty(RDF.type, SKOS.Concept);

  foobarFooRes.addLiteral(prop1, false);
  foobarFooRes.addLiteral(prop2, 1);
  Calendar c = Calendar.getInstance();
  c.set(Calendar.YEAR, 2016);
  c.set(Calendar.DAY_OF_MONTH, 3);
  c.set(Calendar.MONTH, 10);
  foobarFooRes.addLiteral(prop3, model.createTypedLiteral(dtfmt.format(c.getTime()), XSDDatatype.XSDdate));
  foobarFooRes.addProperty(prop4, "2017-01-01", XSDDatatype.XSDdate);
  foobarFooRes.addProperty(prop5, "http://www.google.com", XSDDatatype.XSDanyURI);

  model2.addLiteral(foobarFooRes, prop6, model.createLiteral("2017-02-22", "en"));

  return model2;
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:30,代码来源:DiffToSparqlInsertUpdateBuilderTests.java

示例11: getModelKeyWords

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * Extracts the key words from the model's statements.
 * This includes the Literals and the localNames of Resources and Predicates.
 * 
 * @param model Model to extract key words
 * @return List of key word strings
 */
 public List<String> getModelKeyWords(Model model) {

List<String> keyWords = new ArrayList<String>();
StmtIterator statementIter = model.listStatements();
Statement s;
Property predicate;
RDFNode object;

while (statementIter.hasNext()) {
  s = statementIter.nextStatement();
  predicate = s.getPredicate();
  object = s.getObject();
	
  keyWords.add(predicate.getLocalName());

  // local name of (non blank nodes) Resources
  if (object instanceof Resource && object.toString().contains("/")) {
	keyWords.add(object.asResource().getLocalName());
	  
  } else if (object instanceof Literal) {
	// object is a Literal
	keyWords.add(object.toString());
  }
 }
 return keyWords;
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:34,代码来源:ThingDescriptionUtils.java

示例12: extractNamespacesAndNames

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private void extractNamespacesAndNames() {
	StmtIterator iter = model.listStatements();

	while (iter.hasNext()) {
		Statement r = iter.nextStatement();
		Triple triple = r.asTriple();

		Node[] nodes = new Node[2];

		nodes[0] = triple.getPredicate();
		nodes[1] = triple.getObject();
		// nodes[2] = triple.getSubject();

		for (int i = 0; i < 2; i++) {
			Node node = nodes[i];

			if (!node.isBlank() && !node.isLiteral() && node.isURI()) {
				String uri = "";
				try {
					uri = node.getNameSpace();
					addToMap(uri, node.getLocalName());
				} catch (Exception e) {

				}
			}
		}

	}
}
 
开发者ID:AKSW,项目名称:semantic-ci,代码行数:30,代码来源:LocalGraph.java

示例13: createIndividual

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
private Model createIndividual(VirtualEntity virtualEntity) {
        // some definitions
        String personURI = "http://somewhere/JohnSmith";
        String givenName = "John";
        String familyName = "Smith";
        String fullName = givenName + " " + familyName;

// create an empty Model
        Model model = ModelFactory.createDefaultModel();

// create the resource
//   and add the properties cascading style
        Resource johnSmith
                = model.createResource(personURI)
                        .addProperty(VCARD.FN, fullName)
                        .addProperty(VCARD.N,
                                model.createResource()
                                        .addProperty(VCARD.Given, givenName)
                                        .addProperty(VCARD.Family, familyName));

        // list the statements in the Model
        StmtIterator iter = model.listStatements();

// print out the predicate, subject and object of each statement
        while (iter.hasNext()) {
            Statement stmt = iter.nextStatement();  // get next statement
            Resource subject = stmt.getSubject();     // get the subject
            Property predicate = stmt.getPredicate();   // get the predicate
            RDFNode object = stmt.getObject();      // get the object

            System.out.print(subject.toString());
            System.out.print(" " + predicate.toString() + " ");
            if (object instanceof Resource) {
                System.out.print(object.toString());
            } else {
                // object is a literal
                System.out.print(" \"" + object.toString() + "\"");
            }

            System.out.println(" .");
        }

        return model;
    }
 
开发者ID:nailtonvieira,项目名称:cloudsemanticwot,代码行数:45,代码来源:DataConnectorImpl.java

示例14: toXML

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
public boolean toXML(Document doc, Resource rez) throws Exception {
	StmtIterator i = rez.listProperties();
	while (i.hasNext()) {
		Statement s = i.nextStatement();
		Property p = s.getPredicate();
		element e = getElement(p.getURI());
		if (e!=null && e.toXML(doc, s.getObject(),this)) return true;		
	}
	return false;
}
 
开发者ID:stevebattle,项目名称:Gloze,代码行数:11,代码来源:Context.java

示例15: read

import org.apache.jena.rdf.model.StmtIterator; //导入方法依赖的package包/类
/**
 * Reads mapping from RDF file (NT, N3, TTL, JASON-LD)
 *
 * @return Mapping that represents the content of the file
 */
@Override
public AMapping read() {
    AMapping mapping = MappingFactory.createDefaultMapping();
    Model mappingModel = RDFConfigurationReader.readModel(file);
    StmtIterator iter = mappingModel.listStatements();
    while (iter.hasNext()){
        Statement stmt = iter.nextStatement();
        mapping.add(stmt.getSubject().toString(),stmt.getObject().toString(),1d);
        mapping.setPredicate(stmt.getPredicate().toString());
    }
    return mapping;
}
 
开发者ID:dice-group,项目名称:LIMES,代码行数:18,代码来源:RDFMappingReader.java


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