示例#1
0
 public String toString(int objectsCount) {
   StringBuffer buffer = new StringBuffer(" ------- " + name + " -------\n");
   int i = 0;
   for (Rule rule : rules) {
     buffer.append("  rule ");
     buffer.append(i);
     buffer.append(":  ");
     buffer.append(rule.toString());
     //			buffer.append("supp: ");
     //			buffer.append(rule.getRelativeSupport(objectsCount));
     //			buffer.append(" (");
     //			buffer.append(rule.getAbsoluteSupport());
     //			buffer.append("/");
     //			buffer.append(objectsCount);
     //			buffer.append(")   ");
     //			buffer.append("conf: ");
     //			buffer.append(rule.getConfidence());
     buffer.append("  seqSupp: ");
     buffer.append(rule.getSequentialSupport(objectsCount));
     buffer.append(" (");
     buffer.append(rule.getAbsoluteSeqSupport());
     buffer.append("/");
     buffer.append(objectsCount);
     buffer.append("  seqConf: ");
     buffer.append(rule.getSequentialConfidence());
     buffer.append(" (");
     buffer.append(rule.getAbsoluteSupport());
     buffer.append("/");
     buffer.append(rule.getItemset1().getAbsoluteSupport());
     buffer.append("\n");
     i++;
   }
   buffer.append("--------------------------------\n");
   return buffer.toString();
 }
示例#2
0
 @Override
 public String toString() {
   if (rules == null) return "";
   StringBuilder sb = new StringBuilder();
   for (Rule rule : rules) sb.append(rule.toString()).append('\n');
   return sb.toString();
 }
示例#3
0
  /**
   * Return a string representation of the rules.
   *
   * @param databaseSize the number of transactions in the database where the rules were found.
   */
  public String toString(int databaseSize) {
    StringBuffer buffer = new StringBuffer(" ------- ");
    buffer.append(name);
    buffer.append(" -------\n");
    int i = 0;
    for (Rule rule : rules) {
      //			System.out.println("  L" + j + " ");
      buffer.append("   rule ");
      buffer.append(i);
      buffer.append(":  ");
      buffer.append(rule.toString());
      buffer.append("support :  ");
      buffer.append(rule.getRelativeSupport(databaseSize));

      buffer.append(" (");
      buffer.append(rule.getAbsoluteSupport());
      buffer.append("/");
      buffer.append(databaseSize);
      buffer.append(") ");
      buffer.append("confidence :  ");
      buffer.append(rule.getConfidence());
      buffer.append("\n");
      i++;
    }
    return buffer.toString();
  }
示例#4
0
  /**
   * Return a string representation of this list of rules
   *
   * @param databaseSize the number of transactions in the database where the rules were found.
   * @return a string
   */
  public String toString(int databaseSize) {
    // create a string buffer
    StringBuffer buffer = new StringBuffer(" ------- ");
    buffer.append(name);
    buffer.append(" -------\n");
    int i = 0;
    // for each rule
    for (Rule rule : rules) {
      // append the rule, its support and confidence.
      buffer.append("   rule ");
      buffer.append(i);
      buffer.append(":  ");
      buffer.append(rule.toString());
      buffer.append("support :  ");
      buffer.append(rule.getRelativeSupport(databaseSize));

      buffer.append(" (");
      buffer.append(rule.getAbsoluteSupport());
      buffer.append("/");
      buffer.append(databaseSize);
      buffer.append(") ");
      buffer.append("confidence :  ");
      buffer.append(rule.getConfidence());
      buffer.append("\n");
      i++;
    }
    return buffer.toString(); // return the string
  }
示例#5
0
    protected void toStringRules(
        int level, StringBuilder builder, HashMap<String, Rule> rules, String title) {
      builder.append(title);
      builder.append(String.format(" :%n"));

      for (Rule rule : rules.values()) builder.append(rule.toString(level + 1));
    }
