本文整理汇总了Java中com.hp.hpl.jena.rdf.model.Model.removeAll方法的典型用法代码示例。如果您正苦于以下问题:Java Model.removeAll方法的具体用法?Java Model.removeAll怎么用?Java Model.removeAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.Model
的用法示例。
在下文中一共展示了Model.removeAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bulkUpdate
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
/**
* Method called to Chunk the triples into N-Sized batches and post to VIVO.
* This is designed to work around / handle errors when posting sets of triples
* over 10,000 to the API.
*
* @param namedGraph String with named graph.
* @param changeModel Jena model with set of changes to sync to store.
* @param changeType Either add or remove.
* @return Boolean true if update was successful.
* @throws IOException
*/
private Boolean bulkUpdate(String namedGraph, Model changeModel, String changeType) throws IOException {
// Temporary model to hold
Model tmpModel = ModelFactory.createDefaultModel();
Integer bSize = Integer.parseInt(batchSize);
// Use an integer to count triples rather than calling size on the model
// during each loop.
Integer size = 0;
StmtIterator iter = changeModel.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
tmpModel.add(stmt);
size++;
if (size >= bSize) {
// Submit
log.info("Submitting " + size + " triples to " + namedGraph);
submitBatch(tmpModel, namedGraph, changeType);
// Reset the tmp model.
tmpModel.removeAll();
// Reset the counter.
size = 0;
}
}
log.info("model size:" + tmpModel.size());
// Submit the remaining statements, if any.
if (tmpModel.size() > 0) {
submitBatch(tmpModel, namedGraph, changeType);
}
return true;
}
示例2: collapseAnnotations
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
private List<Statement> collapseAnnotations(Property property, Model model){
List<Statement> stmts = new ArrayList<Statement>();
Map<String, Map<String,Statement>> literalMap = new HashMap<String, Map<String,Statement>>();
StmtIterator stmtIt = model.listStatements(null, property, (RDFNode) null);
stmtIt.forEachRemaining(stmt -> {
RDFNode obj = stmt.getObject();
if(obj.isLiteral()){
Literal lit = obj.asLiteral();
String lang = lit.getLanguage();
if(lang == null){
lang = "null";
}
Map<String, Statement> stmtMap = literalMap.get(lang);
if(stmtMap == null) {
stmtMap = new HashMap<String, Statement>();
literalMap.put(lang, stmtMap);
}
Statement statement = stmtMap.get(lang);
boolean insert = false;
if(statement == null) insert = true;
else{
String statementLF = ((Literal)statement.getObject()).getLexicalForm();
String lexicalForm = lit.getLexicalForm();
if(lexicalForm.length() > statementLF.length()) insert = true;
}
if(insert) stmtMap.put(lang, statement);
}
});
model.removeAll(null, property, (RDFNode) null);
literalMap.forEach((subject, stmtMap) -> {
stmtMap.forEach((lang, stmt) -> {
model.add(stmt);
});
});
return stmts;
}
示例3: keepMaxLengthAnnotationsOnly
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
private List<Statement> keepMaxLengthAnnotationsOnly(Property property, Model model){
List<Statement> stmts = new ArrayList<Statement>();
Map<Resource, Map<String,Statement>> literalMap = new HashMap<Resource, Map<String,Statement>>();
StmtIterator stmtIt = model.listStatements(null, property, (RDFNode) null);
stmtIt.forEachRemaining(stmt -> {
Resource subj = stmt.getSubject();
RDFNode obj = stmt.getObject();
if(obj.isLiteral()){
Literal lit = obj.asLiteral();
String lang = lit.getLanguage();
if(lang == null){
lang = "null";
}
Map<String, Statement> stmtMap = literalMap.get(subj);
if(stmtMap == null) {
stmtMap = new HashMap<String, Statement>();
literalMap.put(subj, stmtMap);
}
Statement statement = stmtMap.get(lang);
boolean insert = false;
if(statement == null) insert = true;
else{
String statementLF = ((Literal)statement.getObject()).getLexicalForm();
String lexicalForm = lit.getLexicalForm();
if(lexicalForm.length() > statementLF.length()) insert = true;
}
if(insert) stmtMap.put(lang, stmt);
}
});
model.removeAll(null, property, (RDFNode) null);
literalMap.forEach((subject, stmtMap) -> {
stmtMap.forEach((lang, stmt) -> {
model.add(stmt);
});
});
return stmts;
}