Permalink
Browse files

PMML : Upgrade and fix custom function processing (in progress)

  • Loading branch information...
1 parent f7a244e commit fd95a7d086eb63af32ab292b44cc0cadeb3569a6 @sotty sotty committed Sep 24, 2012
Oops, something went wrong.
Oops, something went wrong.
@@ -236,93 +236,109 @@ no-loop
when
$def : DefineFunction( $apply : apply != null, apply.function != "identity" )
then
+ System.out.println( "PROCESSED DEFFN WITH APPLY " + $def.getName() );
Apply idApply = new Apply();
idApply.setFunction( "identity" );
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $apply );
modify ( $def ) {
setApply( idApply );
}
+
+ insertLogical( idApply );
end
rule "visitDefineFunction_NormCont"
salience 15
no-loop
when
- $def : DefineFunction( $nc : normContinuous != null )
+ $def : DefineFunction( $name : name, $nc : normContinuous != null, $fld : normContinuous.field )
then
Apply idApply = new Apply();
idApply.setFunction("identity");
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $nc );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+
+ $nc.setField( $name + "_" + $fld );
+
+ insertLogical( idApply );
end
rule "visitDefineFunction_Aggregate"
salience 15
no-loop
when
- $def : DefineFunction( $agg : aggregate != null )
+ $def : DefineFunction( $name : name, $agg : aggregate != null, $fld : aggregate.field )
then
Apply idApply = new Apply();
idApply.setFunction( "identity" );
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $agg );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+
+ $agg.setField( $name + "_" + $fld );
+
+ insertLogical( idApply );
end
rule "visitDefineFunction_Mapvalue"
salience 15
no-loop
when
- $def : DefineFunction( $map : mapValues != null )
+ $def : DefineFunction( $name : name, $map : mapValues != null )
then
Apply idApply = new Apply();
idApply.setFunction( "identity" );
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $map );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+
+ insertLogical( idApply );
end
rule "visitDefineFunction_Discretize"
salience 15
no-loop
when
- $def : DefineFunction( $dx : discretize != null )
+ $def : DefineFunction( $name : name, $dx : discretize != null, $fld : discretize.field )
then
Apply idApply = new Apply();
idApply.setFunction( "identity" );
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $dx );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+
+ $dx.setField( $name + "_" + $fld );
+
+ insertLogical( idApply );
end
rule "visitDefineFunction_NormDiscrete"
salience 15
no-loop
when
- $def : DefineFunction( $nd : normDiscrete != null )
+ $def : DefineFunction( $name : name, $nd : normDiscrete != null, $fld : normDiscrete.field )
then
Apply idApply = new Apply();
idApply.setFunction( "identity" );
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $nd );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+ System.out.println( "Adepted ND to work on fiel " + $name + "_" + $fld );
+ $nd.setField( $name + "_" + $fld );
+
+ insertLogical( idApply );
end
rule "visitDefineFunction_FldRef"
@@ -336,9 +352,9 @@ then
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $ref );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+ insertLogical( idApply );
end
rule "visitDefineFunction_Const"
@@ -347,28 +363,30 @@ no-loop
when
$def : DefineFunction( $k : constant != null )
then
+ System.out.println("Rwrtite def fun with const to use apply internall");
Apply idApply = new Apply();
idApply.setFunction( "identity" );
idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $k );
modify ( $def ) {
- setNormContinuous( null ),
setApply( idApply );
}
+ insertLogical( idApply );
end
+
rule "visitApply"
salience 0
when
Apply( $args : constantsAndFieldRevesAndNormContinuouses, $fun : this.function )
$arg : Object() from $args
then
- insertLogical( $arg );
+ insertLogical( $arg );
end
@@ -34,20 +34,20 @@
rule "aggr_@{name}"
when
@if{groupBy != null} @{groupBy}( valid == true, missing == false, $gval : value ) @end{}
- $agg : @{box(dataType)}() from accumulate (
+ $agg : Number() from accumulate (
@{afield}( valid == true, missing == false,
@if{ context != null } context == @{context}, @end{}
$v : value @if{groupBy != null && constr != null} @{constr} $gval @end{} ),
@{aggrFunc}( $v )
)
then
@{name} x = new @{name}();
- x.setValue($agg);
- x.setMissing(false);
- x.setValid(true);
- x.setName(@{format("string",name)});
- x.setContext(@{context});
- insertLogical(x);
+ x.setValue( @{ numberFromNumber( "$agg", dataType ) } );
+ x.setMissing( false );
+ x.setValid( true );
+ x.setName( @{ format( "string", name ) } );
+ x.setContext( @{ context } );
+ insertLogical( x );
end
@end{}
@@ -38,12 +38,12 @@ when
@if{groupBy != null && constr != null} , value @{constr} $gval @end{} )
)
then
- @{name} x = new @{name}();
- x.setValue($agg);
- x.setMissing(false);
- x.setValid(true);
- x.setName(@{format("string",name)});
- insertLogical(x);
+ @{ name } x = new @{ name }();
+ x.setValue( $agg );
+ x.setMissing( false );
+ x.setValid( true );
+ x.setName( @{ format( "string", name ) } );
+ insertLogical( x );
end
@end{}
@@ -32,14 +32,24 @@
@declare{ 'applyRule' }
rule "fun_@{name}"
when
- @code{ keys = exprFieldList.keySet() }
- @foreach{ field : keys }
- @{ field }( valid == true, missing == false, @{ exprFieldList.get( field ) } : value
+ @foreach{ field : exprFieldList }
+ @{ field }( valid == true, missing == false, @{ exprFieldMap.get( field ) } : value
@if{ context != null } , context == @{ format( "string", context ) } @end{} )
@end{}
+ // @{funName} - @{ isBuiltIn( funName ) }
+ @if{ ! isBuiltIn( funName ) }
+ @{ funName }( @foreach{ arg : funArgs } @{arg} @end{ ',' } , $return ; )
+ @end{}
then
+ System.out.println( "READY TO BUILD @{name} ");
@{name} x = new @{ name }();
- x.setValue( ( @{ dataType } ) @{ funExpr } );
+
+ @if{ isBuiltIn( funName ) }
+ x.setValue( ( @{ dataType } ) @{ mapFunction( funName, funArgs ) } );
+ @else{}
+ x.setValue( ( @{ dataType } ) $return );
+ @end{}
+
x.setMissing( false );
x.setValid( true );
x.setName( @{ format( "string", name ) } );
@@ -29,9 +29,34 @@
}
@declare{'customFunction'}
-function @{dataType} @{name}( @foreach{ param : params} @{mapDatatype(param.dataType)} @{exprFieldList.get(param.name)} @end{','}) {
- return @{funExpr};
-}
+
+query "@{name}"( @foreach{ param : params } @{ mapDatatype( param.dataType ) } @{ param.name } @end{','} , @{ mapDatatype( dataType, true ) } $return )
+ @foreach{ field : innerFields }
+ @{ field }( valid == true, missing == false, @{ exprFieldMap.get( field ) } : value
+ @if{ context != null } , context == @{ format( "string", context ) } @end{} )
+ @end{}
+ $return := @{ mapDatatype( dataType, true ) }() from @{ expr }
+end
+
+rule "@{name}_Goal"
+@code{ int j = 0; }
+when
+ $q : org.drools.base.DroolsQuery( name == "@{name}", @foreach{ param : params } @{ param.name } : elements[@{j++}] @end{ ', ' } )
+then
+
+ @foreach{ param : params }
+ @code{ String pn = compactUpperCase( name ) + "_" + compactUpperCase( param.name ); }
+ @{ pn } _@{pn} = new @{pn}( (@{ mapDatatype( param.dataType, true ) }) @{ param.name }, "@{ name }" );
+ _@{pn}.setValid( true );
+ System.out.println("QUERY @{name} SIED EFFECT GETS " + _@{pn});
+ insertLogical( _@{pn} );
+ @end{}
+
+
+end
+
+
+
@end{}
@includeNamed{'customFunction'}
@@ -25,7 +25,7 @@
public class FunctionsWithNestedTest extends DroolsAbstractPMMLTest {
- private static final boolean VERBOSE = false;
+ private static final boolean VERBOSE = true;
private static final String source = "org/drools/pmml_4_1/test_functions_nested_transformation.xml";
private static final String packageName = "org.drools.pmml_4_1.test";
@@ -1,58 +0,0 @@
-/*
- * Copyright 2011 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.pmml_4_1.transformations;
-
-
-import org.drools.pmml_4_1.DroolsAbstractPMMLTest;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-
-
-public class UserDefinedFunctions2Test extends DroolsAbstractPMMLTest {
-
- private static final boolean VERBOSE = false;
- private static final String source = "org/drools/pmml_4_1/test_user_functions2.xml";
- private static final String packageName = "org.drools.pmml_4_1.test";
-
-
-
- @Before
- public void init() throws Exception {
-
- setKSession(getModelSession(source, VERBOSE));
- setKbase(getKSession().getKnowledgeBase());
- }
-
-
-
- @Test
- @Ignore
- public void functions() throws Exception {
- getKSession().getWorkingMemoryEntryPoint("in_Age").insert(10);
-
- getKSession().fireAllRules();
- checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName, "UserAge"), true, false, null, 6270.0 );
-
- }
-
-
-
-
-
-}
Oops, something went wrong.

0 comments on commit fd95a7d

Please sign in to comment.