Skip to content

Commit

Permalink
Added activation condition
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Nov 14, 2021
1 parent 5225310 commit 2ac12bb
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import com.sun.codemodel.JBlock;
import com.sun.codemodel.JExpr;
Expand Down Expand Up @@ -125,6 +126,23 @@ public TreeModelBoosterTranslator(PMML pmml, MiningModel miningModel){
throw new UnsupportedAttributeException(treeModel, missingValueStrategy);
}
}

AtomicInteger nodeCount = new AtomicInteger(0);

Visitor nodeCounter = new AbstractVisitor(){

@Override
public VisitorAction visit(Node node){
nodeCount.incrementAndGet();

return super.visit(node);
}
};
nodeCounter.applyTo(segmentation);

if(nodeCount.get() > TreeModelBoosterTranslator.NODE_COUNT_LIMIT){
throw new UnsupportedElementException(segmentation);
}
}

@Override
Expand Down Expand Up @@ -387,4 +405,6 @@ private void addNode(Node node){

return treeModel;
}

public static final int NODE_COUNT_LIMIT = Integer.getInteger(TreeModelBoosterTranslator.class.getName() + "#" + "NODE_COUNT_LIMIT", 1000);
}

0 comments on commit 2ac12bb

Please sign in to comment.