sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/OntologyInfo.java
public ArrayList<OntologyPath> findAllPaths(String fromClassName, HashSet<String> targetClassNames, PredicateStats predStats, NodeGroup ng, SparqlConnection conn) throws Exception {
		if (predStats == null) {
			return this.findExactPaths(fromClassName, targetClassNames);
		} else {
			
			// with predStats, findExactPaths will only find exact matches.
			// So fromClassNames and TargetsWithSubClasses are built containing all subclasses.
			
			// add subclasses to fromClassName
			HashSet<String> fromClassNames = new HashSet<String>();
			fromClassNames.add(fromClassName);
			
			for (String subClass : this.getSubclassNames(fromClassName)) {
				fromClassNames.add(subClass);
			}
			
			// add subclasses to targetClassNames
			HashSet<String> targetsWithSubclasses = new HashSet<String>();
			targetsWithSubclasses.addAll(targetClassNames);
			
			for (String targetClass : targetClassNames) {
				for (String subClass : this.getSubclassNames(targetClass)) {
					targetsWithSubclasses.add(subClass);
				}
			}
		
			// find exact paths
			ArrayList<OntologyPath> paths =  this.findExactPaths(fromClassNames, targetsWithSubclasses, predStats, ng, conn);
		
			// Pull out all the paths that starts or ends on a subclass
			ArrayList<OntologyPath> subclassPaths = new ArrayList<OntologyPath>();
			for (OntologyPath p : paths) {
				// if end class is not in the target list or start class is not fromClass
				if (! targetClassNames.contains(p.getEndClassName()) || !p.getStartClassName().equals(fromClassName) ) {
					subclassPaths.add(p);
				}
			}
			// do actual removal from results, and save for next step
			for (OntologyPath p : subclassPaths) {
				paths.remove(p);
			}
			
			// build hash of returns so far
			HashSet<String> pathsHash = new HashSet<String>();
			for (OntologyPath p : paths) {
				pathsHash.add(p.asString());
			}			
						
			// try to promote each removed path to a correct endClass and re-add to results
			for (OntologyPath p : subclassPaths) {
				if (! targetClassNames.contains(p.getEndClassName())) {
					// find a parent that is in targetClassNames
					for (String superClassName : this.getSuperclassNames(p.getEndClassName())) {
						if (targetClassNames.contains(superClassName)) {
							// if end class promotion succeeds
							if (this.promoteEndClass(p, this.getClass(superClassName))) {
								// if start class is ok OR start class promotion succeeds
								if (p.getStartClassName().equals(fromClassName) || this.promoteStartClass(p, this.getClass(fromClassName))) {
									String hash = p.asString();
									// if result isn't already being returned
									if (!pathsHash.contains(hash)) {
										paths.add(p);
										pathsHash.add(hash);
									}
								}
							}
						}
					}
				} else { 
					// was removed only due to  startClass != fromClassName
					if (this.promoteStartClass(p, this.getClass(fromClassName))) {
						String hash = p.asString();
						// if result isn't already being returned
						if (!pathsHash.contains(hash)) {
							paths.add(p);
							pathsHash.add(hash);
						}
					}
				}
			}
			return paths;
		}
	}
/*
	 * This is a wrapper around findExactPaths such that fromClassName and targetClassNames
	 * can be superclasses of the exact paths found.
	 * If ontology allows, those paths are found, and
	 * the start and/or end classes are promoted to the superclasses passed in.
	 * The resulting paths are "exact" except the ends match the parameters.
	 * 
	 * "Exact" is only meaningful when using PredicateStats and/or a nodegroup to 
	 * find paths that have instance data. 
	 * 
	 * @param fromClassName
	 * @param targetClassNames
	 * @param domain
	 * @param predStats - optional : prune paths by existing predicates and/or existing ng data
	 * @param ng - optional : in addition to predStats, prune paths by existing ng data
	 * @param conn - conn to use with ng when checking instance data
	 * @return
	 * @throws Exception 
	 */
This is a wrapper around findExactPaths such that fromClassName and targetClassNames
can be superclasses of the exact paths found.
If ontology allows, those paths are found, and
the start and/or end classes are promoted to the superclasses passed in.
The resulting paths are "exact" except the ends match the parameters.

"Exact" is only meaningful when using PredicateStats and/or a nodegroup to
find paths that have instance data.


