sparqlGraphLibrary/src/main/java/com/ge/research/semtk/belmont/NodeGroup.java
private String generateSparqlSubgraphClausesPropItem(ClauseTypes clauseType, Node snode, PropertyItem prop, Returnable targetObj, String tab) throws Exception {
		boolean indentFlag = false;
		StringBuilder sparql = new StringBuilder();		
		
		if (prop.getSparqlID().isEmpty()) {
			throw new Error ("Can't create SPARQL for property with empty sparql ID: " + prop.getKeyName());
		}
		// check for being optional...
		if(prop.getOptMinus() == PropertyItem.OPT_MINUS_OPTIONAL && clauseType != ClauseTypes.CONSTRUCT_LEADER){
			sparql.append(tab + "optional{\n");
			tab = SparqlToXUtils.tabIndent(tab);
			indentFlag = true;
		} else if(prop.getOptMinus() == PropertyItem.OPT_MINUS_MINUS && clauseType != ClauseTypes.CONSTRUCT_LEADER){
			sparql.append(tab + "minus {\n");
			tab = SparqlToXUtils.tabIndent(tab);
			indentFlag = true;
		}
		
		// get subPropNames or null for IDK
		HashSet<String> subPropNames = (this.oInfo == null) ? null : this.oInfo.inferSubPropertyNames(prop.getUriRelationship(), snode.getUri());
		
		/**
		// Virtuoso can't handle subPropertyOf:
		// It is a messy presumption for sparql.
		// For now, if there's no oInfo, there are no sub-properties.

		if (subPropNames == null) {
			// don't know if there are sub-properties
			String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getUriRelationship());

			if (queryType == AutoGeneratedQueryTypes.QUERY_CONSTRUCT) {
				// varname no values clause
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");

			} else if (	queryType == AutoGeneratedQueryTypes.QUERY_CONSTRUCT_WHERE) {
				// varname plus values clause
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + predVarName + " rdfs:subPropertyOf* " +  this.applyPrefixing(prop.getUriRelationship()) + " .\n");
				
			} else {   // WHERE and DISTINCT
				// varname plus values clause
				sparql.append(tab + snode.getSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + predVarName + " rdfs:subPropertyOf* " +  this.applyPrefixing(prop.getUriRelationship()) + " .\n");
			} 
			
		} else 
		**/
		if (subPropNames == null || subPropNames.size() == 0) {
			// no sub-properties
			
			// CONSTRUCT uses the binding, where others use the sparqlID 
			String nodeId =  (clauseType == ClauseTypes.CONSTRUCT_LEADER) ? snode.getBindingOrSparqlID() : snode.getSparqlID();
			
			sparql.append(tab + nodeId + " " + this.applyPrefixing(prop.getUriRelationship()) + " " + prop.getSparqlID() +  " .\n");
		
		} else {
			// prop with sub-props
			String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getUriRelationship());

			if (clauseType == ClauseTypes.CONSTRUCT_LEADER) {
				// varname no values clause
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");

			} else if (	clauseType == ClauseTypes.CONSTRUCT_WHERE) {
				// varname plus values clause
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getUriRelationship(), subPropNames) + " .\n");
				
			} else if (	clauseType == ClauseTypes.DELETE_WHERE) {
				// varname plus values clause
				sparql.append(tab + snode.getSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getUriRelationship(), subPropNames) + " .\n");
				
			} else {
				// "normal": parenthesized predicate
				sparql.append(tab + snode.getSparqlID() + " " + this.genSubPropertyListParenthesized(prop.getUriRelationship(), subPropNames)+  " " + prop.getSparqlID() +  " .\n");
			}
			
		}
		
		if (prop.getBinding() != null && clauseType != ClauseTypes.CONSTRUCT_LEADER) {
			sparql.append(tab + "BIND(" + prop.getSparqlID() + " as " +  prop.getBinding() + ") .\n" );
		}
	
		// add in attribute range constraint if there is one 
		if(prop.getConstraints() != null && prop.getConstraints() != ""){
			// add unless this is a CONSTRAINT query on targetObj
			if((clauseType != ClauseTypes.CONSTRUCT_LEADER) && (clauseType != ClauseTypes.CONSTRAINT || targetObj == null || prop.getSparqlID() != targetObj.getSparqlID())){
				if(prop.getConstraints() != null && !prop.getConstraints().equalsIgnoreCase("")){
					tab = SparqlToXUtils.tabIndent(tab);
					sparql.append(tab + prop.getConstraints() + " .\n");
					tab = SparqlToXUtils.tabOutdent(tab);
				}
			}
		}
		
		// close optional block.
		if(indentFlag){
			tab = SparqlToXUtils.tabOutdent(tab);
			sparql.append(tab + "} \n");
		}
		return sparql.toString();
	}
/** PropertyItem portion of a subgraph clause.
	 * (no recursion here)
	 * @param clauseType
	 * @param snode
	 * @param targetObj
	 * @param prop
	 * @param tab
	 * @return
	 * @throws Exception
	 */
