Class: Opener::Kaf::Visualizer::Parser
- Inherits:
-
Object
- Object
- Opener::Kaf::Visualizer::Parser
- Defined in:
- lib/opener/s3_outlet/visualizer.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
-
#opinions ⇒ Object
readonly
Returns the value of attribute opinions.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
-
#initialize(input_file_handler) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parse_elements(xpath, klass, opts = {}) ⇒ Object
- #parse_entities ⇒ Object
- #parse_opinions ⇒ Object
- #parse_properties ⇒ Object
- #parse_terms ⇒ Object
- #parse_words ⇒ Object
Constructor Details
#initialize(input_file_handler) ⇒ Parser
Returns a new instance of Parser.
8 9 10 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 8 def initialize(input_file_handler) @doc = Nokogiri::XML(input_file_handler) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
5 6 7 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 5 def doc @doc end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
6 7 8 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 6 def document @document end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
6 7 8 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 6 def entities @entities end |
#opinions ⇒ Object (readonly)
Returns the value of attribute opinions.
6 7 8 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 6 def opinions @opinions end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
6 7 8 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 6 def properties @properties end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
6 7 8 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 6 def terms @terms end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
6 7 8 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 6 def words @words end |
Instance Method Details
#parse ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 12 def parse @words = parse_words @terms = parse_terms @entities = parse_entities @properties = parse_properties @opinions = parse_opinions @document = KAFDocument.new( :words => words, :terms => terms, :entities => entities, :properties => properties, :opinions => opinions ) return document end |
#parse_elements(xpath, klass, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 51 def parse_elements(xpath, klass, opts={}) elements = doc.xpath(xpath) lookup_table = Hash.new elements.each do |element| instance = klass.new(element, opts) lookup_table[instance.id] = instance end lookup_table end |
#parse_entities ⇒ Object
39 40 41 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 39 def parse_entities parse_elements("//entity", Entity, :terms=>terms) end |
#parse_opinions ⇒ Object
47 48 49 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 47 def parse_opinions parse_elements("//opinion", Opinion, :terms=>terms) end |
#parse_properties ⇒ Object
43 44 45 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 43 def parse_properties parse_elements("//property", Property, :terms=>terms) end |
#parse_terms ⇒ Object
33 34 35 36 37 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 33 def parse_terms # Of course terms should be words here. # Dirty Hack, sufficient for now. parse_elements("//term", Term, :terms=>words) end |
#parse_words ⇒ Object
29 30 31 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 29 def parse_words parse_elements("//wf", Word) end |