Class: Abrupt::Converter
- Includes:
- RDF, Singleton
- Defined in:
- lib/abrupt/converter.rb
Overview
Converter
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#hsh ⇒ Object
Returns the value of attribute hsh.
-
#result ⇒ Object
Returns the value of attribute result.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#values ⇒ Object
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_result(statements) ⇒ Object
- #append_pages_for_visitor(visitor) ⇒ Object
- #append_rules ⇒ Object
- #append_tbox ⇒ Object
- #append_user_data(file) ⇒ Object
- #append_website_data(hsh) ⇒ Object
- #init(options = {}) ⇒ Object
- #init_hsh(hsh) ⇒ Object
- #init_website ⇒ Object
- #perform ⇒ Object
- #perform_states(states, parent_uri) ⇒ Object
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
21 22 23 |
# File 'lib/abrupt/converter.rb', line 21 def format @format end |
#hsh ⇒ Object
Returns the value of attribute hsh.
21 22 23 |
# File 'lib/abrupt/converter.rb', line 21 def hsh @hsh end |
#result ⇒ Object
Returns the value of attribute result.
21 22 23 |
# File 'lib/abrupt/converter.rb', line 21 def result @result end |
#uri ⇒ Object
Returns the value of attribute uri.
21 22 23 |
# File 'lib/abrupt/converter.rb', line 21 def uri @uri end |
#values ⇒ Object
Returns the value of attribute values.
21 22 23 |
# File 'lib/abrupt/converter.rb', line 21 def values @values end |
Class Method Details
.json(hsh) ⇒ Object
61 62 63 |
# File 'lib/abrupt/converter.rb', line 61 def self.json(hsh) hsh.to_json end |
.xml(hsh) ⇒ Object
57 58 59 |
# File 'lib/abrupt/converter.rb', line 57 def self.xml(hsh) Gyoku.xml hsh end |
Instance Method Details
#add_to_result(statements) ⇒ Object
65 66 67 |
# File 'lib/abrupt/converter.rb', line 65 def add_to_result(statements) statements.each { |stmt| @result << stmt } end |
#append_pages_for_visitor(visitor) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/abrupt/converter.rb', line 107 def append_pages_for_visitor(visitor) pages = visitor.values[:pages][:page].ensure_to_a pages.each do |page| time = ::Abrupt.format_time(page[:entertime]) Transformation::Client::Base.subclasses.each do |transformer_class| transformer = transformer_class.new(visitor.parent_uri + visitor.uri, ['Visit', time], page) add_to_result transformer.add_individuals end end end |
#append_rules ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/abrupt/converter.rb', line 119 def append_rules Dir.glob(RULES_DIR).each do |rule_directory| Dir.glob(File.join(rule_directory, '*')).each do |rule_file| rule = Repository.load(rule_file) add_to_result(rule.statements) end end end |
#append_tbox ⇒ Object
28 29 30 |
# File 'lib/abrupt/converter.rb', line 28 def append_tbox @result << Repository.load(VOC_FILE) end |
#append_user_data(file) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/abrupt/converter.rb', line 93 def append_user_data(file) return unless file.is_a?(String) && File.exist?(file) xml = Hash.from_xml(File.read(file)).deep_symbolize_keys xml[:database][:visitor].ensure_to_a.each do |values| ip = values[:ip] next unless ip visitor = Transformation::Client::Visitor.new(['Website', @uri.to_s], ['Visitor', ip], values) add_to_result visitor.add_individuals append_pages_for_visitor(visitor) end @result end |
#append_website_data(hsh) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/abrupt/converter.rb', line 32 def append_website_data(hsh) init_hsh(hsh) @uri = URI(@hsh[:website][:domain]) init_website perform end |
#init(options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/abrupt/converter.rb', line 23 def init( = {}) @format = [:format].try(:to_sym) || :turtle @result = Repository.new end |
#init_hsh(hsh) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/abrupt/converter.rb', line 45 def init_hsh(hsh) hsh = Hash.from_xml(File.read(hsh)) unless hsh.is_a?(Hash) @hsh = hsh.deep_symbolize_keys return unless @hsh[:website] @hsh[:website][:url].each_with_index do |value, i| Transformation::Website::Base.subclasses.each do |transformation_class| @hsh[:website][:url][i] = transformation_class.customize_to_schema(value) end end end |
#init_website ⇒ Object
39 40 41 42 43 |
# File 'lib/abrupt/converter.rb', line 39 def init_website domain = RDF::URI("#{VOC}Website/#{@uri}") @result << Statement.new(domain, RDF.type, VOC.Website) @result << Statement.new(domain, VOC.hostName, @uri.host) end |
#perform ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/abrupt/converter.rb', line 69 def perform website = ['Website', @uri.to_s] @hsh[:website][:url].each do |url| page = ['Page', url[:name].append_last_slash] page_transformator = Transformation::Base.new(website, page) add_to_result page_transformator.add_individuals # add Page next unless url[:state] perform_states url[:state], website + page end end |
#perform_states(states, parent_uri) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/abrupt/converter.rb', line 80 def perform_states(states, parent_uri) states = states.is_a?(Array) ? states : [states] states.each do |value| state = ['State', value[:name]] # MAYBE empty? add_to_result Transformation::Base.new(parent_uri, state).result Transformation::Website::Base.subclasses.each do |transformation_class| t = transformation_class.new(parent_uri + state, nil, value) add_to_result t.add_individuals end end end |