<commit_before>#!/usr/bin/ruby

require 'rubygems'
require 'alpinocorpus'
require 'rexml/document'
require 'xml/xslt'

if ARGV.length != 2 then
  puts "#{$0} query corpus"
  exit
end

query = ARGV[0]
corpus = ARGV[1]

styledir = File.dirname($0)
stylesheet = "#{styledir}/bracketed-sentence.xsl"

xslt = XML::XSLT.new()
xslt.xsl = REXML::Document.new(File.new(stylesheet))

reader = AlpinoCorpus::Reader.new(corpus)

markers = [AlpinoCorpus::MarkerQuery.new(query, "active", "1")]

reader.query(query).each { |e|
  xslt.xml = REXML::Document.new(reader.read(e, markers))
  puts xslt.serve()
}<commit_msg>Use Nokogiri in the Ruby bracket example.<commit_after>#!/usr/bin/ruby

require 'rubygems'
require 'alpinocorpus'
require 'nokogiri'

if ARGV.length != 2 then
  puts "#{$0} query corpus"
  exit
end

query = ARGV[0]
corpus = ARGV[1]

styledir = File.dirname($0)
stylesheet = "#{styledir}/bracketed-sentence.xsl"

xslt = Nokogiri::XSLT(File.read(stylesheet))

reader = AlpinoCorpus::Reader.new(corpus)

markers = [AlpinoCorpus::MarkerQuery.new(query, "active", "1")]

reader.query(query).each { |e|
  xml = Nokogiri.XML(reader.read(e, markers))
  puts xslt.apply_to(xml)
}
{'fraction_non_alphanumeric': 0.16695059625212946, 'fraction_numerical': 0.010221465076660987, 'mean_word_length': 5.420765027322404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '3376935', 'n_tokens_mistral': 500, 'n_tokens_neox': 473, 'n_words': 90}