sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/PredicateStats.java
private void storeStats(Table tab, OntologyInfo oInfo, SparqlConnection conn, JobTracker tracker, String jobId, int startPercent, int endPercent) throws AuthorizationException, Exception {
		final String STATUS = "calculating stats";
//		final String W3 = "http://www.w3.org";
		
		// hash start class or endclass to a list of one-hop triples
		Hashtable<String, HashSet<Triple>> tripleHash = new Hashtable<String, HashSet<Triple>>();
		// hash an exactHash key to endClass
		Hashtable<String, OntologyPath> pathHash = new Hashtable<String, OntologyPath>();
		
		
		double rows = tab.getNumRows();
		for (int i=0; i < tab.getNumRows(); i++) {
			if (tracker != null && i % 2000 == 0) {
				int percent = (int) (startPercent + (endPercent - startPercent) * (i / rows));
				tracker.setJobPercentComplete(jobId, percent, STATUS);
			}
			// extract info from query result row
			String sclass = tab.getCell(i, 0);
			String pred = tab.getCell(i, 1);
			String oclass = tab.getCell(i, 2);
			long count =  tab.getCellAsInt(i, 3);
			
//  Need #type for Explore tab, so consider this a failed experiment
//			if (sclass.startsWith(W3) || pred.startsWith(W3) || oclass.startsWith(W3))
//				continue;
			
			// build one-hop Triple and add to tripleHash twice: once for subject, once for object
			// do not include data properties (oclass is empty)
			if (!oclass.isEmpty()) {
				Triple t = new Triple(sclass, pred, oclass);
			
				if (! tripleHash.containsKey(sclass)) {
					tripleHash.put(sclass, new HashSet<Triple>());
				}
				tripleHash.get(sclass).add(t);
				if (! tripleHash.containsKey(oclass)) {
					tripleHash.put(oclass, new HashSet<Triple>());
				}
				tripleHash.get(oclass).add(t);
			}
				
			
			// add one-hops to exactHash
			OntologyPath p = new OntologyPath(sclass);
			p.addTriple(sclass, pred, oclass);
			String key = this.buildKey(p);
			this.exactHash.put(key, count);
			
			// hash the other details
			pathHash.put(key, p);
			
		}
		
		
		
		//-------- build additional hops ---------//
		// Seems to have insurmountable performance problems //
		// TODO
		// needs to be used by path-finding: check the end of the new path
		// smarter setJobPercentComplete()
		// needs return only one-hops to SPARQLgraph
		// MAX_HOPS would be higher, and probably accessible for findExactPaths()
		final int MAX_HOPS = 1;
		HashSet<String> lastLenKeys = new HashSet<String>();
		lastLenKeys.addAll(this.exactHash.keySet());
		
		// for each length of path up the the max we want to compute
		for (int thisLen=2; thisLen <= MAX_HOPS; thisLen++) {
			HashSet<String> thisLenKeys = new HashSet<String>();
			// for each path of the previous length
			for (String key : lastLenKeys) {
				OntologyPath p = pathHash.get(key);
				// for each triple that could be added to the end
				HashSet<Triple> triples = tripleHash.get(p.getEndClassName());
				if (triples != null) {
					for (Triple t : tripleHash.get(p.getEndClassName())) {
						// if new triple wouldn't cause a loop
						if (!p.containsClass(t.getSubject()) || !p.containsClass(t.getObject())) {
							// add triple to new path
							OntologyPath pathCopy = p.deepCopy();
							pathCopy.addTriple(t.getSubject(), t.getPredicate(), t.getObject());
							
							long instanceCount = this.countInstanceData(pathCopy, conn, oInfo);
							if (instanceCount > 0) {
								String k = this.buildKey(pathCopy);
								this.exactHash.put(k, instanceCount);
								thisLenKeys.add(k);
								pathHash.put(k, pathCopy);
							}
						}
					}
				}
			}
			
			lastLenKeys = thisLenKeys;
		}
		
		
		
		///////// DEBUG ///////////
		//for (OntologyPath p : pathHash.values()) {
		//	LocalLogger.logToStdOut(p.debugString());
		//}
		///////////////////////////
		
		if (tracker != null) {
			tracker.setJobPercentComplete(jobId, endPercent, STATUS);
		}
	}
