// TEMPORARY private boolean checkResultsByModel( Query query, Model expectedModel, ResultSetRewindable results) { // Fudge - can't cope with ordered results properly. The output writer for ResultSets does nto // add rs:index. results.reset(); Model actualModel = ResultSetFormatter.toModel(results); // Tidy the models. // Very regretable. expectedModel.removeAll(null, RDF.type, ResultSetGraphVocab.ResultSet); expectedModel.removeAll(null, RDF.type, ResultSetGraphVocab.ResultSolution); expectedModel.removeAll(null, RDF.type, ResultSetGraphVocab.ResultBinding); expectedModel.removeAll(null, ResultSetGraphVocab.size, (RDFNode) null); expectedModel.removeAll(null, ResultSetGraphVocab.index, (RDFNode) null); actualModel.removeAll(null, RDF.type, ResultSetGraphVocab.ResultSet); actualModel.removeAll(null, RDF.type, ResultSetGraphVocab.ResultSolution); actualModel.removeAll(null, RDF.type, ResultSetGraphVocab.ResultBinding); actualModel.removeAll(null, ResultSetGraphVocab.size, (RDFNode) null); actualModel.removeAll(null, ResultSetGraphVocab.index, (RDFNode) null); boolean b = expectedModel.isIsomorphicWith(actualModel); if (!b) { System.out.println("---- Expected"); expectedModel.write(System.out, "TTL"); System.out.println("---- Actual"); actualModel.write(System.out, "TTL"); System.out.println("----"); } return b; }
/** * Remove a Resource from the specified model. If property is null, the entire resource will be * removed. Otherwise only the specified property will be removed from the resource. * * @param path2db (location of the TDB store). * @param uri (base URI of the resource): * @param id (resource id). * @param property (property of the resource). can be null. */ public static void removeResource(String path2db, String uri, String id, Property property) { // TDB.setExecutionLogging(InfoLevel.INFO); TDB.getContext().set(TDB.symLogExec, true); rdf_model = TDBFactory.createModel(path2db); if (property == null) { rdf_model.removeAll(rdf_model.createResource(uri + id), null, null); } else { rdf_model.removeAll(rdf_model.createResource(uri + id), property, null); } }
private void verbModel(Model model, String verb) { Model m = ModelFactory.createDefaultModel(); int testLimit = 1000; StmtIterator stmtIt = model.listStatements(); int count = 0; try { while (stmtIt.hasNext()) { count++; m.add(stmtIt.nextStatement()); if (count % testLimit == 0 || !stmtIt.hasNext()) { StringWriter sw = new StringWriter(); m.write(sw, "N-TRIPLE"); StringBuffer updateStringBuff = new StringBuffer(); String graphURI = graph.getGraphURI(); updateStringBuff.append( verb + " DATA { " + ((graphURI != null) ? "GRAPH <" + graphURI + "> { " : "")); updateStringBuff.append(sw); updateStringBuff.append(((graphURI != null) ? " } " : "") + " }"); String updateString = updateStringBuff.toString(); // log.info(updateString); graph.executeUpdate(updateString); m.removeAll(); } } } finally { stmtIt.close(); } }
@Override public void clear() { Model graph = null; GraphConnection graphConnection = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); graph.removeAll(); // XXX AT: remove reification quadlets explicitly RSIterator it = graph.listReifiedStatements(); List<ReifiedStatement> rss = new ArrayList<ReifiedStatement>(); while (it.hasNext()) { rss.add(it.nextRS()); } for (ReifiedStatement rs : rss) { graph.removeReification(rs); } } finally { if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } }
public void redoInferred(String uri, Model m, boolean nonMon) throws DataException { log.info("Running inferences on " + uri); Data data = getData(); Model infData = data.getModel(uri + "-inferred"); if (nonMon) infData.removeAll(); // Truth maintenance grossly simplified InfModel inf = ModelFactory.createInfModel(reasoner, m); infData.add(inf.getDeductionsModel()); log.info("Inferencing done"); }
/** @param value the value to set */ public void setValue(String value) { this.value = value; if (this.model != null && this.checksumNode != null) { // delete any previous value Property p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE); model.removeAll(checksumResource, p, null); // add the property p = model.createProperty( SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE); checksumResource.addProperty(p, value); } }
public boolean deleteAll(String uri) { try { log.info("Deleting model: " + uri + " " + reasoner); Data data = getData(); Model m = data.getModel(uri); m.removeAll(); if (reasoner != null) redoInferred(uri, m, true); m.close(); data.close(); return true; } catch (DataException e) { e.printStackTrace(); return false; } }
/** * @param algorithm the algorithm to set * @throws InvalidSPDXAnalysisException */ public void setAlgorithm(String algorithm) throws InvalidSPDXAnalysisException { this.algorithm = algorithm; if (this.model != null && this.checksumNode != null) { Resource algResource = algorithmStringToResource(algorithm, this.model); // delete any previous algorithm Property p = model.getProperty( SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM); model.removeAll(checksumResource, p, null); // add the property p = model.createProperty( SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM); checksumResource.addProperty(p, algResource); } }
public void run() { try { isSynchronizing = true; while (removalModel.size() > 0 || additionModel.size() > 0) { Model tempModel = ModelFactory.createDefaultModel(); removalModel.enterCriticalSection(Lock.WRITE); try { tempModel.add(removalModel); removalModel.removeAll(); } finally { removalModel.leaveCriticalSection(); } pelletModel.enterCriticalSection(Lock.WRITE); try { pelletModel.remove(tempModel); } finally { pelletModel.leaveCriticalSection(); } tempModel.removeAll(); additionModel.enterCriticalSection(Lock.WRITE); try { tempModel.add(additionModel); additionModel.removeAll(); } finally { additionModel.leaveCriticalSection(); } pelletModel.enterCriticalSection(Lock.WRITE); try { pelletModel.add(tempModel); } finally { pelletModel.leaveCriticalSection(); } tempModel = null; getInferences(); } } finally { isSynchronizing = false; } }
/** * Remove all data (triples) from the specified TDB store. * * @param path2db (location of the TDB store). */ public static void removeData(String path2db) { // TDB.setExecutionLogging(InfoLevel.INFO); TDB.getContext().set(TDB.symLogExec, true); rdf_model = TDBFactory.createModel(path2db); rdf_model.removeAll(); }
@Override public void clear() { model.removeAll(); }