Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a67102ee65
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 827 lines (620 sloc) 18.267 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
/*
 * 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.compiler;

import org.drools.pmml_4_1.descr.*;
import org.drools.pmml_4_1.*;
import java.util.Map;
import java.util.LinkedHashMap;




//**********************************************************************************************************
//
// VISIT RULES
//
//**********************************************************************************************************



rule "visitPMML"
salience -1
when
    $pmml : PMML(
        $header : header,
        $dataDic : dataDictionary,
        $tranDic : transformationDictionary
    )
then
   insert( $header );
   insert( $dataDic );
   insert( $tranDic );
end


rule "main_cleanup"
salience -9999
when
    $p: PMML( )
then
   retract( $p );
end



//------------------------------------------------------------------------------------------------------------//

rule "visitDataDictionary"
//after visitHeader
salience -10
when
    $dataDic : DataDictionary( $flds : dataFields )
    $fld : DataField() from $flds
then
//System.err.println("INSERT FIELD " + $fld);
   insert($fld);
end

rule "visitDataDictionary_cleanup"
//after visitHeader
salience -11
when
    $dataDic : DataDictionary( )
then
    retract( $dataDic );
end


//------------------------------------------------------------------------------------------------------------//

rule "visitTransformationDictionary"
// after visitDataDictionary
salience -20
when
    TransformationDictionary( $flds : derivedFields )
    $fld : DerivedField( ) from $flds
then
   //System.err.println("INSERT DERIVED FIELD " + $fld);
   insert( $fld );
end

rule "visitTransformationDictionary_cleanup"
// after visitDataDictionary
salience -21
when
    $tranDic : TransformationDictionary( )
then
   retract( $tranDic );
end


rule "visitLocalTransformation"
salience -15
when
    LocalTransformations( $flds : derivedFields )
    $fld : DerivedField( ) from $flds
then
   //System.err.println("INSERT DERIVED FIELD " + $fld);
   insert( $fld );
end

rule "visitLocalTransformation_cleanup"
// after visitDataDictionary
salience -21
when
    $local : LocalTransformations( )
then
   retract( $local );
end



 //------------------------------------------------------------------------------------------------------------//




rule "visitDerivedField_NormContinuous"
salience -1
when
    $fld : DerivedField( $nc : normContinuous != null )
then
    insertLogical( $nc );
end


//------------------------------------------------------------------------------------------------------------//

rule "visitDerivedField_Constant"
salience -1
when
    $fld : DerivedField( $c : constant != null )
then
    insertLogical( $c );
end

 //------------------------------------------------------------------------------------------------------------//

rule "visitDerivedField_Reference"
salience -1
when
    $fld : DerivedField( $f : fieldRef != null )
then
    insertLogical( $f );
end

//------------------------------------------------------------------------------------------------------------//

rule "visitDerivedField_NormDiscrete"
salience -1
when
    $fld : DerivedField( $nd : normDiscrete != null )
then
    insertLogical( $nd );
end

 //------------------------------------------------------------------------------------------------------------//

rule "visitDerivedField_Discretize"
salience -1
when
    $fld : DerivedField( $dx : discretize != null )
then
    insertLogical( $dx );
end


//------------------------------------------------------------------------------------------------------------//


rule "visitDerivedField_MapValues"
salience -1
when
    $fld : DerivedField( $map : mapValues != null )
then
    insertLogical( $map );
end


//------------------------------------------------------------------------------------------------------------//


rule "visitDerivedField_Aggregate"
salience -1
when
    $fld : DerivedField( $agg : aggregate != null )
then
    insertLogical( $agg );
end


//------------------------------------------------------------------------------------------------------------//


rule "visitDerivedField_Apply"
salience -1
when
    $fld : DerivedField( $app : apply != null )
then
    insertLogical( $app );
end


//------------------------------------------------------------------------------------------------------------//


rule "visitDefFunctTransform"
salience -1
when
           TransformationDictionary( $funs : defineFunctions )
    $fun : DefineFunction() from $funs
then
    insert( $fun );
end




rule "visitDefineFunction_Apply_normalize"
salience 15
no-loop
when
    $def : DefineFunction( $apply : apply != null, apply.function != "identity" )
then
    Apply idApply = new Apply();
          idApply.setFunction( "identity" );
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $apply );
    modify ( $def ) {
        setApply( idApply );
    }
end

rule "visitDefineFunction_Apply"
salience 15
when
    $def : DefineFunction( $apply : apply != null, apply.function == "identity" )
then
    insertLogical( $apply );
end

rule "visitDefineFunction_NormCont"
salience 15
no-loop
when
    $def : DefineFunction( $name : name, $nc : normContinuous != null, $fld : normContinuous.field )
then
    Apply idApply = new Apply();
          idApply.setFunction("identity");
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $nc );

    modify ( $def ) {
        setApply( idApply );
    }

    $nc.setField( $name + "_" + $fld );

    insertLogical( idApply );
end


rule "visitDefineFunction_Aggregate"
salience 15
no-loop
when
    $def : DefineFunction( $name : name, $agg : aggregate != null, $fld : aggregate.field )
then
    Apply idApply = new Apply();
         idApply.setFunction( "identity" );
         idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $agg );

    modify ( $def ) {
        setApply( idApply );
    }

    $agg.setField( $name + "_" + $fld );

    insertLogical( idApply );
end

rule "visitDefineFunction_Mapvalue"
salience 15
no-loop
when
    $def : DefineFunction( $name : name, $map : mapValues != null )
then
    Apply idApply = new Apply();
          idApply.setFunction( "identity" );
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $map );

    modify ( $def ) {
        setApply( idApply );
    }

    insertLogical( idApply );
end

rule "visitDefineFunction_Mapvalue_FixLocalFieldNames"
salience 14
no-loop
when
    $def : DefineFunction( $name : name, $map : mapValues != null, $rows : mapValues.fieldColumnPairs )
    $fcp : FieldColumnPair( $fld : field ) from $rows
then
    $fcp.setField( $name + "_" + $fld );
end



rule "visitDefineFunction_Discretize"
salience 15
no-loop
when
    $def : DefineFunction( $name : name, $dx : discretize != null, $fld : discretize.field )
then
    Apply idApply = new Apply();
          idApply.setFunction( "identity" );
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $dx );

    modify ( $def ) {
        setApply( idApply );
    }

    $dx.setField( $name + "_" + $fld );

    insertLogical( idApply );
end

rule "visitDefineFunction_NormDiscrete"
salience 15
no-loop
when
    $def : DefineFunction( $name : name, $nd : normDiscrete != null, $fld : normDiscrete.field )
then
    Apply idApply = new Apply();
          idApply.setFunction( "identity" );
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $nd );

    modify ( $def ) {
        setApply( idApply );
    }

    $nd.setField( $name + "_" + $fld );

    insertLogical( idApply );
end

rule "visitDefineFunction_FldRef"
salience 15
no-loop
when
    $def : DefineFunction( $name : name, $ref : fieldRef != null, $fld : fieldRef.field )
then
    Apply idApply = new Apply();
          idApply.setFunction( "identity" );
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $ref );

    modify ( $def ) {
        setApply( idApply );
    }

// $ref.setField( $name + "_" + $fld );

    insertLogical( idApply );
end

rule "visitDefineFunction_Const"
salience 15
no-loop
when
    $def : DefineFunction( $k : constant != null )
then
    Apply idApply = new Apply();
          idApply.setFunction( "identity" );
          idApply.getConstantsAndFieldRevesAndNormContinuouses().add( $k );

    modify ( $def ) {
        setApply( idApply );
    }

    insertLogical( idApply );
end







rule "visitApply"
salience 0
when
    Apply( $args : constantsAndFieldRevesAndNormContinuouses, $fun : this.function )
    $arg : Object() from $args
then
    insertLogical( $arg );
end





//------------------------------------------------------------------------------------------------------------//



rule "visitModels"
salience -50
when
   PMML( $modelList : associationModelsAndBaselineModelsAndClusteringModels )
   $model : Object() from $modelList
then
   insert( $model );
end



//------------------------------------------------------------------------------------------------------------//


rule "MiningSchema"
salience -7
when
    $m : MiningSchema( $fields : miningFields )
    $o : Object() from $fields
then
    insertLogical( $o );
end



//------------------------------------------------------------------------------------------------------------//



rule "Targets"
when
    Targets( $tgts : targets )
    $t : Target() from $tgts
then
    insertLogical( $t );
end



//------------------------------------------------------------------------------------------------------------//

declare OutputParentModel
    field : OutputField @key
    modelType : String
end

rule "Outputs_Neural"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    NeuralNetwork( $info : extensionsAndNeuralLayersAndNeuralInputs contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "NeuralNetwork" ) );
end

rule "Outputs_Association"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    AssociationModel( $info : extensionsAndMiningSchemasAndOutputs contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "Association" ) );
end

rule "Outputs_Clustering"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    ClusteringModel( $info : extensionsAndClustersAndComparisonMeasures contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "Clustering" ) );
end

rule "Outputs_Regression"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    RegressionModel( $info : extensionsAndRegressionTablesAndMiningSchemas contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "Regression" ) );
end


rule "Outputs_GenRegression"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    GeneralRegressionModel( $info : extensionsAndParamMatrixesAndPPMatrixes contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "GeneralRegression" ) );
end


rule "Outputs_NaiveBayes"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    NaiveBayesModel( $info : extensionsAndBayesOutputsAndBayesInputs contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "NaiveBayes" ) );
end

rule "Outputs_RuleSet"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    RuleSetModel( $info : extensionsAndRuleSetsAndMiningSchemas contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "RuleSet" ) );
end

rule "Outputs_SVM"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    SupportVectorMachineModel( $info : extensionsAndSupportVectorMachinesAndVectorDictionaries contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "SVM" ) );
end

rule "Outputs_Tree"
when
    $out : Output( $outs : outputFields )
    $of : OutputField() from $outs
    TreeModel( $info : extensionsAndNodesAndMiningSchemas contains $out )
then
    insertLogical( $of );
    insertLogical( new OutputParentModel( $of, "Tree" ) );
end










 //------------------------------------------------------------------------------------------------------------//




rule "visitNeuralNetwork"
salience -10
when
    $net : NeuralNetwork( $info : extensionsAndNeuralLayersAndNeuralInputs, $name : modelName )
    $o : Object() from $info
then
    insertLogical( $o );
end




rule "Neural_InputFields"
salience -8
when
    //NeuralNetwork( $info : extensionsAndNeuralLayersAndNeuralInputs , $nn : modelName)
    NeuralInputs( $nis : neuralInputs )
    $ni : NeuralInput( $fld : derivedField, $id : id) from $nis
then
    insertLogical( $ni );
end



rule "Neural_Layers"
salience -9
when
    //NeuralNetwork( $info : extensionsAndNeuralLayersAndNeuralInputs , $nn : modelName)
    NeuralLayer( $ns : neurons, activationFunction != null, threshold != null )
    $n : Neuron( ) from $ns
then
    insertLogical( $n );
end



rule "Neural_Outputs"
salience -9
when
    //NeuralNetwork( $info : extensionsAndNeuralLayersAndNeuralInputs , $nn : modelName)
    NeuralOutputs( $outs : neuralOutputs )
    $out : NeuralOutput() from $outs
then
    insertLogical( $out );
end



 //------------------------------------------------------------------------------------------------------------//




rule "visitTree"
salience -10
when
    $tree : TreeModel( $info : extensionsAndNodesAndMiningSchemas, $name : modelName )
    $o : Object() from $info
then
    insertLogical( $o );
end


rule "visitChildrenNodes"
salience -8
when
    $node : Node( $children : nodes )
    $child : Node() from $children
then
    insertLogical( $child );
end

rule "Visit Node Predicates"
salience -9
when
    $node : Node( $children : extensionsAndSimplePredicatesAndCompoundPredicates )
    $child : Object() from $children
then
    insertLogical( $child );
end

rule "Visit Compound Predicates"
salience -9
when
    $node : CompoundPredicate( $children : simplePredicatesAndCompoundPredicatesAndSimpleSetPredicates )
    $child : Object() from $children
then
    insertLogical( $child );
end

rule "Visit Set Predicates"
salience -9
when
    $node : SimpleSetPredicate( $arr : array )
then
    insertLogical( $arr );
end


 //------------------------------------------------------------------------------------------------------------//


rule "visitSVM"
salience -10
when
    $net : SupportVectorMachineModel( $info : extensionsAndSupportVectorMachinesAndVectorDictionaries, $name : modelName )
    $o : Object() from $info
then
    insertLogical( $o );
end


rule "visitVectorDictionary"
salience -11
when
    $vd : VectorDictionary( $info : vectorInstances, $nrvect : numberOfVectors )
    $ls : VectorInstance() from $info
then
    insertLogical( $ls );
end

rule "visitCoefficients"
salience -13
when
    $net : SupportVectorMachine( $cfs : coefficients, $svs : supportVectors )
then
    insertLogical( $cfs );
    insertLogical( $svs );
end

rule "visitCoefficient"
salience -14
when
    $coe : Coefficients( $info : coefficients )
    $ls : Coefficient() from $info
then
    insertLogical( $ls );
end

rule "visitSupportVector"
salience -15
when
    $svs : SupportVectors( $info : supportVectors )
    $sv : SupportVector() from $info
then
    insertLogical( $sv );
end


 //------------------------------------------------------------------------------------------------------------//


rule "visitRegression"
salience -11
when
    $reg : RegressionModel( $info : extensionsAndRegressionTablesAndMiningSchemas, $name : modelName )
    $o : Object() from $info
then
    insertLogical( $o );
end

rule "visitRegressionTable Numeric"
salience -11
when
    $tab : RegressionTable( $nums : numericPredictors )
    $num : NumericPredictor() from $nums
then
    insertLogical( $num );
end

rule "visitRegressionTable Categorical"
salience -11
when
    $tab : RegressionTable( $cats : categoricalPredictors )
    $cat : CategoricalPredictor() from $cats
then
    insertLogical( $cat );
end

rule "visitRegressionTable Terms"
salience -11
when
    $tab : RegressionTable( $trms : predictorTerms )
    $trm : PredictorTerm() from $trms
then
    insertLogical( $trm );
end


//------------------------------------------------------------------------------------------------------------//


rule "visitClustering"
salience -11
when
    $reg : ClusteringModel( $info : extensionsAndClustersAndComparisonMeasures, $name : modelName )
    $o : Object() from $info
then
    insertLogical( $o );
end



rule "visitClusteringComparison"
salience -11
when
    $fld : ClusteringField( $cmp : comparisons )
then
    insertLogical( $cmp );
end

rule "visitClusteringComparisonMatrixes"
when
    $cmp : Comparisons( $mat : matrix )
then
    insertLogical( $mat );
end




   /*
    protected DATATYPE dataType;
    protected String targetField;
    protected String value;


    protected RESULTFEATURE feature;

        PREDICTED_VALUE("predictedValue"),
        PREDICTED_DISPLAY_VALUE("predictedDisplayValue"),
        PROBABILITY("probability"),
        RESIDUAL("residual"),
        STANDARD_ERROR("standardError"),
        CLUSTER_ID("clusterId"),
        CLUSTER_AFFINITY("clusterAffinity"),
        ENTITY_ID("entityId"),
        ENTITY_AFFINITY("entityAffinity"),
        WARNING("warning"),
        RULE_VALUE("ruleValue");

    protected RULEFEATURE ruleFeature;

    protected String algorithm;
    protected BigInteger rank;
    protected String rankBasis;
    protected String rankOrder;
    protected String isMultiValued;
    */






Something went wrong with that request. Please try again.