Class: Concept
- Inherits:
-
Object
- Object
- Concept
- Defined in:
- lib/asker/data/concept.rb
Constant Summary collapse
- @@id =
Global Concept counter (concept identifier)
0
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Context inherits from map.
-
#data ⇒ Object
readonly
Data about this concept.
-
#filename ⇒ Object
readonly
Filename where this concept is defined.
-
#id ⇒ Object
readonly
Unique identifer (Integer).
-
#lang ⇒ Object
readonly
Lang object.
-
#names ⇒ Object
readonly
Names used to identify or name this concept.
-
#process ⇒ Object
(Boolean) if it is necesary generate questions.
-
#type ⇒ Object
readonly
type = text -> Name values are only text.
Instance Method Summary collapse
- #calculate_nearness_to_concept(other) ⇒ Object
- #images ⇒ Object
-
#initialize(xml_data, filename, lang, context) ⇒ Concept
constructor
Initilize Concept.
- #name(option = :raw) ⇒ Object
- #neighbors ⇒ Object
- #process? ⇒ Boolean
- #reference_to ⇒ Object
- #referenced_by ⇒ Object
- #tables ⇒ Object
- #tags ⇒ Object
- #text ⇒ Object
- #texts ⇒ Object
- #try_adding_neighbor(other) ⇒ Object
- #try_adding_references(other) ⇒ Object
Constructor Details
#initialize(xml_data, filename, lang, context) ⇒ Concept
Initilize Concept
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/asker/data/concept.rb', line 27 def initialize(xml_data, filename, lang, context) @@id += 1 @id = @@id @filename = filename @process = false @lang = lang # LangFactory.instance.get(lang_code) @context = context @names = ["concept." + @id.to_s] @type = "text" @data = {} @data[:tags] = [] @data[:texts] = [] # Used by standard def inputs @data[:images] = [] # Used by [type => file and type => image_url] def inputs @data[:tables] = [] @data[:neighbors] = [] @data[:reference_to] = [] @data[:referenced_by] = [] read_data_from_xml(xml_data) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Context inherits from map
12 13 14 |
# File 'lib/asker/data/concept.rb', line 12 def context @context end |
#data ⇒ Object (readonly)
Data about this concept
16 17 18 |
# File 'lib/asker/data/concept.rb', line 16 def data @data end |
#filename ⇒ Object (readonly)
Filename where this concept is defined
15 16 17 |
# File 'lib/asker/data/concept.rb', line 15 def filename @filename end |
#id ⇒ Object (readonly)
Unique identifer (Integer)
10 11 12 |
# File 'lib/asker/data/concept.rb', line 10 def id @id end |
#lang ⇒ Object (readonly)
Lang object
11 12 13 |
# File 'lib/asker/data/concept.rb', line 11 def lang @lang end |
#names ⇒ Object (readonly)
Names used to identify or name this concept
13 14 15 |
# File 'lib/asker/data/concept.rb', line 13 def names @names end |
#process ⇒ Object
(Boolean) if it is necesary generate questions
17 18 19 |
# File 'lib/asker/data/concept.rb', line 17 def process @process end |
#type ⇒ Object (readonly)
type = text -> Name values are only text
14 15 16 |
# File 'lib/asker/data/concept.rb', line 14 def type @type end |
Instance Method Details
#calculate_nearness_to_concept(other) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/asker/data/concept.rb', line 72 def calculate_nearness_to_concept(other) weights = ProjectData.instance.get(:weights).split(",").map(&:to_f) max1 = @context.count max2 = @data[:tags].count max3 = @data[:tables].count alike1 = alike2 = alike3 = 0.0 # check if exists this items from concept1 into concept2 @context.each { |i| alike1 += 1.0 unless other.context.index(i).nil? } @data[:tags].each { |i| alike2 += 1.0 unless other..index(i).nil? } @data[:tables].each { |i| alike3 += 1.0 unless other.tables.index(i).nil? } alike = (alike1 * weights[0] + alike2 * weights[1] + alike3 * weights[2]) max = (max1 * weights[0] + max2 * weights[1] + max3 * weights[2]) (alike * 100.0 / max) end |
#images ⇒ Object
116 117 118 |
# File 'lib/asker/data/concept.rb', line 116 def images @data[:images] end |
#name(option = :raw) ⇒ Object
50 51 52 |
# File 'lib/asker/data/concept.rb', line 50 def name(option = :raw) DataField.new(@names[0], @id, @type).get(option) end |
#neighbors ⇒ Object
124 125 126 |
# File 'lib/asker/data/concept.rb', line 124 def neighbors @data[:neighbors] end |
#process? ⇒ Boolean
58 59 60 |
# File 'lib/asker/data/concept.rb', line 58 def process? @process end |
#reference_to ⇒ Object
128 129 130 |
# File 'lib/asker/data/concept.rb', line 128 def reference_to @data[:reference_to] end |
#referenced_by ⇒ Object
132 133 134 |
# File 'lib/asker/data/concept.rb', line 132 def referenced_by @data[:referenced_by] end |
#tables ⇒ Object
120 121 122 |
# File 'lib/asker/data/concept.rb', line 120 def tables @data[:tables] end |
#tags ⇒ Object
108 109 110 |
# File 'lib/asker/data/concept.rb', line 108 def @data[:tags] end |
#text ⇒ Object
54 55 56 |
# File 'lib/asker/data/concept.rb', line 54 def text @data[:texts][0] || "..." end |
#texts ⇒ Object
112 113 114 |
# File 'lib/asker/data/concept.rb', line 112 def texts @data[:texts] end |
#try_adding_neighbor(other) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/asker/data/concept.rb', line 62 def try_adding_neighbor(other) p = calculate_nearness_to_concept(other) return if p.zero? @data[:neighbors] << {concept: other, value: p} # Sort neighbors list @data[:neighbors].sort! { |a, b| a[:value] <=> b[:value] } @data[:neighbors].reverse! end |
#try_adding_references(other) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/asker/data/concept.rb', line 91 def try_adding_references(other) reference_to = 0 @data[:tags].each do |i| reference_to += 1 unless other.names.index(i.downcase).nil? end @data[:texts].each do |t| text = t.clone text.split(" ").each do |word| reference_to += 1 unless other.names.index(word.downcase).nil? end end return unless reference_to.positive? @data[:reference_to] << other.name other.data[:referenced_by] << name end |