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.
11 12 13 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 11 def initialize(input_file_handler) @doc = Nokogiri::XML(input_file_handler) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
8 9 10 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 8 def doc @doc end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
9 10 11 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 9 def document @document end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
9 10 11 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 9 def entities @entities end |
#opinions ⇒ Object (readonly)
Returns the value of attribute opinions.
9 10 11 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 9 def opinions @opinions end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
9 10 11 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 9 def properties @properties end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
9 10 11 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 9 def terms @terms end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
9 10 11 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 9 def words @words end |
Instance Method Details
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 15 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
54 55 56 57 58 59 60 61 62 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 54 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
42 43 44 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 42 def parse_entities parse_elements("//entity", Entity, :terms=>terms) end |
#parse_opinions ⇒ Object
50 51 52 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 50 def parse_opinions parse_elements("//opinion", Opinion, :terms=>terms) end |
#parse_properties ⇒ Object
46 47 48 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 46 def parse_properties parse_elements("//property", Property, :terms=>terms) end |
#parse_terms ⇒ Object
36 37 38 39 40 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 36 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
32 33 34 |
# File 'lib/opener/s3_outlet/visualizer.rb', line 32 def parse_words parse_elements("//wf", Word) end |