sparqlGraphLibrary/src/main/java/com/ge/research/semtk/belmont/NodeGroup.java
public Node addPath(OntologyPath path, Node anchorNode, OntologyInfo oInfo, Boolean reverseFlag, Boolean optionalFlag) throws Exception  {

		Node retNode = this.addNode(path.getStartClassName(), oInfo);
		Node lastNode = reverseFlag ? anchorNode : retNode;
		Node node0;
		Node node1;
		int pathLen = path.getLength();
		// loop through path but not the last one
		for (int i = 0; i < pathLen - 1; i++) {
			String class0Uri = path.getClass0Name(i);
			String attUri = path.getAttributeName(i);
			String class1Uri = path.getClass1Name(i);

			
			if (class0Uri.equals(lastNode.getUri())) {
				//  this hop in path is  lastAdded--hasX-->class1
				node1 = this.returnBelmontSemanticNode(class1Uri, oInfo);
				this.addOneNode(node1, lastNode, null, attUri);
				lastNode = node1;
				
				if (optionalFlag) {
					throw new Exception("Internal error in belmont.js:AddPath(): SparqlGraph is not smart enough\nto add an optional path with links pointing away from the new node.\nAdding path without optional flag.");
				}
			
			} else {
				// else this hop in path is class0--hasX-->lastAdded
				node0 = this.returnBelmontSemanticNode(class0Uri, oInfo);
				this.addOneNode(node0, lastNode, attUri, null);
				lastNode = node0;
			}
		}

		// link the last two nodes, which by now already exist
		String class1Uri = path.getClass1Name(pathLen - 1);
		String attUri = path.getAttributeName(pathLen - 1);
		Node finalNode = reverseFlag ? retNode : anchorNode;

		
		if (finalNode.getUri().equals(class1Uri)) {
			// normal link from last node to anchor node, 
			// When last connection URI matches and reverseFlag isn't set
			int opt = optionalFlag ? NodeItem.OPTIONAL_REVERSE : NodeItem.OPTIONAL_FALSE;
			lastNode.setConnection(finalNode, attUri, opt);
			
		
		} else {
			// reverse connection
			// either reverseFlag, or normal direction URI wasn't correct so presume backwards will work
			// throw exception if URI doesn't work
			int opt = optionalFlag ? NodeItem.OPTIONAL_TRUE : NodeItem.OPTIONAL_FALSE;
			finalNode.setConnection(lastNode, attUri, opt);
		}
		return retNode;

	}
/**
	 * Add a path to the nodegroup.  Path's start class is the "new one".  End class connects to nodegroup anchorNode (except reverseFlag)
	 * @param path - path connects in whichever end matches anchorNode.  If both match, default to path END at anchor node.
	 * @param anchorNode - Path connects here
	 * @param oInfo - used to properly build new nodes
	 * @param reverseFlag - Connect with Path START at anchor node, or throw and exception if URI doesn't match
	 * @param optionalFlag - should connection point be OPTIONAL
	 * @return the node at the end of the path that is new to the nodegroup
	 * @throws Exception
	 */
