Skip to content

Commit

Permalink
added new feature, intelligent selection
Browse files Browse the repository at this point in the history
Signed-off-by: Rifat Nabi <to.rifat@gmail.com>
  • Loading branch information
torifat committed Jul 4, 2012
1 parent 6bad417 commit ee710de
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Suggestion.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
Expand Down

0 comments on commit ee710de

Please sign in to comment.