PropertyItem portion of a subgraph clause.
PropertyItem portion of a subgraph clause .
private String generateSparqlSubgraphClausesPropItem(ClauseTypes clauseType, Node snode, PropertyItem prop, Returnable targetObj, String tab) throws Exception {
		boolean indentFlag = false;
		StringBuilder sparql = new StringBuilder();		
		if (prop.getSparqlID().isEmpty()) {
			throw new Error ("Can't create SPARQL for property with empty sparql ID: " + prop.getKeyName());
		}
		if(prop.getOptMinus() == PropertyItem.OPT_MINUS_OPTIONAL && clauseType != ClauseTypes.CONSTRUCT_LEADER){
			sparql.append(tab + "optional{\n");
			tab = SparqlToXUtils.tabIndent(tab);
			indentFlag = true;
		} else if(prop.getOptMinus() == PropertyItem.OPT_MINUS_MINUS && clauseType != ClauseTypes.CONSTRUCT_LEADER){
			sparql.append(tab + "minus {\n");
			tab = SparqlToXUtils.tabIndent(tab);
			indentFlag = true;
		}
		HashSet<String> subPropNames = (this.oInfo == null) ? null : this.oInfo.inferSubPropertyNames(prop.getUriRelationship(), snode.getUri());
		/**
		// Virtuoso can't handle subPropertyOf:
		// It is a messy presumption for sparql.
		// For now, if there's no oInfo, there are no sub-properties.
		if (subPropNames == null) {
			// don't know if there are sub-properties
			String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getUriRelationship());
			if (queryType == AutoGeneratedQueryTypes.QUERY_CONSTRUCT) {
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
			} else if (	queryType == AutoGeneratedQueryTypes.QUERY_CONSTRUCT_WHERE) {
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + predVarName + " rdfs:subPropertyOf* " +  this.applyPrefixing(prop.getUriRelationship()) + " .\n");
			} else {   // WHERE and DISTINCT
				sparql.append(tab + snode.getSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + predVarName + " rdfs:subPropertyOf* " +  this.applyPrefixing(prop.getUriRelationship()) + " .\n");
			} 
		} else 
		**/
		if (subPropNames == null || subPropNames.size() == 0) {
			String nodeId =  (clauseType == ClauseTypes.CONSTRUCT_LEADER) ? snode.getBindingOrSparqlID() : snode.getSparqlID();
			sparql.append(tab + nodeId + " " + this.applyPrefixing(prop.getUriRelationship()) + " " + prop.getSparqlID() +  " .\n");
		} else {
			String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getUriRelationship());
			if (clauseType == ClauseTypes.CONSTRUCT_LEADER) {
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
			} else if (	clauseType == ClauseTypes.CONSTRUCT_WHERE) {
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getUriRelationship(), subPropNames) + " .\n");
			} else if (	clauseType == ClauseTypes.DELETE_WHERE) {
				sparql.append(tab + snode.getSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getUriRelationship(), subPropNames) + " .\n");
			} else {
				sparql.append(tab + snode.getSparqlID() + " " + this.genSubPropertyListParenthesized(prop.getUriRelationship(), subPropNames)+  " " + prop.getSparqlID() +  " .\n");
			}
		}
		if (prop.getBinding() != null && clauseType != ClauseTypes.CONSTRUCT_LEADER) {
			sparql.append(tab + "BIND(" + prop.getSparqlID() + " as " +  prop.getBinding() + ") .\n" );
		}
		if(prop.getConstraints() != null && prop.getConstraints() != ""){
			if((clauseType != ClauseTypes.CONSTRUCT_LEADER) && (clauseType != ClauseTypes.CONSTRAINT || targetObj == null || prop.getSparqlID() != targetObj.getSparqlID())){
				if(prop.getConstraints() != null && !prop.getConstraints().equalsIgnoreCase("")){
					tab = SparqlToXUtils.tabIndent(tab);
					sparql.append(tab + prop.getConstraints() + " .\n");
					tab = SparqlToXUtils.tabOutdent(tab);
				}
			}
		}
		if(indentFlag){
			tab = SparqlToXUtils.tabOutdent(tab);
			sparql.append(tab + "} \n");
		}
		return sparql.toString();
	}
