Permalink
Browse files

Shapes : CWA, RL-based classifier (WIP)

  • Loading branch information...
1 parent 0ed18a1 commit 991b5110a09787a4942610856a6a71bd623807e1 @sotty sotty committed May 12, 2013
@@ -38,6 +38,12 @@
protected static final String[] NAMED_TEMPLATES_TRAITS = new String[] {
"model/drl/trait.drlt"
};
+
+ protected static final String[] NAMED_TEMPLATES_RULES = new String[] {
+ "model/drl/recognitionRule.drlt"
+ };
+
+
protected static final String[] NAMED_TEMPLATES_JAVA = new String[] {
"model/java/TraitInterface.template",
"model/java/IndividualFactory.template",
@@ -73,17 +79,20 @@
public static TemplateRegistry traitRegistry;
+ public static TemplateRegistry ruleRegistry;
public static TemplateRegistry javaRegistry;
public static TemplateRegistry accessorsRegistry;
static {
traitRegistry = new SimpleTemplateRegistry();
+ ruleRegistry = new SimpleTemplateRegistry();
javaRegistry = new SimpleTemplateRegistry();
accessorsRegistry = new SimpleTemplateRegistry();
buildRegistry( traitRegistry, NAMED_TEMPLATES_TRAITS );
+ buildRegistry( ruleRegistry, NAMED_TEMPLATES_RULES );
buildRegistry( javaRegistry, NAMED_TEMPLATES_JAVA );
buildRegistry( accessorsRegistry, ACCESSOR_TEMPLATES_JAVA );
}
@@ -94,6 +103,7 @@ public static TemplateRegistry getDataModelRegistry( ModelFactory.CompileTarget
case XSDX : return accessorsRegistry;
case JAVA : return javaRegistry;
case DRL : return traitRegistry;
+ case RL : return ruleRegistry;
default : return traitRegistry;
}
}
@@ -20,7 +20,7 @@
public enum CompileTarget {
- BASE, JAVA, DRL, JAR, GRAPH, XSD, XSDX, WORKSET;
+ BASE, JAVA, DRL, RL, JAR, GRAPH, XSD, XSDX, WORKSET;
}
@@ -0,0 +1,126 @@
+package org.drools.semantics.builder.reasoner;
+
+import org.drools.lang.api.CEDescrBuilder;
+import org.drools.lang.api.PatternDescrBuilder;
+import org.drools.lang.descr.AnnotatedBaseDescr;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+
+
+public class DLRecognitionBuildContext {
+
+ private int counter = 0;
+ private Stack<BuildStep> vars = new Stack<BuildStep>();
+ private String source;
+
+ public DLRecognitionBuildContext() {
+ push();
+ }
+
+ public void push() {
+ vars.push( new BuildStep( "$x_" + counter++ ) );
+ }
+
+ public void pop() {
+ vars.pop();
+ }
+
+ public String getScopedIdentifier() {
+ return vars.peek().getVar();
+ }
+
+ public BuildStep getScopedContext() {
+ return vars.peek();
+ }
+
+ public boolean isPropertyBound( String propKey ) {
+ return vars.peek().isPropertyBound( propKey );
+ }
+
+ public String bindProperty( String prop ) {
+ return vars.peek().bindProperty( prop );
+ }
+
+ public String getPropertyKey( String prop ) {
+ return vars.peek().getPropertyKey( prop );
+ }
+
+ public void clearBindings() {
+ vars.peek().clearBindings();
+ }
+
+ public String peekParent() {
+ BuildStep temp = vars.pop();
+ BuildStep parent = vars.size() > 0 ? vars.peek() : null;
+ vars.push( temp );
+ return parent != null ? parent.getVar() : null;
+ }
+
+ public void setSource( String source ) {
+ this.source = source;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void resetSource() {
+ source = null;
+ }
+
+
+
+ public static class BuildStep {
+ private String var;
+ private Map<String,PatternDescrBuilder<? extends CEDescrBuilder<? extends CEDescrBuilder, ? extends AnnotatedBaseDescr>>> patterns;
+ private Map<String,String> propertyVars = new HashMap<String,String>();
+
+ private BuildStep( String var ) {
+ this.var = var;
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+ public void addPattern( String type, PatternDescrBuilder<? extends CEDescrBuilder<? extends CEDescrBuilder, ? extends AnnotatedBaseDescr>> builder ) {
+ patterns.put( type, builder );
+ }
+
+ public PatternDescrBuilder<? extends CEDescrBuilder<? extends CEDescrBuilder, ? extends AnnotatedBaseDescr>> getBuilder( String type ) {
+ return patterns.get( type );
+ }
+
+ public boolean hasBuilder( String key ) {
+ return patterns.containsKey( key );
+ }
+
+ public String bindProperty( String property ) {
+ String propKey = getPropertyKey( property );
+ if ( ! propertyVars.containsKey( propKey) ) {
+ propertyVars.put( propKey, property );
+ }
+ return propKey;
+ }
+
+ public boolean isPropertyBound( String propKey ) {
+ return propertyVars.containsKey( propKey );
+ }
+
+ public String getPropertyKey( String prop ) {
+ return var + "_" + prop;
+ }
+
+ public void clearBindings() {
+ propertyVars.clear();
+ }
+
+
+
+ }
+}
+
+
Oops, something went wrong.

0 comments on commit 991b511

Please sign in to comment.