Class: Treat::Workers::Formatters::Visualizers::Standoff
- Inherits:
-
Object
- Object
- Treat::Workers::Formatters::Visualizers::Standoff
- Defined in:
- lib/treat/workers/formatters/visualizers/standoff.rb
Overview
Visualization of entities in standoff (tag-bracketed) format, based on the Stanford tag-bracketed format.
Constant Summary collapse
- DefaultOptions =
Start out with an indent of 0.
{ :indent => 0 }
- Recurse =
A lambda to recursively visualize the children of an entity.
lambda do |entity, | v = '' entity.each { |child| v += visualize(child, ) } v end
Class Method Summary collapse
- .ptb_escape(val) ⇒ Object
-
.visualize(entity, options = {}) ⇒ Object
Fix - brackets Visualize the entity using standoff notation.
Class Method Details
.ptb_escape(val) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/treat/workers/formatters/visualizers/standoff.rb', line 45 def self.ptb_escape(val) Treat..ptb.escape_characters.each do |char, esc| val.gsub!(char, val) end val end |
.visualize(entity, options = {}) ⇒ Object
Fix - brackets Visualize the entity using standoff notation. This can only be called on sentences and smaller entities, as it is not a suitable format to represent larger entities.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/treat/workers/formatters/visualizers/standoff.rb', line 21 def self.visualize(entity, = {}) = DefaultOptions.merge() value = ''; spaces = '' [:indent].times { spaces << ' '} [:indent] += 1 if entity.is_a?(Treat::Entities::Token) val = ptb_escape(entity.value) value += "#{spaces}(#{entity.tag} #{val})" elsif entity.is_a?(Treat::Entities::Phrase) tag = entity.has?(:tag) ? entity.tag : '' value += ("#{spaces}(#{tag}\n" + "#{Recurse.call(entity, )})\n") elsif entity.is_a?(Treat::Entities::Sentence) value += ("#{spaces}(S\n" + "#{Recurse.call(entity, )})\n") else raise 'Standoff format is unsuitable to represent' + ' entities larger than sentences.' end [:indent] -= 1 value.gsub!(")\n)", "))") value end |