Beispiel #1
0
 @Override
 public Node toNode() {
   Node node = new Node("sequence:");
   for (Event event : events) {
     node.add(event.toNode());
   }
   return node;
 }
 @Override
 public Node toNode() {
   Node node = new Node("indicator:");
   if (indicator != null) {
     node.add(indicator.toString());
   }
   addAlignment(node);
   return node;
 }
Beispiel #3
0
  private void findRules(Node node) {

    // Terminal?
    if (!isPhrase(node)) {
      return;
    }

    // Rule.
    ProductionRule rule = new ProductionRule(node.tag);
    Node ellipsis = null;
    Node first = null;
    for (Node child : node.children) {
      if (!child.tag.equals("id:") && !child.tag.equals("reference-id:")) {
        if (first == null) {
          first = child;
        }
        if (!isPhrase(child) && child.getChild("token:") == null) {
          rule.add("*" + child.tag);
          if (ellipsis != null) {
            throw new CoreException("Multiple ellipsis.");
          }
          ellipsis = child;
        } else {
          rule.add(child.tag);
        }
      }
    }

    // Context.
    if (ellipsis != null) {
      int i = leaves.indexOf(ellipsis);
      if (i < 0) {
        throw new CoreException("Leaf mismatch: " + first);
      }

      String before = leaves.get(i - 1).tag;
      String after = i + 1 < leaves.size() ? leaves.get(i + 1).tag : null;
      addEllipsis(before, ellipsis.tag, after);
    }

    // Add.
    String key = rule.toString();
    ProductionRule existingRule = productionRuleMap.get(key);
    if (existingRule != null) {
      existingRule.count++;
    } else {
      rule.count = 1;
      productionRuleMap.put(key, rule);
    }

    // Recurse.
    for (Node child : node.children) {
      findRules(child);
    }
  }
  public static IndicatorAttribute fromNode(Node node) {

    if (!node.hasTag("indicator:")) {
      throw new CoreException("Expected 'indicator:' not '" + node.tag + "'.");
    }

    Indicator indicator = Indicator.valueOf(node.getSingleLeaf());
    int[] tokens = getTokens(node);
    return tokens != null
        ? new IndicatorAttribute(indicator, tokens[0], tokens[1])
        : new IndicatorAttribute(indicator);
  }
Beispiel #5
0
  public static Sequence fromNode(Node node) {

    if (!node.hasTag("sequence:")) {
      throw new CoreException("Expected 'sequence:' not '" + node.tag + "'.");
    }

    Sequence sequence = new Sequence();
    for (Node child : node.children) {
      sequence.events.add(Event.fromNode(child));
    }
    return sequence;
  }
 public static IndicatorAttribute fromString(String text) {
   return fromNode(Node.fromString(text));
 }
Beispiel #7
0
 public static Sequence fromString(String text) {
   return fromNode(Node.fromString(text));
 }