示例#6
0
  public void classifyLemma(
      String lemma, String lemmaPoS, String tag, boolean checkPoS, FoundFormHandler theCallback) {
    if (tag == null) {
      nl.openconvert.log.ConverterLog.defaultLog.println("HEY: tag = null for " + lemma);
    }
    if (!tag.startsWith(lemmaPoS)) {
      return; // doe dit anders!
    }
    Classifier classifier = classifiersPerTag.get(tag);
    if (classifier == null) {
      nl.openconvert.log.ConverterLog.defaultLog.println("Error: no classifier trained for " + tag);
      return;
    }

    Instance testItem = features.makeTestInstance(lemma);

    Distribution outcomes = classifier.distributionForInstance(testItem);
    // nl.openconvert.log.ConverterLog.defaultLog.println(outcomes);
    outcomes.sort();
    double cumulativeP = 0;

    for (int rank = 0; rank < outcomes.size(); rank++) {
      // Problem: the pattern suggested by the classifier need not be applicable to the given lemma
      // TODO: solve this by using a different classifier (or pruning the decision trees)

      String classId = outcomes.get(rank).label;
      double p = outcomes.get(rank).p;
      Rule r = ruleID2Rule.get(classId);
      LemmaLog.addToLog("rule for " + lemma + ":  " + r.toString());
      cumulativeP += p;
      // nl.openconvert.log.ConverterLog.defaultLog.println(r + " " + lemmaPoS + " "  + r.lemmaPoS);
      if (p > cumulativeP / MIN_PROBABILITY && (!checkPoS || r.lemmaPoS.equals(lemmaPoS))) {
        if (theCallback != null) {
          theCallback.foundForm(lemma, tag, lemmaPoS, r, p, rank);
        } else {
          String wf = r.pattern.applyConverse(lemma);
          if (wf != null) {
            System.out.println(
                String.format(
                    "%s\t%s\t%s\t%s\t%f\t[%d]\t%s=%s",
                    wf, lemma, tag, lemmaPoS, p, rank, classId, r.toString()));
          }
        }
      }
    }
  }
示例#7
0
 @Override
 public String toString() {
   StringBuilder b = new StringBuilder();
   for (Rule rule : rules) {
     b.append(rule.toString());
     b.append("\n");
   }
   return b.toString();
 }
 @Ignore
 @Test
 public void testToString() {
   System.out.println("toString");
   Rule instance = null;
   String expResult = "";
   String result = instance.toString();
   assertEquals(expResult, result);
   fail("The test case is a prototype.");
 }
示例#9
0
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();

    builder.append("StyleSheet : {\n");
    builder.append("  default styles:\n");
    builder.append(defaultRule.toString(1));
    builder.append(graphRules.toString(1));
    builder.append(nodeRules.toString(1));
    builder.append(edgeRules.toString(1));
    builder.append(spriteRules.toString(1));

    return builder.toString();
  }
示例#10
0
  public String toString() {
    String output = "";
    Iterator keys = rules.keySet().iterator();

    while (keys.hasNext()) {
      String key = (String) keys.next();
      ListIterator li = getRules(key);

      while (li.hasNext()) {
        Rule rule = (Rule) li.next();
        output += "\nKEY: " + key + " RULE: " + rule.toString();
      }
    }

    return output;
  }
示例#11
0
    public String toString(int level) {
      String prefix = "";

      if (level > 0) {
        for (int i = 0; i < level; i++) prefix += "    ";
      }

      StringBuilder builder = new StringBuilder();

      builder.append(String.format("%s%s default style :%n", prefix, type));
      builder.append(defaultRule.toString(level + 1));
      toStringRules(level, builder, byId, String.format("%s%s id styles", prefix, type));
      toStringRules(level, builder, byClass, String.format("%s%s class styles", prefix, type));

      return builder.toString();
    }
示例#12
0
 /**
  * Print the rules to System.out
  *
  * @param databaseSize the number of transactions in the database where the rules were found.
  */
 public void printRules(int databaseSize) {
   System.out.println(" ------- " + name + " -------");
   int i = 0;
   for (Rule rule : rules) {
     System.out.print("  rule " + i + ":  " + rule.toString());
     System.out.print(
         "support :  "
             + rule.getRelativeSupport(databaseSize)
             + " ("
             + rule.getAbsoluteSupport()
             + "/"
             + databaseSize
             + ") ");
     System.out.print("confidence :  " + rule.getConfidence());
     System.out.println("");
     i++;
   }
   System.out.println(" --------------------------------");
 }
示例#13
0
 /**
  * Print all the rules in this list to System.out, and include information about the lift measure.
  *
  * @param databaseSize the number of transactions in the transaction database where the rules were
  *     found
  */
 public void printRulesWithLift(int objectsCount) {
   System.out.println(" ------- " + name + " -------");
   int i = 0;
   for (Rule rule : rules) {
     System.out.print("  rule " + i + ":  " + rule.toString());
     System.out.print(
         "support :  "
             + rule.getRelativeSupport(objectsCount)
             + " ("
             + rule.getAbsoluteSupport()
             + "/"
             + objectsCount
             + ") ");
     System.out.print("confidence :  " + rule.getConfidence());
     System.out.print(" lift :  " + rule.getLift());
     System.out.println("");
     i++;
   }
   System.out.println(" --------------------------------");
 }
