Permalink
Browse files

added new feature, intelligent selection

Signed-off-by: Rifat Nabi <to.rifat@gmail.com>
  • Loading branch information...
1 parent 6bad417 commit ee710dedab95c2723084f0208ba659d022f3ec9a @torifat committed Jul 4, 2012
Showing with 13 additions and 5 deletions.
  1. +13 −5 Suggestion.m
View
@@ -96,23 +96,31 @@ - (NSMutableArray*)getList:(NSString*)term {
// Suggestions with Suffix
int i;
+ BOOL alreadySelected = FALSE;
for (i = [term length]-1; i > 0; --i) {
- NSLog(@"Suffix English: %@", [[term substringFromIndex:i] lowercaseString]);
NSString* suffix = [[Database sharedInstance] banglaForSuffix:[[term substringFromIndex:i] lowercaseString]];
- NSLog(@"Suffix Bangla: %@", suffix);
if (suffix) {
NSString* base = [term substringToIndex:i];
- NSLog(@"Suffix: %@", base);
NSArray* cached = [[CacheManager sharedInstance] arrayForKey:base];
+ NSString* selected;
+ if (!alreadySelected) {
+ // Base user selection
+ selected = [[CacheManager sharedInstance] stringForKey:base];
+ }
// This should always exist, so it's just a safety check
if (cached) {
for (NSString *item in cached) {
- NSLog(@"Item: %@", item);
// Skip AutoCorrect English Entry
if ([base isEqualToString:item]) {
continue;
}
- [_suggestions addObject:[NSString stringWithFormat:@"%@%@", item, suffix]];
+ NSString* word = [NSString stringWithFormat:@"%@%@", item, suffix];
+ // Intelligent Selection
+ if (!alreadySelected && selected && [item isEqualToString:selected]) {
+ [[CacheManager sharedInstance] setString:word forKey:term];
+ alreadySelected = TRUE;
+ }
+ [_suggestions addObject:word];
}
}
}

0 comments on commit ee710de

Please sign in to comment.