String potentialType = XMLTools.getAttributeValueOrThrowException(domNode, "potential",
"A potential attribute must be specified in order to generate a clique set!");
// If there is more than one term, then add appropriate cliques.
ArrayList<GraphNode> cliqueNodes = null;
Clique c = null;
for (int i = 1; i < Math.pow(2, queryTerms.length); i++) {
String binary = Integer.toBinaryString(i);
int padding = queryTerms.length - binary.length();
for (int j = 0; j < padding; j++) {
binary = "0" + binary;
}
boolean singleTerm = false;
boolean contiguous = true;
int firstOne = binary.indexOf('1');
int lastOne = binary.lastIndexOf('1');
if (lastOne == firstOne) {
singleTerm = true;
}
for (int j = binary.indexOf('1') + 1; j <= binary.lastIndexOf('1') - 1; j++) {
if (binary.charAt(j) == '0') {
contiguous = false;
break;
}
}
if (ordered && !singleTerm && contiguous) {
cliqueNodes = Lists.newArrayList();
if (docDependent) {
cliqueNodes.add(docNode);
}
for (int j = firstOne; j <= lastOne; j++) {
TermNode termNode = new TermNode(queryTerms[j]);
cliqueNodes.add(termNode);
}
// Get the potential function.
PotentialFunction potential = PotentialFunction.create(env, potentialType, domNode);
c = new Clique(cliqueNodes, potential, parameter);
cliques.add(c);
} else if (!ordered && !singleTerm && !contiguous) {
cliqueNodes = Lists.newArrayList();
if (docDependent) {
cliqueNodes.add(docNode);
}
for (int j = 0; j < binary.length(); j++) {
if (binary.charAt(j) == '1') {
TermNode termNode = new TermNode(queryTerms[j]);
cliqueNodes.add(termNode);
}
}
// Get the potential function.
PotentialFunction potential = PotentialFunction.create(env, potentialType, domNode);
c = new Clique(cliqueNodes, potential, parameter);
cliques.add(c);
}
}
return cliques;