示例#14
0
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, String> ns : getNamespaces().entrySet()) {
      builder.append("@prefix ");
      builder.append(ns.getKey());
      builder.append(": <");
      builder.append(ns.getValue());
      builder.append(">\n");
    }
    if (getNamespaces().size() > 0) {
      builder.append("\n");
    }

    for (Rule rule : getRules()) {
      builder.append(rule.toString(getNamespaces()));
      builder.append("\n");
    }
    return builder.toString();
  }
示例#15
0
 @Override
 public String toString() {
   return ruleDefinition.toString();
 }
示例#16
0
  /**
   * Looked at the solution. Basically you can never have a straight that encompasses another, so
   * use a greedy strategy to add the card to the shortest straight.
   */
  public String handleCase(InputData in) {

    List<Rule> rules = Lists.newArrayList();

    String numBinary = Integer.toBinaryString(in.N);
    int writeNumberStateBase = 100;
    int subtractStateBase = 200;

    int leftBoundaryMark = 4;
    int rightBoundaryMark = 5;

    rules.add(new Rule(0, 0, 'E', writeNumberStateBase + 0, leftBoundaryMark));

    // write the number in binary, 3 means 2 ; 2 means 1
    for (int c = 0; c < numBinary.length(); ++c) {
      char ch = numBinary.charAt(c);
      rules.add(
          new Rule(
              writeNumberStateBase + c, 0, 'E', writeNumberStateBase + c + 1, ch == '1' ? 3 : 2));
    }

    // Write right boundary ; go into subtraction mode
    rules.add(
        new Rule(
            writeNumberStateBase + numBinary.length(),
            0,
            'W',
            subtractStateBase,
            rightBoundaryMark));

    // Subtraction--
    // S0 --> need to subtract 1
    // S1 --> done subtracting

    rules.add(new Rule(subtractStateBase, 3, 'W', subtractStateBase + 1, 2));
    rules.add(new Rule(subtractStateBase, 2, 'W', subtractStateBase, 3));

    rules.add(new Rule(subtractStateBase + 1, 3, 'W', subtractStateBase + 1, 3));
    rules.add(new Rule(subtractStateBase + 1, 2, 'W', subtractStateBase + 1, 2));

    rules.add(new Rule(subtractStateBase, 4, 'R', 0, 0));

    int copyPhaseBase = 300;

    // Done subtracting, hit left boundary
    rules.add(new Rule(subtractStateBase + 1, 4, 'E', copyPhaseBase, 7));

    /*
    Copy phase 0 -- start copy
    copy phase 1 -- copy 2 to right
    copy phase 2 -- copy 3 to right
    copy phase 3 -- done copy
    */

    // Start copying
    rules.add(new Rule(copyPhaseBase, 3, 'E', copyPhaseBase + 2, leftBoundaryMark));
    rules.add(new Rule(copyPhaseBase, 2, 'E', copyPhaseBase + 1, leftBoundaryMark));

    // Copy
    rules.add(new Rule(copyPhaseBase + 1, 3, 'E', copyPhaseBase + 2, 2));
    rules.add(new Rule(copyPhaseBase + 1, 2, 'E', copyPhaseBase + 1, 2));

    rules.add(new Rule(copyPhaseBase + 2, 3, 'E', copyPhaseBase + 2, 3));
    rules.add(new Rule(copyPhaseBase + 2, 2, 'E', copyPhaseBase + 1, 3));

    // Hit right boundary
    rules.add(new Rule(copyPhaseBase + 1, rightBoundaryMark, 'E', copyPhaseBase + 3, 2));
    rules.add(new Rule(copyPhaseBase + 2, rightBoundaryMark, 'E', copyPhaseBase + 3, 3));

    // Write right boundary and start subtraction
    rules.add(new Rule(copyPhaseBase + 3, 0, 'W', subtractStateBase, rightBoundaryMark));

    StringBuffer ruleText = new StringBuffer();

    ruleText.append(rules.size());
    ruleText.append("\n");

    for (Rule rule : rules) {
      // log.debug("Rule: {}", rule);
      ruleText.append(rule.toString());
      ruleText.append("\n");
    }

    try {
      /*
      String text =
              IOUtils.toString(this.getClass().getResourceAsStream(
                      "/codejam/y2011/rules1.txt"));
                      */
      String text = ruleText.toString();

      log.debug(text);

      Simulator s = Simulator.fromStr(text);
      s.printStateLimit = 20;

      Integer finalLoc = s.go();

      Preconditions.checkState(finalLoc.equals(in.N));

      log.debug("Final state {}", finalLoc);

    } catch (Exception ex) {
      log.debug("ex", ex);
    }
    ruleText.deleteCharAt(ruleText.length() - 1);
    return String.format("Case #%d: ", in.testCase) + ruleText.toString();
  }