<commit_before>require 'srgs/version'
require 'srgs/elements/grammar'
require 'srgs/elements/item'
require 'srgs/elements/example'
require 'srgs/elements/lexicon'
require 'srgs/elements/meta'
require 'srgs/elements/metadata'
require 'srgs/elements/one_of'
require 'srgs/elements/rule'
require 'srgs/elements/rule_ref'
require 'srgs/elements/tag'
require 'srgs/elements/token'

module Srgs
  # Your code goes here...
end<commit_msg>Added some of the build grammar methods<commit_after>require 'srgs/version'
require 'srgs/elements/grammar'
require 'srgs/elements/item'
require 'srgs/elements/example'
require 'srgs/elements/lexicon'
require 'srgs/elements/meta'
require 'srgs/elements/metadata'
require 'srgs/elements/one_of'
require 'srgs/elements/rule'
require 'srgs/elements/rule_ref'
require 'srgs/elements/tag'
require 'srgs/elements/token'
require 'nokogiri'

module Srgs
  extend self

  def build(grammar)
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.grammar do
        grammar.rules.each do |rule|
          rule(xml, rule)
        end
      end
    end
  end

  def item(item, xml)
    att = {}
    set(:repeat, att, item.repeat)
    set(:'repeat-prob', att, item.repeat_prob)
    set(:weight, att, item.weight)
    if item.element.is_a Token
      xml.item(att) do
        tag(item.tag, xml) unless item.tag.nil?
        token(item.element, xml)
      end
    else
      xml.item(att) item.element do
        tag(item.tag, xml) unless item.tag.nil?
      end
    end
  end

  def lexicon(lexicon, xml)

  end

  def meta(meta, xml)

  end

  def metadata(metadata, xml)
  end

  def one_of(one_of, xml)

  end

  def rule(xml, rule)
    att = {id: rule.id}
    set(:scope, att, rule.scope)
    set(:'sapi:dynamic', att, rule.dynamic)
    xml.rule(att) do
      @rule.elements.each do |element|
        if element.is_a Item
          item(element, xml)
        end
      end
    end
  end

  def rule_ref(rule_ref, xml)

  end

  def tag(tag, xml)
    xml.tag tag.text
  end

  def token(token, xml)
    att = {}
    att(:'sapi:display', att, token.display)
    att(:'sapi:pron', att, token.pron)
    xml.token(att) token.text
  end

  def set(sym, att, value)
    att[sym] = value unless value.nil?
  end

end
{'fraction_non_alphanumeric': 0.12085944494180842, 'fraction_numerical': 0.0, 'mean_word_length': 3.027027027027027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 21}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3334578', 'n_tokens_mistral': 809, 'n_tokens_neox': 791, 'n_words': 194}