This is a wrapper around findExactPaths such that fromClassName and targetClassNames can be superclasses of the exact paths found . If ontology allows those paths are found and the start and / or end classes are promoted to the superclasses passed in . The resulting paths are " exact " except the ends match the parameters . " Exact " is only meaningful when using PredicateStats and / or a nodegroup to find paths that have instance data .
public ArrayList<OntologyPath> findAllPaths(String fromClassName, HashSet<String> targetClassNames, PredicateStats predStats, NodeGroup ng, SparqlConnection conn) throws Exception {
		if (predStats == null) {
			return this.findExactPaths(fromClassName, targetClassNames);
		} else {
			HashSet<String> fromClassNames = new HashSet<String>();
			fromClassNames.add(fromClassName);
			for (String subClass : this.getSubclassNames(fromClassName)) {
				fromClassNames.add(subClass);
			}
			HashSet<String> targetsWithSubclasses = new HashSet<String>();
			targetsWithSubclasses.addAll(targetClassNames);
			for (String targetClass : targetClassNames) {
				for (String subClass : this.getSubclassNames(targetClass)) {
					targetsWithSubclasses.add(subClass);
				}
			}
			ArrayList<OntologyPath> paths =  this.findExactPaths(fromClassNames, targetsWithSubclasses, predStats, ng, conn);
			ArrayList<OntologyPath> subclassPaths = new ArrayList<OntologyPath>();
			for (OntologyPath p : paths) {
				if (! targetClassNames.contains(p.getEndClassName()) || !p.getStartClassName().equals(fromClassName) ) {
					subclassPaths.add(p);
				}
			}
			for (OntologyPath p : subclassPaths) {
				paths.remove(p);
			}
			HashSet<String> pathsHash = new HashSet<String>();
			for (OntologyPath p : paths) {
				pathsHash.add(p.asString());
			}			
			for (OntologyPath p : subclassPaths) {
				if (! targetClassNames.contains(p.getEndClassName())) {
					for (String superClassName : this.getSuperclassNames(p.getEndClassName())) {
						if (targetClassNames.contains(superClassName)) {
							if (this.promoteEndClass(p, this.getClass(superClassName))) {
								if (p.getStartClassName().equals(fromClassName) || this.promoteStartClass(p, this.getClass(fromClassName))) {
									String hash = p.asString();
									if (!pathsHash.contains(hash)) {
										paths.add(p);
										pathsHash.add(hash);
									}
								}
							}
						}
					}
				} else { 
					if (this.promoteStartClass(p, this.getClass(fromClassName))) {
						String hash = p.asString();
						if (!pathsHash.contains(hash)) {
							paths.add(p);
							pathsHash.add(hash);
						}
					}
				}
			}
			return paths;
		}
	}
public ArrayList < OntologyPath > findAllPaths ( String fromClassName , HashSet < String > targetClassNames , PredicateStats predStats , NodeGroup ng , SparqlConnection conn ) throws Exception { if ( predStats == null ) { return this . findExactPaths ( fromClassName , targetClassNames ) ; } else { HashSet < String > fromClassNames = new HashSet < String > ( ) ; fromClassNames . add ( fromClassName ) ; for ( String subClass : this . getSubclassNames ( fromClassName ) ) { fromClassNames . add ( subClass ) ; } HashSet < String > targetsWithSubclasses = new HashSet < String > ( ) ; targetsWithSubclasses . addAll ( targetClassNames ) ; for ( String targetClass : targetClassNames ) { for ( String subClass : this . getSubclassNames ( targetClass ) ) { targetsWithSubclasses . add ( subClass ) ; } } ArrayList < OntologyPath > paths = this . findExactPaths ( fromClassNames , targetsWithSubclasses , predStats , ng , conn ) ; ArrayList < OntologyPath > subclassPaths = new ArrayList < OntologyPath > ( ) ; for ( OntologyPath p : paths ) { if ( ! targetClassNames . contains ( p . getEndClassName ( ) ) || ! p . getStartClassName ( ) . equals ( fromClassName ) ) { subclassPaths . add ( p ) ; } } for ( OntologyPath p : subclassPaths ) { paths . remove ( p ) ; } HashSet < String > pathsHash = new HashSet < String > ( ) ; for ( OntologyPath p : paths ) { pathsHash . add ( p . asString ( ) ) ; } for ( OntologyPath p : subclassPaths ) { if ( ! targetClassNames . contains ( p . getEndClassName ( ) ) ) { for ( String superClassName : this . getSuperclassNames ( p . getEndClassName ( ) ) ) { if ( targetClassNames . contains ( superClassName ) ) { if ( this . promoteEndClass ( p , this . getClass ( superClassName ) ) ) { if ( p . getStartClassName ( ) . equals ( fromClassName ) || this . promoteStartClass ( p , this . getClass ( fromClassName ) ) ) { String hash = p . asString ( ) ; if ( ! pathsHash . contains ( hash ) ) { paths . add ( p ) ; pathsHash . add ( hash ) ; } } } } } } else { if ( this . promoteStartClass ( p , this . getClass ( fromClassName ) ) ) { String hash = p . asString ( ) ; if ( ! pathsHash . contains ( hash ) ) { paths . add ( p ) ; pathsHash . add ( hash ) ; } } } } return paths ; } }
This is a wrapper around findExactPaths such that fromClassName and targetClassNames
 can be superclasses of the exact paths found.
This is a wrapper around findExactPaths such that fromClassName and targetClassNames can be superclasses of the exact paths found .
// with predStats, findExactPaths will only find exact matches. // So fromClassNames and TargetsWithSubClasses are built containing all subclasses. // add subclasses to fromClassName // add subclasses to targetClassNames // find exact paths // Pull out all the paths that starts or ends on a subclass // if end class is not in the target list or start class is not fromClass // do actual removal from results, and save for next step // build hash of returns so far // try to promote each removed path to a correct endClass and re-add to results // find a parent that is in targetClassNames // if end class promotion succeeds // if start class is ok OR start class promotion succeeds // if result isn't already being returned // was removed only due to  startClass != fromClassName // if result isn't already being returned