Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactoring: tokenCount -> tokenData

  • Loading branch information...
commit a483b157a33a075fe2b0c0da926c847de4e3e0c8 1 parent 6d5127c
Samuel Mendes authored

Showing 2 changed files with 18 additions and 22 deletions. Show diff stats Hide diff stats

  1. +1 1  src/BKBayesianDataPool.h
  2. +17 21 src/BKBayesianDataPool.m
2  src/BKBayesianDataPool.h
@@ -43,7 +43,7 @@
43 43
44 44 @private
45 45 NSUInteger _tokensTotalCount;
46   - NSMutableDictionary *_tokensCount;
  46 + NSMutableDictionary *_tokensData;
47 47 }
48 48
49 49 @property (readonly) NSString *name;
38 src/BKBayesianDataPool.m
@@ -49,7 +49,7 @@ - (id)initWithName:(NSString*)aName
49 49 self = [super init];
50 50 if (self) {
51 51 name = [aName retain];
52   - _tokensCount = [[NSMutableDictionary alloc] init];
  52 + _tokensData = [[NSMutableDictionary alloc] init];
53 53 }
54 54 return self;
55 55 }
@@ -57,7 +57,7 @@ - (id)initWithName:(NSString*)aName
57 57 - (void)dealloc
58 58 {
59 59 [name release];
60   - [_tokensCount release];
  60 + [_tokensData release];
61 61 [super dealloc];
62 62 }
63 63
@@ -69,7 +69,7 @@ - (id)initWithCoder:(NSCoder*)coder
69 69 if (self) {
70 70 name = [[coder decodeObjectForKey:@"Name"] retain];
71 71 _tokensTotalCount = [coder decodeIntegerForKey:@"TotalCount"];
72   - _tokensCount = [[coder decodeObjectForKey:@"Tokens"] retain];
  72 + _tokensData = [[coder decodeObjectForKey:@"TokensData"] retain];
73 73 }
74 74 return self;
75 75 }
@@ -78,14 +78,14 @@ - (void)encodeWithCoder:(NSCoder*)coder
78 78 {
79 79 [coder encodeObject:name forKey:@"Name"];
80 80 [coder encodeInteger:_tokensTotalCount forKey:@"TotalCount"];
81   - [coder encodeObject:_tokensCount forKey:@"Tokens"];
  81 + [coder encodeObject:_tokensData forKey:@"TokensData"];
82 82 }
83 83
84 84 #pragma mark -
85 85 #pragma mark Token Counting Methods
86 86 - (NSUInteger)countForToken:(NSString*)token
87 87 {
88   - BKBayesianTokenData *data = [_tokensCount objectForKey:token];
  88 + BKBayesianTokenData *data = [_tokensData objectForKey:token];
89 89 if (data) {
90 90 return [data count];
91 91 } else {
@@ -96,14 +96,14 @@ - (NSUInteger)countForToken:(NSString*)token
96 96 - (void)setCount:(NSUInteger)count forToken:(NSString*)token
97 97 {
98 98 _tokensTotalCount -= [self countForToken:token];
99   - [_tokensCount setObject:[BKBayesianTokenData tokenDataWithCount:count]
  99 + [_tokensData setObject:[BKBayesianTokenData tokenDataWithCount:count]
100 100 forKey:token];
101 101 _tokensTotalCount += count;
102 102 }
103 103
104 104 - (void)addCount:(NSUInteger)count forToken:(NSString*)token
105 105 {
106   - BKBayesianTokenData *data = [_tokensCount objectForKey:token];
  106 + BKBayesianTokenData *data = [_tokensData objectForKey:token];
107 107 if (!data) {
108 108 data = [BKBayesianTokenData tokenDataWithCount:count];
109 109 } else {
@@ -115,13 +115,13 @@ - (void)addCount:(NSUInteger)count forToken:(NSString*)token
115 115 data = [BKBayesianTokenData tokenDataWithCount:(count + [data count])];
116 116 }
117 117 _tokensTotalCount+=count;
118   - [_tokensCount setObject:data forKey:token];
  118 + [_tokensData setObject:data forKey:token];
119 119 }
120 120
121 121 - (void)increaseCountForToken:(NSString*)token
122 122 {
123 123 NSUInteger count = [self countForToken:token];
124   - [_tokensCount setObject:[BKBayesianTokenData tokenDataWithCount:count+1]
  124 + [_tokensData setObject:[BKBayesianTokenData tokenDataWithCount:count+1]
125 125 forKey:token];
126 126 _tokensTotalCount++;
127 127 }
@@ -130,7 +130,7 @@ - (void)increaseCountForToken:(NSString*)token
130 130 #pragma mark Token Probabilities Methods
131 131 - (float)probabilityForToken:(NSString*)token
132 132 {
133   - BKBayesianTokenData *data = [_tokensCount objectForKey:token];
  133 + BKBayesianTokenData *data = [_tokensData objectForKey:token];
134 134 if (data) {
135 135 return [data probability];
136 136 } else {
@@ -140,7 +140,7 @@ - (float)probabilityForToken:(NSString*)token
140 140
141 141 - (void)setProbability:(float)probability forToken:(NSString*)token
142 142 {
143   - BKBayesianTokenData *data = [_tokensCount objectForKey:token];
  143 + BKBayesianTokenData *data = [_tokensData objectForKey:token];
144 144 if (data) {
145 145 [data setProbability:probability];
146 146 }
@@ -165,13 +165,13 @@ - (NSArray*)probabilitiesForTokens:(NSArray*)tokens
165 165 #pragma mark General Token Manipulation
166 166 - (NSArray*)allTokens
167 167 {
168   - return [_tokensCount allKeys];
  168 + return [_tokensData allKeys];
169 169 }
170 170
171 171 - (void)removeToken:(NSString*)token
172 172 {
173 173 _tokensTotalCount -= [self countForToken:token];
174   - [_tokensCount removeObjectForKey:token];
  174 + [_tokensData removeObjectForKey:token];
175 175 }
176 176
177 177
@@ -179,29 +179,25 @@ - (void)removeToken:(NSString*)token
179 179 #pragma mark Printing Methods
180 180 - (NSString*)description
181 181 {
182   - return [_tokensCount description];
  182 + return [_tokensData description];
183 183 }
184 184
185 185 - (void)printInformations
186 186 {
187 187 NSLog(@"%@ Informations:", name);
188   - NSLog(@" Number of tokens: %llu", [_tokensCount count]);
  188 + NSLog(@" Number of tokens: %llu", [_tokensData count]);
189 189 NSLog(@" Total count of tokens: %llu", _tokensTotalCount);
190 190
191   - NSArray *keys = [_tokensCount keysSortedByValueUsingSelector:@selector(compareCount:)];
  191 + NSArray *keys = [_tokensData keysSortedByValueUsingSelector:@selector(compareCount:)];
192 192 NSString *token = [keys lastObject];
193 193 NSLog(@" Most counted token: %@ counted %llu times", token, [self countForToken:token]);
194   -
195   - keys = [_tokensCount keysSortedByValueUsingSelector:@selector(compareProbability:)];
196   - token = [keys lastObject];
197   - NSLog(@"Highest probability token: %@ with %02i%%", token, (int)([self probabilityForToken:token]*100.));
198 194 }
199 195
200 196 #pragma mark -
201 197 #pragma mark NSFastEnumeration Methods
202 198 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
203 199 {
204   - return [_tokensCount countByEnumeratingWithState:state objects:stackbuf count:len];
  200 + return [_tokensData countByEnumeratingWithState:state objects:stackbuf count:len];
205 201 }
206 202
207 203 @end

0 comments on commit a483b15

Please sign in to comment.
Something went wrong with that request. Please try again.