Add a path to the nodegroup.  Path's start class is the "new one".  End class connects to nodegroup anchorNode (except reverseFlag)
@param path - path connects in whichever end matches anchorNode.  If both match, default to path END at anchor node.
Add a path to the nodegroup . Path ' s start class is the " new one " . End class connects to nodegroup anchorNode ( except reverseFlag ) @param path - path connects in whichever end matches anchorNode . If both match default to path END at anchor node .
public Node addPath(OntologyPath path, Node anchorNode, OntologyInfo oInfo, Boolean reverseFlag, Boolean optionalFlag) throws Exception  {
		Node retNode = this.addNode(path.getStartClassName(), oInfo);
		Node lastNode = reverseFlag ? anchorNode : retNode;
		Node node0;
		Node node1;
		int pathLen = path.getLength();
		for (int i = 0; i < pathLen - 1; i++) {
			String class0Uri = path.getClass0Name(i);
			String attUri = path.getAttributeName(i);
			String class1Uri = path.getClass1Name(i);
			if (class0Uri.equals(lastNode.getUri())) {
				node1 = this.returnBelmontSemanticNode(class1Uri, oInfo);
				this.addOneNode(node1, lastNode, null, attUri);
				lastNode = node1;
				if (optionalFlag) {
					throw new Exception("Internal error in belmont.js:AddPath(): SparqlGraph is not smart enough\nto add an optional path with links pointing away from the new node.\nAdding path without optional flag.");
				}
			} else {
				node0 = this.returnBelmontSemanticNode(class0Uri, oInfo);
				this.addOneNode(node0, lastNode, attUri, null);
				lastNode = node0;
			}
		}
		String class1Uri = path.getClass1Name(pathLen - 1);
		String attUri = path.getAttributeName(pathLen - 1);
		Node finalNode = reverseFlag ? retNode : anchorNode;
		if (finalNode.getUri().equals(class1Uri)) {
			int opt = optionalFlag ? NodeItem.OPTIONAL_REVERSE : NodeItem.OPTIONAL_FALSE;
			lastNode.setConnection(finalNode, attUri, opt);
		} else {
			int opt = optionalFlag ? NodeItem.OPTIONAL_TRUE : NodeItem.OPTIONAL_FALSE;
			finalNode.setConnection(lastNode, attUri, opt);
		}
		return retNode;
	}
public Node addPath ( OntologyPath path , Node anchorNode , OntologyInfo oInfo , Boolean reverseFlag , Boolean optionalFlag ) throws Exception { Node retNode = this . addNode ( path . getStartClassName ( ) , oInfo ) ; Node lastNode = reverseFlag ? anchorNode : retNode ; Node node0 ; Node node1 ; int pathLen = path . getLength ( ) ; for ( int i = 0 ; i < pathLen - 1 ; i ++ ) { String class0Uri = path . getClass0Name ( i ) ; String attUri = path . getAttributeName ( i ) ; String class1Uri = path . getClass1Name ( i ) ; if ( class0Uri . equals ( lastNode . getUri ( ) ) ) { node1 = this . returnBelmontSemanticNode ( class1Uri , oInfo ) ; this . addOneNode ( node1 , lastNode , null , attUri ) ; lastNode = node1 ; if ( optionalFlag ) { throw new Exception ( "Internal error in belmont.js:AddPath(): SparqlGraph is not smart enough\nto add an optional path with links pointing away from the new node.\nAdding path without optional flag." ) ; } } else { node0 = this . returnBelmontSemanticNode ( class0Uri , oInfo ) ; this . addOneNode ( node0 , lastNode , attUri , null ) ; lastNode = node0 ; } } String class1Uri = path . getClass1Name ( pathLen - 1 ) ; String attUri = path . getAttributeName ( pathLen - 1 ) ; Node finalNode = reverseFlag ? retNode : anchorNode ; if ( finalNode . getUri ( ) . equals ( class1Uri ) ) { int opt = optionalFlag ? NodeItem . OPTIONAL_REVERSE : NodeItem . OPTIONAL_FALSE ; lastNode . setConnection ( finalNode , attUri , opt ) ; } else { int opt = optionalFlag ? NodeItem . OPTIONAL_TRUE : NodeItem . OPTIONAL_FALSE ; finalNode . setConnection ( lastNode , attUri , opt ) ; } return retNode ; }
Add a path to the nodegroup.
Add a path to the nodegroup .
// loop through path but not the last one //  this hop in path is  lastAdded--hasX-->class1 // else this hop in path is class0--hasX-->lastAdded // link the last two nodes, which by now already exist // normal link from last node to anchor node,  // When last connection URI matches and reverseFlag isn't set // reverse connection // either reverseFlag, or normal direction URI wasn't correct so presume backwards will work // throw exception if URI doesn't work