Class: PheremoneAnalysis
- Inherits:
-
Object
- Object
- PheremoneAnalysis
- Defined in:
- lib/summa.rb
Instance Attribute Summary collapse
-
#documet ⇒ Object
Returns the value of attribute documet.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#output ⇒ Object
Returns the value of attribute output.
-
#pheremones ⇒ Object
Returns the value of attribute pheremones.
-
#sigma ⇒ Object
Returns the value of attribute sigma.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
- #analyze ⇒ Object
- #findEndOfSentence(i) ⇒ Object
- #findStartOfSentence(i) ⇒ Object
-
#initialize(text) ⇒ PheremoneAnalysis
constructor
A new instance of PheremoneAnalysis.
- #summarize ⇒ Object
Constructor Details
#initialize(text) ⇒ PheremoneAnalysis
Returns a new instance of PheremoneAnalysis.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/summa.rb', line 18 def initialize(document, keywords, constants) @pheremones = Array.new(document.wordArray.length()) for i in 0...document.wordArray.length @pheremones[i] = 0 end @document = document @keywords = keywords @sigma = SummaData.sigma @sigma_sq = @sigma * @sigma @threshold = SummaData.threshold @output = "" end |
Instance Attribute Details
#documet ⇒ Object
Returns the value of attribute documet.
163 164 165 |
# File 'lib/summa.rb', line 163 def documet @documet end |
#keywords ⇒ Object
Returns the value of attribute keywords.
163 164 165 |
# File 'lib/summa.rb', line 163 def keywords @keywords end |
#output ⇒ Object
Returns the value of attribute output.
163 164 165 |
# File 'lib/summa.rb', line 163 def output @output end |
#pheremones ⇒ Object
Returns the value of attribute pheremones.
163 164 165 |
# File 'lib/summa.rb', line 163 def pheremones @pheremones end |
#sigma ⇒ Object
Returns the value of attribute sigma.
163 164 165 |
# File 'lib/summa.rb', line 163 def sigma @sigma end |
#threshold ⇒ Object
Returns the value of attribute threshold.
163 164 165 |
# File 'lib/summa.rb', line 163 def threshold @threshold end |
Instance Method Details
#analyze ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/summa.rb', line 46 def analyze() front = 1/(@sigma * Math.sqrt(2 * Math::PI)) for i in 0 ... @document.wordArray.length for j in 0 ... @keywords.wordArray.length if @document.docArray[i][@keywords.wordArray[j]] != nil for pos in 0 ... @document.wordArray.length temp = front * Math.exp(-((i-pos)*(i-pos))/(2*@sigma_sq)) @pheremones[pos] = @pheremones[pos] + temp end end end end max_value = -1; for i in 0 ... @pheremones.length if max_value < @pheremones[i] max_value = @pheremones[i]; end end for i in 0 ... @pheremones.length @pheremones[i] /= max_value; end end |
#findEndOfSentence(i) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/summa.rb', line 128 def findEndOfSentence(i) endIndex = @document.docArray.length index = i local_output = "" while(index < @document.docArray.length) word = @document.docArray[index] if(word != "Mr." && word != "Mrs." && word != "Dr." && word != "U.S." && word != "Jan." && word != "Feb." && word != "Mar." && word != "Apr." && word != "May." && word != "Jun." && word != "Jul." && word != "Aug." && word != "Sep." && word != "Oct." && word != "Nov." && word != "Dec." && word != "Sept." && word != "Lt." && word != "Maj." && word != "Col.") c = word[word.length - 1] if(c == "."[0] || c == ";"[0] || c == ":"[0]) endIndex = index break; end end index = index + 1 end if endIndex != i for j in i+1 ... (endIndex + 1) local_output += @document.docArray[j] local_output += " " end end local_output end |
#findStartOfSentence(i) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/summa.rb', line 96 def findStartOfSentence(i) index = i startIndex = 0 local_output = "" while(index > 0) word = @document.docArray[index] if(word != "Mr." && word != "Mrs." && word != "Dr." && word != "U.S." && word != "Jan." && word != "Feb." && word != "Mar." && word != "Apr." && word != "May." && word != "Jun." && word != "Jul." && word != "Aug." && word != "Sep." && word != "Oct." && word != "Nov." && word != "Dec." && word != "Sept." && word != "Lt." && word != "Maj." && word != "Col.") c = word[word.length - 1] if(c == "."[0] || c == ";"[0] || c == ":"[0]) startIndex = index + 1 break; end end index = index - 1 end for j in startIndex ... i local_output += @document.docArray[j] local_output += " " end local_output end |
#summarize ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/summa.rb', line 71 def summarize() @output = "" inRegion = false for i in 0 ... @pheremones.length if @pheremones[i] >= @threshold if inRegion @output += @document.docArray[i]; @output += " "; else inRegion = true @output += findStartOfSentence(i) @output += @document.docArray[i]; @output += " " end else if inRegion inRegion = false @output += findEndOfSentence(i-1) @output += " " end end end @output end |