sparqlGraphLibrary/src/main/java/com/ge/research/semtk/ontologyTools/PathExplorer.java
private NodeGroup buildNgWithData(ArrayList<ClassInstance> classInstanceList, ArrayList<String> propRetList, ArrayList<String> objRetList) throws Exception {

		// get all model paths between all pairs
		ArrayList<OntologyPath> pathList = new ArrayList<OntologyPath>(); 
		ArrayList<ClassInstance> anchorInstanceList = new ArrayList<ClassInstance>();
		ArrayList<ClassInstance> endInstanceList = new ArrayList<ClassInstance>();
		
		ArrayList<ArrayList<ClassInstance>> missingClassLists = new ArrayList<ArrayList<ClassInstance>>();
		ArrayList<ArrayList<String>> missingPropLists = new ArrayList<ArrayList<String>>();

		int smallest = 9999;
		
		for (int i=0; i < classInstanceList.size() - 1; i++) {
			for (int j=i+1; j < classInstanceList.size(); j++) {
				
				for (OntologyPath path : this.oInfo.findAllPaths(classInstanceList.get(j).classUri, classInstanceList.get(i).classUri)) {
					pathList.add(path);
					anchorInstanceList.add(classInstanceList.get(i));
					endInstanceList.add(classInstanceList.get(j));
					
					// calculate missing instances for path
					ArrayList<ClassInstance> missingClassList = path.calcMissingInstances(classInstanceList);
					ArrayList<String> missingPropList = path.calcMissingProperties(propRetList, this.oInfo);
					missingClassLists.add(missingClassList);
					missingPropLists.add(missingPropList);

					if (missingClassList.size() + missingPropList.size() < smallest) {
						smallest = missingClassList.size() + missingPropList.size();
					}
				}
			}
		}
		
		// loop through paths with least missing classes first
		for (int size=smallest; size < classInstanceList.size(); size++) {
			for (int i = 0; i < pathList.size(); i++) {
				boolean success = true;
				if (missingClassLists.get(i).size() + missingPropLists.get(i).size() == size) {
					LocalLogger.logToStdOut("buildNgWithData trying path: " + pathList.get(i).asString());
					// build nodegroup with anchor node
					NodeGroup ng = new NodeGroup();
					Node anchor = null;
					if (anchorInstanceList.get(i) == null) {
						anchor = ng.addNode(anchorInstanceList.get(i).classUri, this.oInfo);
					} else {
						anchor = ng.addNodeInstance(anchorInstanceList.get(i).classUri, this.oInfo, anchorInstanceList.get(i).instanceUri);
					}
					
					// if this path has instances
					if (this.pathHasInstance(ng, anchor, pathList.get(i), endInstanceList.get(i).instanceUri)) {
						
						// add the path
						Node added = ng.addPath(pathList.get(i), anchor, oInfo);
						if (endInstanceList.get(i).instanceUri != null) {
							added.addValueConstraint(ValueConstraint.buildFilterInConstraint(added, endInstanceList.get(i).instanceUri));
						}
						
						// try adding all the missing instances
						for (ClassInstance missingInstance : missingClassLists.get(i)) {
							Node addedMissing = this.addClassFirstPath(ng, missingInstance.classUri, missingInstance.instanceUri);
							if (addedMissing == null) {
								success = false;
								LocalLogger.logToStdOut("...failed to add class: " + missingInstance.classUri);
								break;
							}
						}
						if (! success) 
							break;
				
						// make a copy in hopes we can cache this
						NodeGroup cacheNg = NodeGroup.deepCopy(ng);
						
						success = this.addEnumReturns(ng, objRetList);
						if (! success) 
							break;
						
						success = this.addDataPropReturn(ng, propRetList);
						if (! success) 
							break;
						
						LocalLogger.logToStdOut("...succeeded");
						this.putToCache(cacheNg, classInstanceList);
						return ng;
					}
				}
			}
		}
		
		return null;
	}
/**
	 * Build a nodegroup with all classes in clasInstanceList, possibly constrained to URI's
	 * Add property and enum returns 
	 * Saves to cache 
	 *   
	 * @param classInstanceList
	 * @param propRetList
	 * @param objRetList
	 * @return
	 * @throws Exception
	 */
