cass.rollup.processors.v2.graph.CompetencyGraph Maven / Gradle / Ivy
package cass.rollup.processors.v2.graph;
import org.stjs.javascript.Array;
import org.stjs.javascript.Global;
import org.stjs.javascript.JSCollections;
import org.stjs.javascript.Map;
public class CompetencyGraph {
public static final String NARROWS_RELATION_TEXT = "narrows";
public static final String BROADENS_RELATION_TEXT = "broadens";
public static final String REQUIRES_RELATION_TEXT = "requires";
public static final String IS_REQUIRED_BY_RELATION_TEXT = "isRequiredBy";
public static final String IS_EQUIVALENT_TO_RELATION_TEXT = "isEquivalentTo";
private static final String EDGE_MAP_FIELD_DELIMETER = " -------||||||------- ";
private class CleanGraph {
private Array nodes;
private Array edges;
public CleanGraph(Array nodes, Array edges) {
this.nodes = nodes;
this.edges = edges;
}
}
private class CleanGraphWithAssertions {
private Array nodes;
private Array edges;
private Array positiveAssertions;
private Array negativeAssertions;
public CleanGraphWithAssertions(Array nodes, Array edges, Array positiveAssertions,
Array negativeAssertions) {
this.nodes = nodes;
this.edges = edges;
this.positiveAssertions = positiveAssertions;
this.negativeAssertions = negativeAssertions;
}
}
private Array nodes;
private Array edges;
private Array positiveAssertions;
private Array negativeAssertions;
private Map nodeMap;
private Map edgeMap;
private boolean includeAssertions;
public CompetencyGraph(boolean includeAssertions) {
nodes = new Array();
edges = new Array();
positiveAssertions = new Array();
negativeAssertions = new Array();
nodeMap = JSCollections.$map();
edgeMap = JSCollections.$map();
this.includeAssertions = includeAssertions;
}
public void addNode(String id) {
if (!graphContainsNode(id)) {
nodes.push(id);
nodeMap.$put(id,id);
}
}
private String getEdgeKey(String source, String target, String relationType) {
return source + EDGE_MAP_FIELD_DELIMETER + target + EDGE_MAP_FIELD_DELIMETER + relationType;
}
public void addEdge(String source, String target, String relationType) {
if (!graphContainsEdge(source,target,relationType)) {
edges.push(new CgEdge(source,target,relationType));
String edgeKey = getEdgeKey(source,target,relationType);
edgeMap.$put(edgeKey,edgeKey);
}
}
public void addPositiveAssertion(SimpleAssertion simpleAssertion) {
if (simpleAssertion != null) positiveAssertions.push(simpleAssertion);
}
public void addNegativeAssertion(SimpleAssertion simpleAssertion) {
if (simpleAssertion != null) negativeAssertions.push(simpleAssertion);
}
public boolean graphContainsNode(String nodeId) {
if (nodeMap.$get(nodeId) == null) return false;
return true;
}
public boolean graphContainsEdge(String source, String target, String relationType) {
if (edgeMap.$get(getEdgeKey(source,target,relationType)) == null) return false;
return true;
}
public void createImpliedRelationships() {
Array edgesToAdd = new Array();
CgEdge e;
for (int i=0;i getNodes() {return nodes;}
public void setNodes(Array nodes) {this.nodes = nodes;}
public Array getEdges() {return edges;}
public void setEdges(Array edges) {this.edges = edges;}
public Array getPositiveAssertions() {return positiveAssertions;}
public void setPositiveAssertions(Array positiveAssertions) {this.positiveAssertions = positiveAssertions;}
public Array getNegativeAssertions() {return negativeAssertions;}
public void setNegativeAssertions(Array negativeAssertions) {this.negativeAssertions = negativeAssertions;}
}