Added maxActiveConcepts property in ComprehensionModel

parent 916b7ed6
......@@ -26,16 +26,18 @@ import com.readerbench.coreservices.semanticmodels.SemanticModel;
public class ComprehensionModel {
private final double minActivationScore;
private final int maxActiveConcepts;
private final int maxDictionaryExpansion;
private final ActivationScoreLogger activationScoreLogger;
private final CMIndexer cmIndexer;
private CMGraphDO currentGraph;
public ComprehensionModel(String text, SemanticModel semModel, double minActivationScore, int maxDictionaryExpansion) {
public ComprehensionModel(String text, SemanticModel semModel, double minActivationScore, int maxActiveConcepts, int maxDictionaryExpansion) {
this.cmIndexer = new CMIndexer(text, semModel);
this.currentGraph = new CMGraphDO();
this.minActivationScore = minActivationScore;
this.maxActiveConcepts = maxActiveConcepts;
this.maxDictionaryExpansion = maxDictionaryExpansion;
this.activationScoreLogger = new ActivationScoreLogger();
}
......@@ -65,6 +67,7 @@ public class ComprehensionModel {
pageRank.runPageRank(this.currentGraph);
this.normalizeActivationScoreMapWithMax();
this.activateWordsOverThreshold();
this.currentGraph.restrictActiveNodes(maxActiveConcepts);
this.activationScoreLogger.saveScores(this.currentGraph.getActivationMap());
}
......
......@@ -101,6 +101,19 @@ public class CMGraphDO {
}
}
}
public void restrictActiveNodes(int maxActiveConcepts) {
Collections.sort(this.nodeList, (n1, n2) -> (-1) * new Double(n1.getActivationScore()).compareTo(n2.getActivationScore()));
for(int i = 0; i < this.nodeList.size(); i++) {
CMNodeDO node = this.nodeList.get(i);
if(node.isActive() && i >= maxActiveConcepts) {
node.deactivate();
this.getEdgeList(node).stream().forEach(edge -> {
edge.deactivate();
});
}
}
}
private boolean containsEdge(CMEdgeDO otherEdge) {
return edgeListContainsEdge(this.edgeList, otherEdge);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment