connectionUtils/src/main/java/com/ge/research/semtk/sparqlX/SparqlEndpointInterface.java
public void clearGraphInChunks(int chunkSize) throws Exception {
	
		String sparql;
		int count;
		
		while (true) {
			// count all triples
			count = this.executeToTable(SparqlToXUtils.generateCountTriplesSparql(this)).getCellAsInt(0, 0);
			
			if (count == 0) 
				return;
			
			else if (count < chunkSize) {
				// few enough, delete them all
				sparql = SparqlToXUtils.generateDeleteAllQuery(this);
				LocalLogger.logToStdOut(sparql);
				this.executeQueryAndConfirm(sparql);
				LocalLogger.logToStdOut("done deleting triples");
				return;
				
			}  else {
				LocalLogger.logToStdOut("Searching for " + count + " triples...");
				
				// get a random subject
				String s = this.executeToTable(SparqlToXUtils.generateSelectTriplesSparql(this, 1)).getCell(0, 0);
				
				// count how many triples have a subject with this subject's last character, last two characters, last three characters...
				// until the number is lower than chunk size
				for (int i=1; i < s.length(); i++) {
					String regex = s.substring(s.length() - i) + "$";
					count = this.executeToTable(SparqlToXUtils.generateCountBySubjectRegexQuery(this, regex)).getCellAsInt(0, 0);
					if (count < chunkSize) {
						
						// perform a delete
						sparql = SparqlToXUtils.generateDeleteBySubjectRegexQuery(this, regex);
						LocalLogger.logToStdOut(sparql);
						this.executeQueryAndConfirm(sparql);
						break;
					}
				}
			}
		}
	}
/**
	 * Delete triples chunkSize at a time until the graph is empty.
	 * Designed for Neptune.
	 * @param chunkSize
	 * @throws Exception
	 */
Delete triples chunkSize at a time until the graph is empty.
Designed for Neptune.
@param chunkSize
@throws Exception
Delete triples chunkSize at a time until the graph is empty . Designed for Neptune . @param chunkSize @throws Exception
public void clearGraphInChunks(int chunkSize) throws Exception {
		String sparql;
		int count;
		while (true) {
			count = this.executeToTable(SparqlToXUtils.generateCountTriplesSparql(this)).getCellAsInt(0, 0);
			if (count == 0) 
				return;
			else if (count < chunkSize) {
				sparql = SparqlToXUtils.generateDeleteAllQuery(this);
				LocalLogger.logToStdOut(sparql);
				this.executeQueryAndConfirm(sparql);
				LocalLogger.logToStdOut("done deleting triples");
				return;
			}  else {
				LocalLogger.logToStdOut("Searching for " + count + " triples...");
				String s = this.executeToTable(SparqlToXUtils.generateSelectTriplesSparql(this, 1)).getCell(0, 0);
				for (int i=1; i < s.length(); i++) {
					String regex = s.substring(s.length() - i) + "$";
					count = this.executeToTable(SparqlToXUtils.generateCountBySubjectRegexQuery(this, regex)).getCellAsInt(0, 0);
					if (count < chunkSize) {
						sparql = SparqlToXUtils.generateDeleteBySubjectRegexQuery(this, regex);
						LocalLogger.logToStdOut(sparql);
						this.executeQueryAndConfirm(sparql);
						break;
					}
				}
			}
		}
	}
public void clearGraphInChunks ( int chunkSize ) throws Exception { String sparql ; int count ; while ( true ) { count = this . executeToTable ( SparqlToXUtils . generateCountTriplesSparql ( this ) ) . getCellAsInt ( 0 , 0 ) ; if ( count == 0 ) return ; else if ( count < chunkSize ) { sparql = SparqlToXUtils . generateDeleteAllQuery ( this ) ; LocalLogger . logToStdOut ( sparql ) ; this . executeQueryAndConfirm ( sparql ) ; LocalLogger . logToStdOut ( "done deleting triples" ) ; return ; } else { LocalLogger . logToStdOut ( "Searching for " + count + " triples..." ) ; String s = this . executeToTable ( SparqlToXUtils . generateSelectTriplesSparql ( this , 1 ) ) . getCell ( 0 , 0 ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { String regex = s . substring ( s . length ( ) - i ) + "$" ; count = this . executeToTable ( SparqlToXUtils . generateCountBySubjectRegexQuery ( this , regex ) ) . getCellAsInt ( 0 , 0 ) ; if ( count < chunkSize ) { sparql = SparqlToXUtils . generateDeleteBySubjectRegexQuery ( this , regex ) ; LocalLogger . logToStdOut ( sparql ) ; this . executeQueryAndConfirm ( sparql ) ; break ; } } } } }
Delete triples chunkSize at a time until the graph is empty.
Delete triples chunkSize at a time until the graph is empty .
// count all triples // few enough, delete them all // get a random subject // count how many triples have a subject with this subject's last character, last two characters, last three characters... // until the number is lower than chunk size // perform a delete