private String generateSparqlSubgraphClausesPropItem ( ClauseTypes clauseType , Node snode , PropertyItem prop , Returnable targetObj , String tab ) throws Exception { boolean indentFlag = false ; StringBuilder sparql = new StringBuilder ( ) ; if ( prop . getSparqlID ( ) . isEmpty ( ) ) { throw new Error ( "Can't create SPARQL for property with empty sparql ID: " + prop . getKeyName ( ) ) ; } if ( prop . getOptMinus ( ) == PropertyItem . OPT_MINUS_OPTIONAL && clauseType != ClauseTypes . CONSTRUCT_LEADER ) { sparql . append ( tab + "optional{\n" ) ; tab = SparqlToXUtils . tabIndent ( tab ) ; indentFlag = true ; } else if ( prop . getOptMinus ( ) == PropertyItem . OPT_MINUS_MINUS && clauseType != ClauseTypes . CONSTRUCT_LEADER ) { sparql . append ( tab + "minus {\n" ) ; tab = SparqlToXUtils . tabIndent ( tab ) ; indentFlag = true ; } HashSet < String > subPropNames = ( this . oInfo == null ) ? null : this . oInfo . inferSubPropertyNames ( prop . getUriRelationship ( ) , snode . getUri ( ) ) ; /**
		// Virtuoso can't handle subPropertyOf:
		// It is a messy presumption for sparql.
		// For now, if there's no oInfo, there are no sub-properties.

		if (subPropNames == null) {
			// don't know if there are sub-properties
			String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getUriRelationship());

			if (queryType == AutoGeneratedQueryTypes.QUERY_CONSTRUCT) {
				// varname no values clause
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");

			} else if (	queryType == AutoGeneratedQueryTypes.QUERY_CONSTRUCT_WHERE) {
				// varname plus values clause
				sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + predVarName + " rdfs:subPropertyOf* " +  this.applyPrefixing(prop.getUriRelationship()) + " .\n");
				
			} else {   // WHERE and DISTINCT
				// varname plus values clause
				sparql.append(tab + snode.getSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
				sparql.append(tab + predVarName + " rdfs:subPropertyOf* " +  this.applyPrefixing(prop.getUriRelationship()) + " .\n");
			} 
			
		} else 
		**/ if ( subPropNames == null || subPropNames . size ( ) == 0 ) { String nodeId = ( clauseType == ClauseTypes . CONSTRUCT_LEADER ) ? snode . getBindingOrSparqlID ( ) : snode . getSparqlID ( ) ; sparql . append ( tab + nodeId + " " + this . applyPrefixing ( prop . getUriRelationship ( ) ) + " " + prop . getSparqlID ( ) + " .\n" ) ; } else { String predVarName = SparqlToXUtils . safeSparqlVar ( snode . getSparqlID ( ) + "_" + prop . getUriRelationship ( ) ) ; if ( clauseType == ClauseTypes . CONSTRUCT_LEADER ) { sparql . append ( tab + snode . getBindingOrSparqlID ( ) + " " + predVarName + " " + prop . getSparqlID ( ) + " .\n" ) ; } else if ( clauseType == ClauseTypes . CONSTRUCT_WHERE ) { sparql . append ( tab + snode . getBindingOrSparqlID ( ) + " " + predVarName + " " + prop . getSparqlID ( ) + " .\n" ) ; sparql . append ( tab + this . genSubPropertiesContraint ( predVarName , prop . getUriRelationship ( ) , subPropNames ) + " .\n" ) ; } else if ( clauseType == ClauseTypes . DELETE_WHERE ) { sparql . append ( tab + snode . getSparqlID ( ) + " " + predVarName + " " + prop . getSparqlID ( ) + " .\n" ) ; sparql . append ( tab + this . genSubPropertiesContraint ( predVarName , prop . getUriRelationship ( ) , subPropNames ) + " .\n" ) ; } else { sparql . append ( tab + snode . getSparqlID ( ) + " " + this . genSubPropertyListParenthesized ( prop . getUriRelationship ( ) , subPropNames ) + " " + prop . getSparqlID ( ) + " .\n" ) ; } } if ( prop . getBinding ( ) != null && clauseType != ClauseTypes . CONSTRUCT_LEADER ) { sparql . append ( tab + "BIND(" + prop . getSparqlID ( ) + " as " + prop . getBinding ( ) + ") .\n" ) ; } if ( prop . getConstraints ( ) != null && prop . getConstraints ( ) != "" ) { if ( ( clauseType != ClauseTypes . CONSTRUCT_LEADER ) && ( clauseType != ClauseTypes . CONSTRAINT || targetObj == null || prop . getSparqlID ( ) != targetObj . getSparqlID ( ) ) ) { if ( prop . getConstraints ( ) != null && ! prop . getConstraints ( ) . equalsIgnoreCase ( "" ) ) { tab = SparqlToXUtils . tabIndent ( tab ) ; sparql . append ( tab + prop . getConstraints ( ) + " .\n" ) ; tab = SparqlToXUtils . tabOutdent ( tab ) ; } } } if ( indentFlag ) { tab = SparqlToXUtils . tabOutdent ( tab ) ; sparql . append ( tab + "} \n" ) ; } return sparql . toString ( ) ; }
PropertyItem portion of a subgraph clause.
PropertyItem portion of a subgraph clause .
// check for being optional... // get subPropNames or null for IDK // no sub-properties // CONSTRUCT uses the binding, where others use the sparqlID  // prop with sub-props // varname no values clause // varname plus values clause // varname plus values clause // "normal": parenthesized predicate // add in attribute range constraint if there is one  // add unless this is a CONSTRAINT query on targetObj // close optional block.