code: public GrammarRules toGrammarRulesData() {
  
      GrammarRules res = new GrammarRules();
  
      GrammarRuleRecord r0 = new GrammarRuleRecord();
      r0.setRuleNumber(0);
      r0.setRuleString(this.r0String);
      r0.setExpandedRuleString(this.r0ExpandedString);
      r0.setOccurrences(new int[] { 0 });
      r0.setMeanLength(-1);
      r0.setMinMaxLength(new int[] { -1 });
      res.addRule(r0);
  
      for (RePairRule rule : theRules.values()) {
        // System.out.println("processing the rule " + rule.ruleNumber);
        GrammarRuleRecord rec = new GrammarRuleRecord();
  
        rec.setRuleNumber(rule.ruleNumber);
        rec.setRuleString(rule.toRuleString());
        rec.setExpandedRuleString(rule.expandedRuleString);
        rec.setRuleYield(countSpaces(rule.expandedRuleString));
        rec.setOccurrences(rule.getOccurrences());
        rec.setRuleIntervals(rule.getRuleIntervals());
        rec.setRuleLevel(rule.getLevel());
        rec.setMinMaxLength(rule.getLengths());
        rec.setMeanLength(mean(rule.getRuleIntervals()));
  
        res.addRule(rec);
      }
  
      // count the rule use
      for (GrammarRuleRecord r : res) {
        String str = r.getRuleString();
        String[] tokens = str.split("\\s+");
        for (String t : tokens) {
          if (t.startsWith("R")) {
            Integer ruleId = Integer.valueOf(t.substring(1));
            GrammarRuleRecord rr = res.get(ruleId);
            // System.out.print(rr.getRuleUseFrequency() + " ");
            int newFreq = rr.getRuleUseFrequency() + 1;
            rr.setRuleUseFrequency(newFreq);
            // System.out.println(rr.getRuleUseFrequency());
          }
        }
      }
  
      return res;
    }
docs: Build a grammarviz-"portable" grammar object.
  
  @return a grammarviz-"portable" grammar object.