Build a nodegroup with all classes in clasInstanceList, possibly constrained to URI's
Add property and enum returns
Saves to cache


Build a nodegroup with all classes in clasInstanceList possibly constrained to URI ' s Add property and enum returns Saves to cache
private NodeGroup buildNgWithData(ArrayList<ClassInstance> classInstanceList, ArrayList<String> propRetList, ArrayList<String> objRetList) throws Exception {
		ArrayList<OntologyPath> pathList = new ArrayList<OntologyPath>(); 
		ArrayList<ClassInstance> anchorInstanceList = new ArrayList<ClassInstance>();
		ArrayList<ClassInstance> endInstanceList = new ArrayList<ClassInstance>();
		ArrayList<ArrayList<ClassInstance>> missingClassLists = new ArrayList<ArrayList<ClassInstance>>();
		ArrayList<ArrayList<String>> missingPropLists = new ArrayList<ArrayList<String>>();
		int smallest = 9999;
		for (int i=0; i < classInstanceList.size() - 1; i++) {
			for (int j=i+1; j < classInstanceList.size(); j++) {
				for (OntologyPath path : this.oInfo.findAllPaths(classInstanceList.get(j).classUri, classInstanceList.get(i).classUri)) {
					pathList.add(path);
					anchorInstanceList.add(classInstanceList.get(i));
					endInstanceList.add(classInstanceList.get(j));
					ArrayList<ClassInstance> missingClassList = path.calcMissingInstances(classInstanceList);
					ArrayList<String> missingPropList = path.calcMissingProperties(propRetList, this.oInfo);
					missingClassLists.add(missingClassList);
					missingPropLists.add(missingPropList);
					if (missingClassList.size() + missingPropList.size() < smallest) {
						smallest = missingClassList.size() + missingPropList.size();
					}
				}
			}
		}
		for (int size=smallest; size < classInstanceList.size(); size++) {
			for (int i = 0; i < pathList.size(); i++) {
				boolean success = true;
				if (missingClassLists.get(i).size() + missingPropLists.get(i).size() == size) {
					LocalLogger.logToStdOut("buildNgWithData trying path: " + pathList.get(i).asString());
					NodeGroup ng = new NodeGroup();
					Node anchor = null;
					if (anchorInstanceList.get(i) == null) {
						anchor = ng.addNode(anchorInstanceList.get(i).classUri, this.oInfo);
					} else {
						anchor = ng.addNodeInstance(anchorInstanceList.get(i).classUri, this.oInfo, anchorInstanceList.get(i).instanceUri);
					}
					if (this.pathHasInstance(ng, anchor, pathList.get(i), endInstanceList.get(i).instanceUri)) {
						Node added = ng.addPath(pathList.get(i), anchor, oInfo);
						if (endInstanceList.get(i).instanceUri != null) {
							added.addValueConstraint(ValueConstraint.buildFilterInConstraint(added, endInstanceList.get(i).instanceUri));
						}
						for (ClassInstance missingInstance : missingClassLists.get(i)) {
							Node addedMissing = this.addClassFirstPath(ng, missingInstance.classUri, missingInstance.instanceUri);
							if (addedMissing == null) {
								success = false;
								LocalLogger.logToStdOut("...failed to add class: " + missingInstance.classUri);
								break;
							}
						}
						if (! success) 
							break;
						NodeGroup cacheNg = NodeGroup.deepCopy(ng);
						success = this.addEnumReturns(ng, objRetList);
						if (! success) 
							break;
						success = this.addDataPropReturn(ng, propRetList);
						if (! success) 
							break;
						LocalLogger.logToStdOut("...succeeded");
						this.putToCache(cacheNg, classInstanceList);
						return ng;
					}
				}
			}
		}
		return null;
	}
