<commit_before># Example:
#   Illustrates how to add an Annotation definition and values to evidence
#   objects. The evidence results are then serializes out to BEL.
# Usage:
#   ruby examples/add_annotation.rb large_corpus.bel

require 'bel'

# read file from first command argument
bel_file       = File.open(ARGV.first)

# retrieve the formatter for BEL script
bel_formatter  = BEL::Extension::Format.formatters(:bel)

# create new LIST annotation definition
new_annotation = {
  :type   => :list,
  :domain => ['Draft', 'Review', 'Approved', 'Rejected']
}

# read BEL script from file
new_evidence = bel_formatter.deserialize(bel_file).each.lazy.map { |evidence|
  # for each piece of evidence

  # ...add definition and value
  evidence.metadata.annotation_definitions[:Status] = new_annotation
  evidence.experiment_context << {
    :name  => 'Status',
    :value => 'Approved'
  }

  # ...return new evidence
  evidence
}

# serialize new evidence to BEL script and write out
bel_formatter.serialize(new_evidence, $stdout)<commit_msg>updated exampel to read BEL and write JSON<commit_after># Example:
#   Illustrates how to add an Annotation definition and values to evidence
#   objects. Evidence is read from BEL script (e.g. bel formatter) and written
#   as JSON evidence (e.g. json formatter).
# Usage:
#   ruby examples/add_annotation.rb large_corpus.bel

require 'bel'

# read file from first command argument
bel_file       = File.open(ARGV.first)

# retrieve the formatter for BEL script
bel_formatter   = BEL::Extension::Format.formatters(:bel)
json_formatter  = BEL::Extension::Format.formatters(:json)

# create new LIST annotation definition
new_annotation = {
  :type   => :list,
  :domain => ['Draft', 'Review', 'Approved', 'Rejected']
}

# read BEL script from file
new_evidence = bel_formatter.deserialize(bel_file).each.lazy.map { |evidence|
  # for each piece of evidence

  # ...add definition and value
  evidence.metadata.annotation_definitions[:Status] = new_annotation
  evidence.metadata[:Status] = 'Approved'

  # ...return new evidence
  evidence
}

# serialize new evidence to BEL script and write out
json_formatter.serialize(new_evidence, $stdout)
{'fraction_non_alphanumeric': 0.10205949656750572, 'fraction_numerical': 0.0, 'mean_word_length': 4.424317617866005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6784058', 'n_tokens_mistral': 676, 'n_tokens_neox': 637, 'n_words': 207}