/**
	 * For a table of exact results  subj pred obj count
	 * set statsHash such that hash(s,p,o) gets sum of all triples where:
	 *         subject_superclass* predicate_superclass* object_superclass*	 * @param t
	 *         
	 * If tracker is not null, send job percent complete info.  
	 * 
	 * @param oInfo
	 * @param tracker
	 * @param jobId
	 * @param startPercent
	 * @param endPercent
	 * @throws AuthorizationException
	 * @throws Exception
	 */
For a table of exact results  subj pred obj count
set statsHash such that hash(s,p,o) gets sum of all triples where:
subject_superclass* predicate_superclass* object_superclass*  * @param t

If tracker is not null, send job percent complete info.


For a table of exact results subj pred obj count set statsHash such that hash ( s p o ) gets sum of all triples where : subject_superclass * predicate_superclass * object_superclass * * @param t If tracker is not null send job percent complete info .
private void storeStats(Table tab, OntologyInfo oInfo, SparqlConnection conn, JobTracker tracker, String jobId, int startPercent, int endPercent) throws AuthorizationException, Exception {
		final String STATUS = "calculating stats";
		Hashtable<String, HashSet<Triple>> tripleHash = new Hashtable<String, HashSet<Triple>>();
		Hashtable<String, OntologyPath> pathHash = new Hashtable<String, OntologyPath>();
		double rows = tab.getNumRows();
		for (int i=0; i < tab.getNumRows(); i++) {
			if (tracker != null && i % 2000 == 0) {
				int percent = (int) (startPercent + (endPercent - startPercent) * (i / rows));
				tracker.setJobPercentComplete(jobId, percent, STATUS);
			}
			String sclass = tab.getCell(i, 0);
			String pred = tab.getCell(i, 1);
			String oclass = tab.getCell(i, 2);
			long count =  tab.getCellAsInt(i, 3);
			if (!oclass.isEmpty()) {
				Triple t = new Triple(sclass, pred, oclass);
				if (! tripleHash.containsKey(sclass)) {
					tripleHash.put(sclass, new HashSet<Triple>());
				}
				tripleHash.get(sclass).add(t);
				if (! tripleHash.containsKey(oclass)) {
					tripleHash.put(oclass, new HashSet<Triple>());
				}
				tripleHash.get(oclass).add(t);
			}
			OntologyPath p = new OntologyPath(sclass);
			p.addTriple(sclass, pred, oclass);
			String key = this.buildKey(p);
			this.exactHash.put(key, count);
			pathHash.put(key, p);
		}
		final int MAX_HOPS = 1;
		HashSet<String> lastLenKeys = new HashSet<String>();
		lastLenKeys.addAll(this.exactHash.keySet());
		for (int thisLen=2; thisLen <= MAX_HOPS; thisLen++) {
			HashSet<String> thisLenKeys = new HashSet<String>();
			for (String key : lastLenKeys) {
				OntologyPath p = pathHash.get(key);
				HashSet<Triple> triples = tripleHash.get(p.getEndClassName());
				if (triples != null) {
					for (Triple t : tripleHash.get(p.getEndClassName())) {
						if (!p.containsClass(t.getSubject()) || !p.containsClass(t.getObject())) {
							OntologyPath pathCopy = p.deepCopy();
							pathCopy.addTriple(t.getSubject(), t.getPredicate(), t.getObject());
							long instanceCount = this.countInstanceData(pathCopy, conn, oInfo);
							if (instanceCount > 0) {
								String k = this.buildKey(pathCopy);
								this.exactHash.put(k, instanceCount);
								thisLenKeys.add(k);
								pathHash.put(k, pathCopy);
							}
						}
					}
				}
			}
			lastLenKeys = thisLenKeys;
		}
		if (tracker != null) {
			tracker.setJobPercentComplete(jobId, endPercent, STATUS);
		}
	}
