Esempio n. 1
0
  public static void run(String demo) {

    TraitFactory.reset();

    StatefulKnowledgeSession kSession = getSession(demo);

    kSession.fireAllRules();

    Collection c = kSession.getObjects();
    System.out.println("------------------------- " + c.size() + " ----------------------");
    for (Object o : c) {
      System.out.println(" \t --- " + o);
    }
    System.out.println("-----------------------------------------------------------------");

    kSession.dispose();
  }
  @Override
  public void initializeDriver() {
    System.out.println("\ninitializeDriver");

    drl =
        "package opencds.test;\n"
            + "\n"
            + "import org.opencds.vmr.v1_0.internal.*;\n"
            + "import org.opencds.vmr.v1_0.internal.concepts.*;\n"
            + "import org.opencds.vmr.v1_0.internal.datatypes.*;\n"
            + "import org.drools.factmodel.traits.Traitable;\n"
            +
            //                "import org.drools.factmodel.traits.Thing;\n" +
            "import java.util.*;\n"
            + "\n"
            + "declare ObservationResult2\n"
            + "@Traitable\n"
            + "@propertyReactive\n"
            + "   id : String \n"
            + "   observationFocus : CD \n "
            + "   subjectIsFocalPerson : boolean \n"
            + "   observationValue : ObservationValue \n"
            + ""
            + "end\n"
            + ""
            + ""
            + "declare trait opencdsConcept\n"
            + "@propertyReactive\n"
            + "    openCdsConceptCode : String\n"
            + "    id : String\n"
            + "end\n"
            + ""
            + "";

    String trait = "";
    for (int i = 0; i <= maxStep; i++) {

      trait +=
          ""
              + "declare trait "
              + "autoTrait001"
              + i
              + "  extends opencdsConcept\n"
              + "@propertyReactive\n"
              + "    openCdsConceptCode : String = \"C001"
              + i
              + "\"\n"
              + "end\n"
              + "declare trait "
              + "autoTrait002"
              + i
              + "  extends opencdsConcept\n"
              + "@propertyReactive\n"
              + "    openCdsConceptCode : String = \"C002"
              + i
              + "\"\n"
              + "end\n";
    }

    String rule = "";

    for (int i = 0; i < maxStep; i++) {

      rule +=
          "rule \"ObservationFocusConcept by concept 001"
              + i
              + "\"\n"
              + "no-loop\n"
              + "when\n"
              + "    $obs : ObservationResult2(  $id : id==\"001"
              + i
              + "\" , "
              + "    $code : observationFocus.code == \"10220\",\n"
              + "        $codeSystem : observationFocus.codeSystem )\n"
              + "then\n"
              + "    //System.out.println( \"Claxified \" + $id + \" as auto Trait1 \" + "
              + i
              + " ); \n"
              + "    Object x1 = don( $obs, autoTrait001"
              + i
              + ".class );\n"
              + "    //insert(new CD()); \n"
              + "end\n"
              + "rule \"ObservationFocusConcept by concept 002"
              + i
              + "\"\n"
              + "no-loop\n"
              + "when\n"
              + "    $obs : ObservationResult2(  $id : id==\"001"
              + (i)
              + "\" , "
              + "$code : observationValue.concept.code == \"34254\",\n"
              + "        $codeSystem : observationFocus.codeSystem )\n"
              + "then\n"
              + "    //System.out.println( \"Claxified \" + $id + \" as auto Trait2 \" + "
              + i
              + " ); \n"
              + "    Object x1 = don( $obs, autoTrait002"
              + (i)
              + ".class );\n"
              + "    //insert(new CD()); \n"
              + "end\n";

      rule +=
          "rule \"IsReportableInfluenza001"
              + i
              + "\"\n"
              + "no-loop\n"
              + "when\n"
              +
              //                            "    $obj : autoTrait001"+i+"($obj2 : this isA
              // autoTrait002"+(i)+".class, $obj3 : getCore())\n" +
              "    $obj : autoTrait001"
              + i
              + "( this isA autoTrait002"
              + (i)
              + ".class )\n"
              + "then\n"
              + "    //System.out.println(\":: InfluenzaTestForOrganism ResultPositive \"+$obj.getId());\n"
              + "//System.out.println($obj.getId());\n"
              + " //retract($obj3);\n"
              + "end\n";

      /// Thing ( this isA autoTrait002 && isA autoTrait001 )

    }

    //        rule += "rule \"Clean\"\n" +
    //                "salience -999"+
    //                "when\n" +
    //                "  $s : String()\n" +
    //                "  $o : Object( this != $s )\n" +
    //                "then\n" +
    //                "  if ( ! $o.getClass().getName().contains( \"Initial\" ) ) { \n" +
    //                "   retract( $o );\n" +
    //                "  } \n" +
    //                "  //System.out.println(\"removed\");\n"+
    //                "end  ";

    drl += trait + rule;

    ksession = loadKnowledgeBaseFromString(drl).newStatefulKnowledgeSession();
    TraitFactory.setMode(TraitFactory.VirtualPropertyMode.MAP, ksession.getKnowledgeBase());
    ksession.fireAllRules();
    ksession.getAgenda().clear();
  }
  @Override
  public void initializeDriver() {
    WC = Integer.parseInt(getParam("japex.warmupIterations"));
    warmups = new double[TN][WC];
    System.out.println("\ninitializeDriver");

    drl =
        "package opencds.test;\n"
            + "\n"
            + "import java.util.*;\n"
            + "\n"
            + "declare InputObject\n"
            + "   id : String \n"
            + "end\n"
            + "\n";
    for (int i = 0; i < maxStep; i++) {
      drl += "declare JoinC00" + i + "\n" + "   hook :  InputObject\n" + "end\n" + "\n" + "";
    }

    String rule = "";
    for (int i = 0; i < maxStep; i++) {

      rule +=
          "rule \"Initiate Joins"
              + i
              + " \"\n"
              + "no-loop\n"
              + "when\n"
              + "    $obj : InputObject( $id : id == \"00A001\" )\n"
              + "then\n"
              + "    JoinC00"
              + i
              + " join"
              + i
              + " = new JoinC00"
              + i
              + "($obj);\n"
              + "    insert( join"
              + i
              + " );\n"
              + "end\n";
    }

    rule +=
        "rule \"Highly Join Check\"\n"
            + "no-loop\n"
            + "when\n"
            + "    $obj : InputObject( $id : id == \"00A001\" )\n"
            + "";
    for (int i = 0; i < maxStep; i++) {

      rule += "    JoinC00" + i + "( hook == $obj )\n";
    }

    rule +=
        "then\n"
            +
            //                "   System.out.println(\">>>fired\");" +
            "end\n";
    drl += rule;

    //        System.out.println(drl);

    ksession = loadKnowledgeBaseFromString(drl).newStatefulKnowledgeSession();
    TraitFactory.setMode(TraitFactory.VirtualPropertyMode.MAP, ksession.getKnowledgeBase());
    ksession.fireAllRules();
    ksession.getAgenda().clear();
  }