private NodeGroup buildNgWithData ( ArrayList < ClassInstance > classInstanceList , ArrayList < String > propRetList , ArrayList < String > objRetList ) throws Exception { ArrayList < OntologyPath > pathList = new ArrayList < OntologyPath > ( ) ; ArrayList < ClassInstance > anchorInstanceList = new ArrayList < ClassInstance > ( ) ; ArrayList < ClassInstance > endInstanceList = new ArrayList < ClassInstance > ( ) ; ArrayList < ArrayList < ClassInstance > > missingClassLists = new ArrayList < ArrayList < ClassInstance > > ( ) ; ArrayList < ArrayList < String > > missingPropLists = new ArrayList < ArrayList < String > > ( ) ; int smallest = 9999 ; for ( int i = 0 ; i < classInstanceList . size ( ) - 1 ; i ++ ) { for ( int j = i + 1 ; j < classInstanceList . size ( ) ; j ++ ) { for ( OntologyPath path : this . oInfo . findAllPaths ( classInstanceList . get ( j ) . classUri , classInstanceList . get ( i ) . classUri ) ) { pathList . add ( path ) ; anchorInstanceList . add ( classInstanceList . get ( i ) ) ; endInstanceList . add ( classInstanceList . get ( j ) ) ; ArrayList < ClassInstance > missingClassList = path . calcMissingInstances ( classInstanceList ) ; ArrayList < String > missingPropList = path . calcMissingProperties ( propRetList , this . oInfo ) ; missingClassLists . add ( missingClassList ) ; missingPropLists . add ( missingPropList ) ; if ( missingClassList . size ( ) + missingPropList . size ( ) < smallest ) { smallest = missingClassList . size ( ) + missingPropList . size ( ) ; } } } } for ( int size = smallest ; size < classInstanceList . size ( ) ; size ++ ) { for ( int i = 0 ; i < pathList . size ( ) ; i ++ ) { boolean success = true ; if ( missingClassLists . get ( i ) . size ( ) + missingPropLists . get ( i ) . size ( ) == size ) { LocalLogger . logToStdOut ( "buildNgWithData trying path: " + pathList . get ( i ) . asString ( ) ) ; NodeGroup ng = new NodeGroup ( ) ; Node anchor = null ; if ( anchorInstanceList . get ( i ) == null ) { anchor = ng . addNode ( anchorInstanceList . get ( i ) . classUri , this . oInfo ) ; } else { anchor = ng . addNodeInstance ( anchorInstanceList . get ( i ) . classUri , this . oInfo , anchorInstanceList . get ( i ) . instanceUri ) ; } if ( this . pathHasInstance ( ng , anchor , pathList . get ( i ) , endInstanceList . get ( i ) . instanceUri ) ) { Node added = ng . addPath ( pathList . get ( i ) , anchor , oInfo ) ; if ( endInstanceList . get ( i ) . instanceUri != null ) { added . addValueConstraint ( ValueConstraint . buildFilterInConstraint ( added , endInstanceList . get ( i ) . instanceUri ) ) ; } for ( ClassInstance missingInstance : missingClassLists . get ( i ) ) { Node addedMissing = this . addClassFirstPath ( ng , missingInstance . classUri , missingInstance . instanceUri ) ; if ( addedMissing == null ) { success = false ; LocalLogger . logToStdOut ( "...failed to add class: " + missingInstance . classUri ) ; break ; } } if ( ! success ) break ; NodeGroup cacheNg = NodeGroup . deepCopy ( ng ) ; success = this . addEnumReturns ( ng , objRetList ) ; if ( ! success ) break ; success = this . addDataPropReturn ( ng , propRetList ) ; if ( ! success ) break ; LocalLogger . logToStdOut ( "...succeeded" ) ; this . putToCache ( cacheNg , classInstanceList ) ; return ng ; } } } } return null ; }
Build a nodegroup with all classes in clasInstanceList, possibly constrained to URI's
 Add property and enum returns
 Saves to cache
Build a nodegroup with all classes in clasInstanceList possibly constrained to URI ' s Add property and enum returns Saves to cache
// get all model paths between all pairs // calculate missing instances for path // loop through paths with least missing classes first // build nodegroup with anchor node // if this path has instances // add the path // try adding all the missing instances // make a copy in hopes we can cache this