本文整理汇总了Java中org.apache.jena.rdf.model.Model.listStatements方法的典型用法代码示例。如果您正苦于以下问题:Java Model.listStatements方法的具体用法?Java Model.listStatements怎么用?Java Model.listStatements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.Model
的用法示例。
在下文中一共展示了Model.listStatements方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLoads
import org.apache.jena.rdf.model.Model; //导入方法依赖的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);
}
示例2: testSimpleDiff
import org.apache.jena.rdf.model.Model; //导入方法依赖的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
示例3: hydrateAndModifySecondModel
import org.apache.jena.rdf.model.Model; //导入方法依赖的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
示例4: getModelKeyWords
import org.apache.jena.rdf.model.Model; //导入方法依赖的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;
}
示例5: asTriples
import org.apache.jena.rdf.model.Model; //导入方法依赖的package包/类
private Set<Triple> asTriples(Model model) {
Set<Triple> triples = new HashSet<>((int) model.size());
StmtIterator iterator = model.listStatements();
while (iterator.hasNext()) {
Statement statement = iterator.next();
triples.add(statement.asTriple());
}
return triples;
}