private void storeStats ( Table tab , OntologyInfo oInfo , SparqlConnection conn , JobTracker tracker , String jobId , int startPercent , int endPercent ) throws AuthorizationException , Exception { final String STATUS = "calculating stats" ; Hashtable < String , HashSet < Triple > > tripleHash = new Hashtable < String , HashSet < Triple > > ( ) ; Hashtable < String , OntologyPath > pathHash = new Hashtable < String , OntologyPath > ( ) ; double rows = tab . getNumRows ( ) ; for ( int i = 0 ; i < tab . getNumRows ( ) ; i ++ ) { if ( tracker != null && i % 2000 == 0 ) { int percent = ( int ) ( startPercent + ( endPercent - startPercent ) * ( i / rows ) ) ; tracker . setJobPercentComplete ( jobId , percent , STATUS ) ; } String sclass = tab . getCell ( i , 0 ) ; String pred = tab . getCell ( i , 1 ) ; String oclass = tab . getCell ( i , 2 ) ; long count = tab . getCellAsInt ( i , 3 ) ; if ( ! oclass . isEmpty ( ) ) { Triple t = new Triple ( sclass , pred , oclass ) ; if ( ! tripleHash . containsKey ( sclass ) ) { tripleHash . put ( sclass , new HashSet < Triple > ( ) ) ; } tripleHash . get ( sclass ) . add ( t ) ; if ( ! tripleHash . containsKey ( oclass ) ) { tripleHash . put ( oclass , new HashSet < Triple > ( ) ) ; } tripleHash . get ( oclass ) . add ( t ) ; } OntologyPath p = new OntologyPath ( sclass ) ; p . addTriple ( sclass , pred , oclass ) ; String key = this . buildKey ( p ) ; this . exactHash . put ( key , count ) ; pathHash . put ( key , p ) ; } final int MAX_HOPS = 1 ; HashSet < String > lastLenKeys = new HashSet < String > ( ) ; lastLenKeys . addAll ( this . exactHash . keySet ( ) ) ; for ( int thisLen = 2 ; thisLen <= MAX_HOPS ; thisLen ++ ) { HashSet < String > thisLenKeys = new HashSet < String > ( ) ; for ( String key : lastLenKeys ) { OntologyPath p = pathHash . get ( key ) ; HashSet < Triple > triples = tripleHash . get ( p . getEndClassName ( ) ) ; if ( triples != null ) { for ( Triple t : tripleHash . get ( p . getEndClassName ( ) ) ) { if ( ! p . containsClass ( t . getSubject ( ) ) || ! p . containsClass ( t . getObject ( ) ) ) { OntologyPath pathCopy = p . deepCopy ( ) ; pathCopy . addTriple ( t . getSubject ( ) , t . getPredicate ( ) , t . getObject ( ) ) ; long instanceCount = this . countInstanceData ( pathCopy , conn , oInfo ) ; if ( instanceCount > 0 ) { String k = this . buildKey ( pathCopy ) ; this . exactHash . put ( k , instanceCount ) ; thisLenKeys . add ( k ) ; pathHash . put ( k , pathCopy ) ; } } } } } lastLenKeys = thisLenKeys ; } if ( tracker != null ) { tracker . setJobPercentComplete ( jobId , endPercent , STATUS ) ; } }
For a table of exact results  subj pred obj count
 set statsHash such that hash(s,p,o) gets sum of all triples where:
         subject_superclass* predicate_superclass* object_superclass*  * @param t
For a table of exact results subj pred obj count set statsHash such that hash ( s p o ) gets sum of all triples where : subject_superclass * predicate_superclass * object_superclass * * @param t
//		final String W3 = "http://www.w3.org"; // hash start class or endclass to a list of one-hop triples // hash an exactHash key to endClass // extract info from query result row //  Need #type for Explore tab, so consider this a failed experiment //			if (sclass.startsWith(W3) || pred.startsWith(W3) || oclass.startsWith(W3)) //				continue; // build one-hop Triple and add to tripleHash twice: once for subject, once for object // do not include data properties (oclass is empty) // add one-hops to exactHash // hash the other details //-------- build additional hops ---------// // Seems to have insurmountable performance problems // // TODO // needs to be used by path-finding: check the end of the new path // smarter setJobPercentComplete() // needs return only one-hops to SPARQLgraph // MAX_HOPS would be higher, and probably accessible for findExactPaths() // for each length of path up the the max we want to compute // for each path of the previous length // for each triple that could be added to the end // if new triple wouldn't cause a loop // add triple to new path ///////// DEBUG /////////// //for (OntologyPath p : pathHash.values()) { //	LocalLogger.logToStdOut(p.debugString()); //} ///////////////////////////