Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed @synchronized, performance comes first

Signed-off-by: Rifat Nabi <to.rifat@gmail.com>
  • Loading branch information...
commit fa22adf69d336a0983de1d1a5f7a2da534cfbd86 1 parent 3539f85
@torifat torifat authored
View
99 AutoCorrect.m
@@ -15,22 +15,17 @@ @implementation AutoCorrect
@synthesize autoCorrectEntries = _autoCorrectEntries;
+ (AutoCorrect *)sharedInstance {
- @synchronized (self) {
- if (sharedInstance == nil) {
- [[self alloc] init]; // assignment not done here, see allocWithZone
- }
- }
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here, see allocWithZone
+ }
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
- @synchronized(self) {
- if (sharedInstance == nil) {
- sharedInstance = [super allocWithZone:zone];
- return sharedInstance; // assignment and return on first allocation
- }
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
}
-
return nil; //on subsequent allocation attempts return nil
}
@@ -55,62 +50,56 @@ - (NSUInteger)retainCount {
}
- (id)init {
- @synchronized(self) {
- self = [super init];
- if (self) {
- // Open the file
- NSString *fileName = [[NSBundle mainBundle] pathForResource:@"autodict" ofType:@"dct"];
- const char *fn = [fileName UTF8String];
- FILE *file = fopen(fn, "r");
+ self = [super init];
+ if (self) {
+ // Open the file
+ NSString *fileName = [[NSBundle mainBundle] pathForResource:@"autodict" ofType:@"dct"];
+ const char *fn = [fileName UTF8String];
+ FILE *file = fopen(fn, "r");
+
+ // Read from the file
+ char replaceBuffer[512], withBuffer[512];
+ _autoCorrectEntries = [[NSMutableArray alloc] init];
+ while(fscanf(file, "%s %[^\n]\n", replaceBuffer, withBuffer) == 2) {
+ NSString* replace = [NSString stringWithFormat:@"%s", replaceBuffer];
+ NSString* with = [NSString stringWithFormat:@"%s", withBuffer];
- // Read from the file
- char replaceBuffer[512], withBuffer[512];
- _autoCorrectEntries = [[NSMutableArray alloc] init];
- while(fscanf(file, "%s %[^\n]\n", replaceBuffer, withBuffer) == 2) {
- NSString* replace = [NSString stringWithFormat:@"%s", replaceBuffer];
- NSString* with = [NSString stringWithFormat:@"%s", withBuffer];
-
- if ([replace isEqualToString:with] == NO) {
- with = [[AvroParser sharedInstance] parse:with];
- }
-
- NSMutableDictionary* item = [[NSMutableDictionary alloc] initWithObjectsAndKeys:replace, @"replace", with, @"with", nil];
- [_autoCorrectEntries addObject:item];
- [item release];
+ if ([replace isEqualToString:with] == NO) {
+ with = [[AvroParser sharedInstance] parse:with];
}
- fclose(file);
+
+ NSMutableDictionary* item = [[NSMutableDictionary alloc] initWithObjectsAndKeys:replace, @"replace", with, @"with", nil];
+ [_autoCorrectEntries addObject:item];
+ [item release];
}
- return self;
- }
+ fclose(file);
+ }
+ return self;
}
- (void)dealloc {
- @synchronized(self) {
- [_autoCorrectEntries release];
- [super dealloc];
- }
+ [_autoCorrectEntries release];
+ [super dealloc];
}
// Instance Methods
- (NSString*)find:(NSString*)term {
- @synchronized(self) {
- term = [[AvroParser sharedInstance] fix:term];
- // Binary Search
- int left = 0, right = [_autoCorrectEntries count] -1, mid;
- while (right >= left) {
- mid = (left + right) / 2;
- NSDictionary* item = [_autoCorrectEntries objectAtIndex:mid];
- NSComparisonResult comp = [term compare:[item objectForKey:@"replace"]];
- if (comp == NSOrderedDescending) {
- left = mid + 1;
- } else if (comp == NSOrderedAscending) {
- right = mid - 1;
- } else {
- return [item objectForKey:@"with"];
- }
+ term = [[AvroParser sharedInstance] fix:term];
+ // Binary Search
+ int left = 0, right = [_autoCorrectEntries count] -1, mid;
+ while (right >= left) {
+ mid = (left + right) / 2;
+ NSDictionary* item = [_autoCorrectEntries objectAtIndex:mid];
+ NSComparisonResult comp = [term compare:[item objectForKey:@"replace"]];
+ if (comp == NSOrderedDescending) {
+ left = mid + 1;
+ } else if (comp == NSOrderedAscending) {
+ right = mid - 1;
+ } else {
+ return [item objectForKey:@"with"];
}
- return nil;
}
+ return nil;
}
@end
View
426 AvroParser.m
@@ -12,22 +12,17 @@
@implementation AvroParser
+ (AvroParser *)sharedInstance {
- @synchronized (self) {
- if (sharedInstance == nil) {
- [[self alloc] init]; // assignment not done here, see allocWithZone
- }
- }
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here, see allocWithZone
+ }
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
- @synchronized(self) {
- if (sharedInstance == nil) {
- sharedInstance = [super allocWithZone:zone];
- return sharedInstance; // assignment and return on first allocation
- }
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
}
-
return nil; //on subsequent allocation attempts return nil
}
@@ -52,281 +47,260 @@ - (NSUInteger)retainCount {
}
- (id)init {
- @synchronized(self) {
- self = [super init];
- if (self) {
- NSError *error = nil;
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
- NSData *jsonData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error: &error];
+ self = [super init];
+ if (self) {
+ NSError *error = nil;
+ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
+ NSData *jsonData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error: &error];
+
+ if (jsonData) {
- if (jsonData) {
-
- NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContainers error: &error];
-
- if (!jsonArray) {
- @throw error;
- // @throw [NSException exceptionWithName:@"AvroParser init" reason:@"Error parsing JSON" userInfo:nil];
- } else {
- _vowel = [[NSString alloc] initWithString:[jsonArray objectForKey:@"vowel"]];
- _consonant = [[NSString alloc] initWithString:[jsonArray objectForKey:@"consonant"]];
- _casesensitive = [[NSString alloc] initWithString:[jsonArray objectForKey:@"casesensitive"]];
- _patterns = [[NSArray alloc] initWithArray:[jsonArray objectForKey:@"patterns"]];
- _maxPatternLength = [[[_patterns objectAtIndex:0] objectForKey:@"find"] length];
- }
-
- } else {
+ NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContainers error: &error];
+
+ if (!jsonArray) {
@throw error;
+ // @throw [NSException exceptionWithName:@"AvroParser init" reason:@"Error parsing JSON" userInfo:nil];
+ } else {
+ _vowel = [[NSString alloc] initWithString:[jsonArray objectForKey:@"vowel"]];
+ _consonant = [[NSString alloc] initWithString:[jsonArray objectForKey:@"consonant"]];
+ _casesensitive = [[NSString alloc] initWithString:[jsonArray objectForKey:@"casesensitive"]];
+ _patterns = [[NSArray alloc] initWithArray:[jsonArray objectForKey:@"patterns"]];
+ _maxPatternLength = [[[_patterns objectAtIndex:0] objectForKey:@"find"] length];
}
+
+ } else {
+ @throw error;
}
- return self;
}
+ return self;
}
- (void)dealloc {
- @synchronized(self) {
- [_vowel release];
- [_consonant release];
- [_casesensitive release];
- [_patterns release];
-
- [super dealloc];
- }
+ [_vowel release];
+ [_consonant release];
+ [_casesensitive release];
+ [_patterns release];
+
+ [super dealloc];
}
- (NSString*)parse:(NSString *)string {
- @synchronized(self) {
- if (!string || [string length] == 0) {
- return @"";
- }
-
- NSString * fixed = [self fix:string];
- NSMutableString* output = [[NSMutableString alloc] initWithCapacity:0];
+ if (!string || [string length] == 0) {
+ return @"";
+ }
+
+ NSString * fixed = [self fix:string];
+ NSMutableString* output = [[NSMutableString alloc] initWithCapacity:0];
+
+ int len = [fixed length], cur;
+ for(cur = 0; cur < len; ++cur) {
+ int start = cur, end;
+ BOOL matched = FALSE;
- int len = [fixed length], cur;
- for(cur = 0; cur < len; ++cur) {
- int start = cur, end;
- BOOL matched = FALSE;
-
- int chunkLen;
- for(chunkLen = _maxPatternLength; chunkLen > 0; --chunkLen) {
- end = start + chunkLen;
- if(end <= len) {
- NSString* chunk = [fixed substringWithRange:NSMakeRange(start, chunkLen)];
-
- // Binary Search
- int left = 0, right = [_patterns count] - 1, mid;
- while(right >= left) {
- mid = (right + left) / 2;
- NSDictionary* pattern = [_patterns objectAtIndex:mid];
- NSString* find = [pattern objectForKey:@"find"];
- if([find isEqualToString:chunk]) {
- NSArray* rules = [pattern objectForKey:@"rules"];
- for(NSDictionary* rule in rules) {
+ int chunkLen;
+ for(chunkLen = _maxPatternLength; chunkLen > 0; --chunkLen) {
+ end = start + chunkLen;
+ if(end <= len) {
+ NSString* chunk = [fixed substringWithRange:NSMakeRange(start, chunkLen)];
+
+ // Binary Search
+ int left = 0, right = [_patterns count] - 1, mid;
+ while(right >= left) {
+ mid = (right + left) / 2;
+ NSDictionary* pattern = [_patterns objectAtIndex:mid];
+ NSString* find = [pattern objectForKey:@"find"];
+ if([find isEqualToString:chunk]) {
+ NSArray* rules = [pattern objectForKey:@"rules"];
+ for(NSDictionary* rule in rules) {
+
+ BOOL replace = TRUE;
+ int chk = 0;
+ NSArray* matches = [rule objectForKey:@"matches"];
+ for(NSDictionary* match in matches) {
+ NSString* value = [match objectForKey:@"value"];
+ NSString* type = [match objectForKey:@"type"];
+ NSString* scope = [match objectForKey:@"scope"];
+ BOOL isNegative = [[match objectForKey:@"negative"] boolValue];
- BOOL replace = TRUE;
- int chk = 0;
- NSArray* matches = [rule objectForKey:@"matches"];
- for(NSDictionary* match in matches) {
- NSString* value = [match objectForKey:@"value"];
- NSString* type = [match objectForKey:@"type"];
- NSString* scope = [match objectForKey:@"scope"];
- BOOL isNegative = [[match objectForKey:@"negative"] boolValue];
-
+ if([type isEqualToString:@"suffix"]) {
+ chk = end;
+ }
+ // Prefix
+ else {
+ chk = start - 1;
+ }
+
+ // Beginning
+ if([scope isEqualToString:@"punctuation"]) {
+ if(
+ ! (
+ (chk < 0 && [type isEqualToString:@"prefix"]) ||
+ (chk >= len && [type isEqualToString:@"suffix"]) ||
+ [self isPunctuation:[fixed characterAtIndex:chk]]
+ ) ^ isNegative
+ ) {
+ replace = FALSE;
+ break;
+ }
+ }
+ // Vowel
+ else if([scope isEqualToString:@"vowel"]) {
+ if(
+ ! (
+ (
+ (chk >= 0 && [type isEqualToString:@"prefix"]) ||
+ (chk < len && [type isEqualToString:@"suffix"])
+ ) &&
+ [self isVowel:[fixed characterAtIndex:chk]]
+ ) ^ isNegative
+ ) {
+ replace = FALSE;
+ break;
+ }
+ }
+ // Consonant
+ else if([scope isEqualToString:@"consonant"]) {
+ if(
+ ! (
+ (
+ (chk >= 0 && [type isEqualToString:@"prefix"]) ||
+ (chk < len && [type isEqualToString:@"suffix"])
+ ) &&
+ [self isConsonant:[fixed characterAtIndex:chk]]
+ ) ^ isNegative
+ ) {
+ replace = FALSE;
+ break;
+ }
+ }
+ // Exact
+ else if([scope isEqualToString:@"exact"]) {
+ int s, e;
if([type isEqualToString:@"suffix"]) {
- chk = end;
+ s = end;
+ e = end + [value length];
}
// Prefix
else {
- chk = start - 1;
- }
-
- // Beginning
- if([scope isEqualToString:@"punctuation"]) {
- if(
- ! (
- (chk < 0 && [type isEqualToString:@"prefix"]) ||
- (chk >= len && [type isEqualToString:@"suffix"]) ||
- [self isPunctuation:[fixed characterAtIndex:chk]]
- ) ^ isNegative
- ) {
- replace = FALSE;
- break;
- }
- }
- // Vowel
- else if([scope isEqualToString:@"vowel"]) {
- if(
- ! (
- (
- (chk >= 0 && [type isEqualToString:@"prefix"]) ||
- (chk < len && [type isEqualToString:@"suffix"])
- ) &&
- [self isVowel:[fixed characterAtIndex:chk]]
- ) ^ isNegative
- ) {
- replace = FALSE;
- break;
- }
+ s = start - [value length];
+ e = start;
}
- // Consonant
- else if([scope isEqualToString:@"consonant"]) {
- if(
- ! (
- (
- (chk >= 0 && [type isEqualToString:@"prefix"]) ||
- (chk < len && [type isEqualToString:@"suffix"])
- ) &&
- [self isConsonant:[fixed characterAtIndex:chk]]
- ) ^ isNegative
- ) {
- replace = FALSE;
- break;
- }
+ if(![self isExact:value heystack:fixed start:s end:e not:isNegative]) {
+ replace = FALSE;
+ break;
}
- // Exact
- else if([scope isEqualToString:@"exact"]) {
- int s, e;
- if([type isEqualToString:@"suffix"]) {
- s = end;
- e = end + [value length];
- }
- // Prefix
- else {
- s = start - [value length];
- e = start;
- }
- if(![self isExact:value heystack:fixed start:s end:e not:isNegative]) {
- replace = FALSE;
- break;
- }
- }
- }
-
- if(replace) {
- [output appendString:[rule objectForKey:@"replace"]];
- cur = end - 1;
- matched = TRUE;
- break;
}
-
}
- if(matched == TRUE) break;
+ if(replace) {
+ [output appendString:[rule objectForKey:@"replace"]];
+ cur = end - 1;
+ matched = TRUE;
+ break;
+ }
- // Default
- [output appendString:[pattern objectForKey:@"replace"]];
- cur = end - 1;
- matched = TRUE;
- break;
- }
- else if ([find length] > [chunk length] ||
- ([find length] == [chunk length] && [find compare:chunk] == NSOrderedAscending)) {
- left = mid + 1;
- } else {
- right = mid - 1;
}
+
+ if(matched == TRUE) break;
+
+ // Default
+ [output appendString:[pattern objectForKey:@"replace"]];
+ cur = end - 1;
+ matched = TRUE;
+ break;
+ }
+ else if ([find length] > [chunk length] ||
+ ([find length] == [chunk length] && [find compare:chunk] == NSOrderedAscending)) {
+ left = mid + 1;
+ } else {
+ right = mid - 1;
}
- if(matched == TRUE) break;
}
+ if(matched == TRUE) break;
}
-
- if(!matched) {
- unichar oldChar = [fixed characterAtIndex:cur];
- [output appendString:[NSString stringWithCharacters:&oldChar length:1]];
- }
- // NSLog(@"cur: %s, start: %s, end: %s, prev: %s\n", cur, start, end, prev);
}
- [output autorelease];
-
- return output;
+ if(!matched) {
+ unichar oldChar = [fixed characterAtIndex:cur];
+ [output appendString:[NSString stringWithCharacters:&oldChar length:1]];
+ }
+ // NSLog(@"cur: %s, start: %s, end: %s, prev: %s\n", cur, start, end, prev);
}
+
+ [output autorelease];
+
+ return output;
}
- (BOOL)isVowel:(unichar)c {
- @synchronized(self) {
- // Making it lowercase for checking
- c = [self smallCap:c];
- int i, len = [_vowel length];
- for (i = 0; i < len; ++i) {
- if ([_vowel characterAtIndex:i] == c) {
- return TRUE;
- }
+ // Making it lowercase for checking
+ c = [self smallCap:c];
+ int i, len = [_vowel length];
+ for (i = 0; i < len; ++i) {
+ if ([_vowel characterAtIndex:i] == c) {
+ return TRUE;
}
- return FALSE;
}
+ return FALSE;
}
- (BOOL)isConsonant:(unichar)c {
- @synchronized(self) {
- // Making it lowercase for checking
- c = [self smallCap:c];
- int i, len = [_consonant length];
- for (i = 0; i < len; ++i) {
- if ([_consonant characterAtIndex:i] == c) {
- return TRUE;
- }
+ // Making it lowercase for checking
+ c = [self smallCap:c];
+ int i, len = [_consonant length];
+ for (i = 0; i < len; ++i) {
+ if ([_consonant characterAtIndex:i] == c) {
+ return TRUE;
}
- return FALSE;
- //return [consonant rangeOfString:c options:NSCaseInsensitiveSearch].location != NSNotFound;
}
+ return FALSE;
+ //return [consonant rangeOfString:c options:NSCaseInsensitiveSearch].location != NSNotFound;
}
- (BOOL)isPunctuation:(unichar)c {
- @synchronized(self) {
- return !([self isVowel:c] || [self isConsonant:c]);
- }
+ return !([self isVowel:c] || [self isConsonant:c]);
}
- (BOOL)isCaseSensitive:(unichar)c {
- @synchronized(self) {
- // Making it lowercase for checking
- c = [self smallCap:c];
- int i, len = [_casesensitive length];
- for (i = 0; i < len; ++i) {
- if ([_casesensitive characterAtIndex:i] == c) {
- return TRUE;
- }
+ // Making it lowercase for checking
+ c = [self smallCap:c];
+ int i, len = [_casesensitive length];
+ for (i = 0; i < len; ++i) {
+ if ([_casesensitive characterAtIndex:i] == c) {
+ return TRUE;
}
- return FALSE;
}
+ return FALSE;
}
- (BOOL)isExact:(NSString*) needle heystack:(NSString*)heystack start:(int)start end:(int)end not:(BOOL)not {
- @synchronized(self) {
- // NSLog(@"Cut: %@", [heystack substringWithRange:NSMakeRange(start, end)]);
- int len = end - start;
- return ((start >= 0 && end < [heystack length]
- && [[heystack substringWithRange:NSMakeRange(start, len)] isEqualToString:needle]) ^ not);
- }
+ // NSLog(@"Cut: %@", [heystack substringWithRange:NSMakeRange(start, end)]);
+ int len = end - start;
+ return ((start >= 0 && end < [heystack length]
+ && [[heystack substringWithRange:NSMakeRange(start, len)] isEqualToString:needle]) ^ not);
}
- (unichar)smallCap:(unichar) letter {
- @synchronized(self) {
- if(letter >= 'A' && letter <= 'Z') {
- letter = letter - 'A' + 'a';
- }
- return letter;
+ if(letter >= 'A' && letter <= 'Z') {
+ letter = letter - 'A' + 'a';
}
+ return letter;
}
- (NSString*)fix:(NSString *)string {
- @synchronized(self) {
- NSMutableString* fixed = [[NSMutableString alloc] initWithCapacity:0];
- int i, len = [string length];
- for (i = 0; i < len; ++i) {
- unichar c = [string characterAtIndex:i];
- if (![self isCaseSensitive:c]) {
- [fixed appendFormat:@"%C", [self smallCap:c]];
- }
- else {
- [fixed appendFormat:@"%C", c];
- }
+ NSMutableString* fixed = [[NSMutableString alloc] initWithCapacity:0];
+ int i, len = [string length];
+ for (i = 0; i < len; ++i) {
+ unichar c = [string characterAtIndex:i];
+ if (![self isCaseSensitive:c]) {
+ [fixed appendFormat:@"%C", [self smallCap:c]];
+ }
+ else {
+ [fixed appendFormat:@"%C", c];
}
- [fixed autorelease];
- return fixed;
}
+ [fixed autorelease];
+ return fixed;
}
-
@end
View
121 CacheManager.m
@@ -12,22 +12,18 @@
@implementation CacheManager
+ (CacheManager *)sharedInstance {
- @synchronized (self) {
- if (sharedInstance == nil) {
- [[self alloc] init]; // assignment not done here, see allocWithZone
- }
- }
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here, see allocWithZone
+ }
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
- @synchronized(self) {
- if (sharedInstance == nil) {
- sharedInstance = [super allocWithZone:zone];
- return sharedInstance; // assignment and return on first allocation
- }
+
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
}
-
return nil; //on subsequent allocation attempts return nil
}
@@ -52,109 +48,84 @@ - (NSUInteger)retainCount {
}
- (id)init {
- @synchronized(self) {
- self = [super init];
- if (self) {
- // Weight PLIST File
- NSString *path = [self getSharedFolder];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if ([fileManager fileExistsAtPath:path] == NO) {
- NSError* error = nil;
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
- if (error) {
- @throw error;
- }
- }
-
- path = [path stringByAppendingPathComponent:@"weight.plist"];
-
- if ([fileManager fileExistsAtPath:path]) {
- _weightCache = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
- } else {
- _weightCache = [[NSMutableDictionary alloc] initWithCapacity:0];
+ self = [super init];
+ if (self) {
+ // Weight PLIST File
+ NSString *path = [self getSharedFolder];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ if ([fileManager fileExistsAtPath:path] == NO) {
+ NSError* error = nil;
+ [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
+ if (error) {
+ @throw error;
}
- _phoneticCache = [[NSMutableDictionary alloc] initWithCapacity:0];
- _recentBaseCache = [[NSMutableDictionary alloc] initWithCapacity:0];
}
- return self;
+
+ path = [path stringByAppendingPathComponent:@"weight.plist"];
+
+ if ([fileManager fileExistsAtPath:path]) {
+ _weightCache = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
+ } else {
+ _weightCache = [[NSMutableDictionary alloc] initWithCapacity:0];
+ }
+ _phoneticCache = [[NSMutableDictionary alloc] initWithCapacity:0];
+ _recentBaseCache = [[NSMutableDictionary alloc] initWithCapacity:0];
}
+ return self;
}
- (void)dealloc {
- @synchronized(self) {
- [self persist];
- [_phoneticCache release];
- [_recentBaseCache release];
- [_weightCache release];
- [super dealloc];
- }
+ [self persist];
+ [_phoneticCache release];
+ [_recentBaseCache release];
+ [_weightCache release];
+ [super dealloc];
}
- (void)persist {
- @synchronized(self) {
- [_weightCache writeToFile:[[self getSharedFolder] stringByAppendingPathComponent:@"weight.plist"] atomically:YES];
- }
+ [_weightCache writeToFile:[[self getSharedFolder] stringByAppendingPathComponent:@"weight.plist"] atomically:YES];
}
- (NSString*)getSharedFolder {
- @synchronized(self) {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
- return [[[paths objectAtIndex:0]
- stringByAppendingPathComponent:@"OmicronLab"]
- stringByAppendingPathComponent:@"Avro Keyboard"];
- }
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ return [[[paths objectAtIndex:0]
+ stringByAppendingPathComponent:@"OmicronLab"]
+ stringByAppendingPathComponent:@"Avro Keyboard"];
}
// Weight Cache
- (NSString*)stringForKey:(NSString*)aKey {
- @synchronized(self) {
- return [_weightCache objectForKey:aKey];
- }
+ return [_weightCache objectForKey:aKey];
}
- (void)removeStringForKey:(NSString*)aKey {
- @synchronized(self) {
- [_weightCache removeObjectForKey:aKey];
- }
+ [_weightCache removeObjectForKey:aKey];
}
- (void)setString:(NSString*)aString forKey:(NSString*)aKey {
- @synchronized(self) {
- [_weightCache setObject:aString forKey:aKey];
- }
+ [_weightCache setObject:aString forKey:aKey];
}
// Phonetic Cache
- (NSArray*)arrayForKey:(NSString*)aKey {
- @synchronized(self) {
- return [_phoneticCache objectForKey:aKey];
- }
+ return [_phoneticCache objectForKey:aKey];
}
- (void)setArray:(NSArray*)anArray forKey:(NSString*)aKey {
- @synchronized(self) {
- [_phoneticCache setObject:anArray forKey:aKey];
- }
+ [_phoneticCache setObject:anArray forKey:aKey];
}
// Base Cache
-
- (void)removeAllBase {
- @synchronized(self) {
- [_recentBaseCache removeAllObjects];
- }
+ [_recentBaseCache removeAllObjects];
}
- (NSArray*)baseForKey:(NSString*)aKey {
- @synchronized(self) {
- return [_recentBaseCache objectForKey:aKey];
- }
+ return [_recentBaseCache objectForKey:aKey];
}
- (void)setBase:(NSArray*)aBase forKey:(NSString*)aKey {
- @synchronized(self) {
- [_recentBaseCache setObject:aBase forKey:aKey];
- }
+ [_recentBaseCache setObject:aBase forKey:aKey];
}
@end
View
14 Candidates.m
@@ -12,12 +12,14 @@
@implementation Candidates
+ (void)allocateSharedInstanceWithServer:(IMKServer *)server {
- _sharedInstance = [[self alloc] initWithServer:server panelType:kIMKSingleColumnScrollingCandidatePanel];
- [_sharedInstance setAttributes:[NSDictionary
- dictionaryWithObject:[NSNumber numberWithBool:YES]
- forKey:IMKCandidatesSendServerKeyEventFirst]];
-
- [_sharedInstance setDismissesAutomatically:NO];
+ if (_sharedInstance == nil) {
+ _sharedInstance = [[self alloc] initWithServer:server panelType:kIMKSingleColumnScrollingCandidatePanel];
+ [_sharedInstance setAttributes:[NSDictionary
+ dictionaryWithObject:[NSNumber numberWithBool:YES]
+ forKey:IMKCandidatesSendServerKeyEventFirst]];
+
+ [_sharedInstance setDismissesAutomatically:NO];
+ }
}
+ (void)deallocateSharedInstance {
View
457 Database.m
@@ -15,22 +15,17 @@
@implementation Database
+ (Database *)sharedInstance {
- @synchronized (self) {
- if (sharedInstance == nil) {
- [[self alloc] init]; // assignment not done here, see allocWithZone
- }
- }
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here, see allocWithZone
+ }
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
- @synchronized(self) {
- if (sharedInstance == nil) {
- sharedInstance = [super allocWithZone:zone];
- return sharedInstance; // assignment and return on first allocation
- }
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
}
-
return nil; //on subsequent allocation attempts return nil
}
@@ -55,253 +50,241 @@ - (NSUInteger)retainCount {
}
- (id)init {
- @synchronized(self) {
- self = [super init];
- if (self) {
- _db = [[NSMutableDictionary alloc] initWithCapacity:0];
- _suffix = [[NSMutableDictionary alloc] initWithCapacity:0];
-
- NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
-
- NSString* filePath = [[NSBundle mainBundle] pathForResource:@"database" ofType:@"db3"];
- FMDatabase *sqliteDb = [FMDatabase databaseWithPath:filePath];
- [sqliteDb open];
-
- [self loadTableWithName:@"A" fromDatabase:sqliteDb];
- [self loadTableWithName:@"AA" fromDatabase:sqliteDb];
- [self loadTableWithName:@"B" fromDatabase:sqliteDb];
- [self loadTableWithName:@"BH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"C" fromDatabase:sqliteDb];
- [self loadTableWithName:@"CH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"D" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Dd" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Ddh" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Dh" fromDatabase:sqliteDb];
- [self loadTableWithName:@"E" fromDatabase:sqliteDb];
- [self loadTableWithName:@"G" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Gh" fromDatabase:sqliteDb];
- [self loadTableWithName:@"H" fromDatabase:sqliteDb];
- [self loadTableWithName:@"I" fromDatabase:sqliteDb];
- [self loadTableWithName:@"II" fromDatabase:sqliteDb];
- [self loadTableWithName:@"J" fromDatabase:sqliteDb];
- [self loadTableWithName:@"JH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"K" fromDatabase:sqliteDb];
- [self loadTableWithName:@"KH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Khandatta" fromDatabase:sqliteDb];
- [self loadTableWithName:@"L" fromDatabase:sqliteDb];
- [self loadTableWithName:@"M" fromDatabase:sqliteDb];
- [self loadTableWithName:@"N" fromDatabase:sqliteDb];
- [self loadTableWithName:@"NGA" fromDatabase:sqliteDb];
- [self loadTableWithName:@"NN" fromDatabase:sqliteDb];
- [self loadTableWithName:@"NYA" fromDatabase:sqliteDb];
- [self loadTableWithName:@"O" fromDatabase:sqliteDb];
- [self loadTableWithName:@"OI" fromDatabase:sqliteDb];
- [self loadTableWithName:@"OU" fromDatabase:sqliteDb];
- [self loadTableWithName:@"P" fromDatabase:sqliteDb];
- [self loadTableWithName:@"PH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"R" fromDatabase:sqliteDb];
- [self loadTableWithName:@"RR" fromDatabase:sqliteDb];
- [self loadTableWithName:@"RRH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"RRI" fromDatabase:sqliteDb];
- [self loadTableWithName:@"S" fromDatabase:sqliteDb];
- [self loadTableWithName:@"SH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"SS" fromDatabase:sqliteDb];
- [self loadTableWithName:@"T" fromDatabase:sqliteDb];
- [self loadTableWithName:@"TH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"TT" fromDatabase:sqliteDb];
- [self loadTableWithName:@"TTH" fromDatabase:sqliteDb];
- [self loadTableWithName:@"U" fromDatabase:sqliteDb];
- [self loadTableWithName:@"UU" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Y" fromDatabase:sqliteDb];
- [self loadTableWithName:@"Z" fromDatabase:sqliteDb];
-
- [self loadSuffixTableFromDatabase:sqliteDb];
-
- [sqliteDb close];
-
- [loopPool release];
- }
- return self;
+ self = [super init];
+ if (self) {
+ _db = [[NSMutableDictionary alloc] initWithCapacity:0];
+ _suffix = [[NSMutableDictionary alloc] initWithCapacity:0];
+
+ NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
+
+ NSString* filePath = [[NSBundle mainBundle] pathForResource:@"database" ofType:@"db3"];
+ FMDatabase *sqliteDb = [FMDatabase databaseWithPath:filePath];
+ [sqliteDb open];
+
+ [self loadTableWithName:@"A" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"AA" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"B" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"BH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"C" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"CH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"D" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Dd" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Ddh" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Dh" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"E" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"G" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Gh" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"H" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"I" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"II" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"J" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"JH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"K" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"KH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Khandatta" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"L" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"M" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"N" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"NGA" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"NN" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"NYA" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"O" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"OI" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"OU" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"P" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"PH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"R" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"RR" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"RRH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"RRI" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"S" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"SH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"SS" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"T" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"TH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"TT" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"TTH" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"U" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"UU" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Y" fromDatabase:sqliteDb];
+ [self loadTableWithName:@"Z" fromDatabase:sqliteDb];
+
+ [self loadSuffixTableFromDatabase:sqliteDb];
+
+ [sqliteDb close];
+
+ [loopPool release];
}
+ return self;
}
- (void)dealloc {
- @synchronized(self) {
- [_db release];
- [_suffix release];
- [super dealloc];
- }
+ [_db release];
+ [_suffix release];
+ [super dealloc];
}
- (void)loadTableWithName:(NSString*)name fromDatabase:(FMDatabase*)sqliteDb {
- @synchronized(self) {
- NSMutableArray* items = [[NSMutableArray alloc] init];
-
- FMResultSet *results = [sqliteDb executeQuery:[NSString stringWithFormat:@"SELECT * FROM %@", name]];
- while([results next]) {
- [items addObject:[results stringForColumn:@"Words"]];
- }
-
- /*
- NSLog(@"-----------------------------------------------------------------");
- NSLog(@"%d items added to key %@", count, name);
- NSLog(@"-----------------------------------------------------------------");
- */
-
- [_db setObject:items forKey:[name lowercaseString]];
-
- [results close];
- [items release];
+ NSMutableArray* items = [[NSMutableArray alloc] init];
+
+ FMResultSet *results = [sqliteDb executeQuery:[NSString stringWithFormat:@"SELECT * FROM %@", name]];
+ while([results next]) {
+ [items addObject:[results stringForColumn:@"Words"]];
}
+
+ /*
+ NSLog(@"-----------------------------------------------------------------");
+ NSLog(@"%d items added to key %@", count, name);
+ NSLog(@"-----------------------------------------------------------------");
+ */
+
+ [_db setObject:items forKey:[name lowercaseString]];
+
+ [results close];
+ [items release];
}
- (void)loadSuffixTableFromDatabase:(FMDatabase*)sqliteDb {
- @synchronized(self) {
- FMResultSet *results = [sqliteDb executeQuery:[NSString stringWithFormat:@"SELECT * FROM Suffix"]];
- while([results next]) {
- [_suffix setObject:[results stringForColumn:@"Bangla"] forKey:[results stringForColumn:@"English"]];
- }
- [results close];
+ FMResultSet *results = [sqliteDb executeQuery:[NSString stringWithFormat:@"SELECT * FROM Suffix"]];
+ while([results next]) {
+ [_suffix setObject:[results stringForColumn:@"Bangla"] forKey:[results stringForColumn:@"English"]];
}
+ [results close];
}
- (NSArray*)find:(NSString*)term {
- @synchronized(self) {
- // Left Most Character
- unichar lmc = [[term lowercaseString] characterAtIndex:0];
- NSString* regex = [NSString stringWithFormat:@"^%@$", [[RegexParser sharedInstance] parse:term]];
- NSMutableArray* tableList = [[NSMutableArray alloc] initWithCapacity:0];
- NSMutableSet* suggestions = [[NSMutableSet alloc] initWithCapacity:0];
-
- switch (lmc) {
- case 'a':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"a", @"aa", @"e", @"oi", @"o", @"nya", @"y", nil]];
- break;
- case 'b':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"b", @"bh", nil]];
- break;
- case 'c':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"c", @"ch", @"k", nil]];
- break;
- case 'd':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"d", @"dh", @"dd", @"ddh", nil]];
- break;
- case 'e':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"i", @"ii", @"e", @"y", nil]];
- break;
- case 'f':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"ph", nil]];
- break;
- case 'g':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"g", @"gh", @"j", nil]];
- break;
- case 'h':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"h", nil]];
- break;
- case 'i':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"i", @"ii", @"y", nil]];
- break;
- case 'j':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"j", @"jh", @"z", nil]];
- break;
- case 'k':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"k", @"kh", nil]];
- break;
- case 'l':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"l", nil]];
- break;
- case 'm':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"h", @"m", nil]];
- break;
- case 'n':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"n", @"nya", @"nga", @"nn", nil]];
- break;
- case 'o':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"a", @"u", @"uu", @"oi", @"o", @"ou", @"y", nil]];
- break;
- case 'p':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"p", @"ph", nil]];
- break;
- case 'q':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"k", nil]];
- break;
- case 'r':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"rri", @"h", @"r", @"rr", @"rrh", nil]];
- break;
- case 's':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"s", @"sh", @"ss", nil]];
- break;
- case 't':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"t", @"th", @"tt", @"tth", @"khandatta", nil]];
- break;
- case 'u':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"u", @"uu", @"y", nil]];
- break;
- case 'v':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"bh", nil]];
- break;
- case 'w':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"o", nil]];
- break;
- case 'x':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"e", @"k", nil]];
- break;
- case 'y':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"i", @"y", nil]];
- break;
- case 'z':
- [tableList addObjectsFromArray:
- [NSArray arrayWithObjects:@"h", @"j", @"jh", @"z", nil]];
- break;
- default:
- break;
- }
-
- for (NSString* table in tableList) {
- NSArray* tableData = [_db objectForKey:table];
- for (NSString* tmpString in tableData) {
- if ([tmpString isMatchedByRegex:regex]) {
- [suggestions addObject:tmpString];
- }
+ // Left Most Character
+ unichar lmc = [[term lowercaseString] characterAtIndex:0];
+ NSString* regex = [NSString stringWithFormat:@"^%@$", [[RegexParser sharedInstance] parse:term]];
+ NSMutableArray* tableList = [[NSMutableArray alloc] initWithCapacity:0];
+ NSMutableSet* suggestions = [[NSMutableSet alloc] initWithCapacity:0];
+
+ switch (lmc) {
+ case 'a':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"a", @"aa", @"e", @"oi", @"o", @"nya", @"y", nil]];
+ break;
+ case 'b':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"b", @"bh", nil]];
+ break;
+ case 'c':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"c", @"ch", @"k", nil]];
+ break;
+ case 'd':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"d", @"dh", @"dd", @"ddh", nil]];
+ break;
+ case 'e':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"i", @"ii", @"e", @"y", nil]];
+ break;
+ case 'f':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"ph", nil]];
+ break;
+ case 'g':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"g", @"gh", @"j", nil]];
+ break;
+ case 'h':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"h", nil]];
+ break;
+ case 'i':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"i", @"ii", @"y", nil]];
+ break;
+ case 'j':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"j", @"jh", @"z", nil]];
+ break;
+ case 'k':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"k", @"kh", nil]];
+ break;
+ case 'l':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"l", nil]];
+ break;
+ case 'm':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"h", @"m", nil]];
+ break;
+ case 'n':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"n", @"nya", @"nga", @"nn", nil]];
+ break;
+ case 'o':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"a", @"u", @"uu", @"oi", @"o", @"ou", @"y", nil]];
+ break;
+ case 'p':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"p", @"ph", nil]];
+ break;
+ case 'q':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"k", nil]];
+ break;
+ case 'r':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"rri", @"h", @"r", @"rr", @"rrh", nil]];
+ break;
+ case 's':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"s", @"sh", @"ss", nil]];
+ break;
+ case 't':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"t", @"th", @"tt", @"tth", @"khandatta", nil]];
+ break;
+ case 'u':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"u", @"uu", @"y", nil]];
+ break;
+ case 'v':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"bh", nil]];
+ break;
+ case 'w':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"o", nil]];
+ break;
+ case 'x':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"e", @"k", nil]];
+ break;
+ case 'y':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"i", @"y", nil]];
+ break;
+ case 'z':
+ [tableList addObjectsFromArray:
+ [NSArray arrayWithObjects:@"h", @"j", @"jh", @"z", nil]];
+ break;
+ default:
+ break;
+ }
+
+ for (NSString* table in tableList) {
+ NSArray* tableData = [_db objectForKey:table];
+ for (NSString* tmpString in tableData) {
+ if ([tmpString isMatchedByRegex:regex]) {
+ [suggestions addObject:tmpString];
}
}
-
- [tableList release];
- [suggestions autorelease];
-
- return [suggestions allObjects];
}
+
+ [tableList release];
+ [suggestions autorelease];
+
+ return [suggestions allObjects];
}
- (NSString*)banglaForSuffix:(NSString*)suffix {
- @synchronized(self) {
- return [_suffix objectForKey:suffix];
- }
+ return [_suffix objectForKey:suffix];
}
@end
View
419 RegexParser.m
@@ -12,22 +12,18 @@
@implementation RegexParser
+ (RegexParser *)sharedInstance {
- @synchronized (self) {
- if (sharedInstance == nil) {
- [[self alloc] init]; // assignment not done here, see allocWithZone
- }
- }
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here, see allocWithZone
+ }
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
- @synchronized(self) {
- if (sharedInstance == nil) {
- sharedInstance = [super allocWithZone:zone];
- return sharedInstance; // assignment and return on first allocation
- }
+
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
}
-
return nil; //on subsequent allocation attempts return nil
}
@@ -52,275 +48,256 @@ - (NSUInteger)retainCount {
}
- (id)init {
- @synchronized(self) {
- self = [super init];
- if (self) {
- NSError *error = nil;
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"regex" ofType:@"json"];
- NSData *jsonData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error: &error];
+ self = [super init];
+ if (self) {
+ NSError *error = nil;
+ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"regex" ofType:@"json"];
+ NSData *jsonData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error: &error];
+
+ if (jsonData) {
- if (jsonData) {
-
- NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error: &error];
-
- if (!jsonArray) {
- @throw error;
- } else {
- _vowel = [[NSString alloc] initWithString:[jsonArray objectForKey:@"vowel"]];
- _consonant = [[NSString alloc] initWithString:[jsonArray objectForKey:@"consonant"]];
- _casesensitive = [[NSString alloc] initWithString:[jsonArray objectForKey:@"casesensitive"]];
- _patterns = [[NSArray alloc] initWithArray:[jsonArray objectForKey:@"patterns"]];
- _maxPatternLength = [[[_patterns objectAtIndex:0] objectForKey:@"find"] length];
- }
-
- } else {
+ NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error: &error];
+
+ if (!jsonArray) {
@throw error;
+ } else {
+ _vowel = [[NSString alloc] initWithString:[jsonArray objectForKey:@"vowel"]];
+ _consonant = [[NSString alloc] initWithString:[jsonArray objectForKey:@"consonant"]];
+ _casesensitive = [[NSString alloc] initWithString:[jsonArray objectForKey:@"casesensitive"]];
+ _patterns = [[NSArray alloc] initWithArray:[jsonArray objectForKey:@"patterns"]];
+ _maxPatternLength = [[[_patterns objectAtIndex:0] objectForKey:@"find"] length];
}
+
+ } else {
+ @throw error;
}
- return self;
}
+ return self;
}
- (void)dealloc {
- @synchronized(self) {
- [_vowel release];
- [_consonant release];
- [_casesensitive release];
- [_patterns release];
-
- [super dealloc];
- }
+ [_vowel release];
+ [_consonant release];
+ [_casesensitive release];
+ [_patterns release];
+
+ [super dealloc];
}
- (NSString*)parse:(NSString *)string {
- @synchronized(self) {
- if (!string || [string length] == 0) {
- return string;
- }
-
- NSString* fixed = [self clean:string];
- NSMutableString* output = [[NSMutableString alloc] initWithCapacity:0];
+ if (!string || [string length] == 0) {
+ return string;
+ }
+
+ NSString* fixed = [self clean:string];
+ NSMutableString* output = [[NSMutableString alloc] initWithCapacity:0];
+
+ int len = [fixed length], cur;
+ for(cur = 0; cur < len; ++cur) {
+ int start = cur, end;
+ BOOL matched = FALSE;
- int len = [fixed length], cur;
- for(cur = 0; cur < len; ++cur) {
- int start = cur, end;
- BOOL matched = FALSE;
-
- int chunkLen;
- for(chunkLen = _maxPatternLength; chunkLen > 0; --chunkLen) {
- end = start + chunkLen;
- if(end <= len) {
- NSString* chunk = [fixed substringWithRange:NSMakeRange(start, chunkLen)];
-
- // Binary Search
- int left = 0, right = [_patterns count] - 1, mid;
- while(right >= left) {
- mid = (right + left) / 2;
- NSDictionary* pattern = [_patterns objectAtIndex:mid];
- NSString* find = [pattern objectForKey:@"find"];
- if([find isEqualToString:chunk]) {
- NSArray* rules = [pattern objectForKey:@"rules"];
- for(NSDictionary* rule in rules) {
+ int chunkLen;
+ for(chunkLen = _maxPatternLength; chunkLen > 0; --chunkLen) {
+ end = start + chunkLen;
+ if(end <= len) {
+ NSString* chunk = [fixed substringWithRange:NSMakeRange(start, chunkLen)];
+
+ // Binary Search
+ int left = 0, right = [_patterns count] - 1, mid;
+ while(right >= left) {
+ mid = (right + left) / 2;
+ NSDictionary* pattern = [_patterns objectAtIndex:mid];
+ NSString* find = [pattern objectForKey:@"find"];
+ if([find isEqualToString:chunk]) {
+ NSArray* rules = [pattern objectForKey:@"rules"];
+ for(NSDictionary* rule in rules) {
+
+ BOOL replace = TRUE;
+ int chk = 0;
+ NSArray* matches = [rule objectForKey:@"matches"];
+ for(NSDictionary* match in matches) {
+ NSString* value = [match objectForKey:@"value"];
+ NSString* type = [match objectForKey:@"type"];
+ NSString* scope = [match objectForKey:@"scope"];
+ BOOL isNegative = [[match objectForKey:@"negative"] boolValue];
+
+ if([type isEqualToString:@"suffix"]) {
+ chk = end;
+ }
+ // Prefix
+ else {
+ chk = start - 1;
+ }
- BOOL replace = TRUE;
- int chk = 0;
- NSArray* matches = [rule objectForKey:@"matches"];
- for(NSDictionary* match in matches) {
- NSString* value = [match objectForKey:@"value"];
- NSString* type = [match objectForKey:@"type"];
- NSString* scope = [match objectForKey:@"scope"];
- BOOL isNegative = [[match objectForKey:@"negative"] boolValue];
-
+ // Beginning
+ if([scope isEqualToString:@"punctuation"]) {
+ if(
+ ! (
+ (chk < 0 && [type isEqualToString:@"prefix"]) ||
+ (chk >= len && [type isEqualToString:@"suffix"]) ||
+ [self isPunctuation:[fixed characterAtIndex:chk]]
+ ) ^ isNegative
+ ) {
+ replace = FALSE;
+ break;
+ }
+ }
+ // Vowel
+ else if([scope isEqualToString:@"vowel"]) {
+ if(
+ ! (
+ (
+ (chk >= 0 && [type isEqualToString:@"prefix"]) ||
+ (chk < len && [type isEqualToString:@"suffix"])
+ ) &&
+ [self isVowel:[fixed characterAtIndex:chk]]
+ ) ^ isNegative
+ ) {
+ replace = FALSE;
+ break;
+ }
+ }
+ // Consonant
+ else if([scope isEqualToString:@"consonant"]) {
+ if(
+ ! (
+ (
+ (chk >= 0 && [type isEqualToString:@"prefix"]) ||
+ (chk < len && [type isEqualToString:@"suffix"])
+ ) &&
+ [self isConsonant:[fixed characterAtIndex:chk]]
+ ) ^ isNegative
+ ) {
+ replace = FALSE;
+ break;
+ }
+ }
+ // Exact
+ else if([scope isEqualToString:@"exact"]) {
+ int s, e;
if([type isEqualToString:@"suffix"]) {
- chk = end;
+ s = end;
+ e = end + [value length];
}
// Prefix
else {
- chk = start - 1;
- }
-
- // Beginning
- if([scope isEqualToString:@"punctuation"]) {
- if(
- ! (
- (chk < 0 && [type isEqualToString:@"prefix"]) ||
- (chk >= len && [type isEqualToString:@"suffix"]) ||
- [self isPunctuation:[fixed characterAtIndex:chk]]
- ) ^ isNegative
- ) {
- replace = FALSE;
- break;
- }
- }
- // Vowel
- else if([scope isEqualToString:@"vowel"]) {
- if(
- ! (
- (
- (chk >= 0 && [type isEqualToString:@"prefix"]) ||
- (chk < len && [type isEqualToString:@"suffix"])
- ) &&
- [self isVowel:[fixed characterAtIndex:chk]]
- ) ^ isNegative
- ) {
- replace = FALSE;
- break;
- }
- }
- // Consonant
- else if([scope isEqualToString:@"consonant"]) {
- if(
- ! (
- (
- (chk >= 0 && [type isEqualToString:@"prefix"]) ||
- (chk < len && [type isEqualToString:@"suffix"])
- ) &&
- [self isConsonant:[fixed characterAtIndex:chk]]
- ) ^ isNegative
- ) {
- replace = FALSE;
- break;
- }
+ s = start - [value length];
+ e = start;
}
- // Exact
- else if([scope isEqualToString:@"exact"]) {
- int s, e;
- if([type isEqualToString:@"suffix"]) {
- s = end;
- e = end + [value length];
- }
- // Prefix
- else {
- s = start - [value length];
- e = start;
- }
- if(![self isExact:value heystack:fixed start:s end:e not:isNegative]) {
- replace = FALSE;
- break;
- }
+ if(![self isExact:value heystack:fixed start:s end:e not:isNegative]) {
+ replace = FALSE;
+ break;
}
}
-
- if(replace) {
- [output appendString:[rule objectForKey:@"replace"]];
- [output appendString:@"(্[যবম])?(্?)([ঃঁ]?)"];
- cur = end - 1;
- matched = TRUE;
- break;
- }
-
}
- if(matched == TRUE) break;
+ if(replace) {
+ [output appendString:[rule objectForKey:@"replace"]];
+ [output appendString:@"(্[যবম])?(্?)([ঃঁ]?)"];
+ cur = end - 1;
+ matched = TRUE;
+ break;
+ }
- // Default
- [output appendString:[pattern objectForKey:@"replace"]];
- [output appendString:@"(্[যবম])?(্?)([ঃঁ]?)"];
- cur = end - 1;
- matched = TRUE;
- break;
- }
- else if ([find length] > [chunk length] ||
- ([find length] == [chunk length] && [find compare:chunk] == NSOrderedAscending)) {
- left = mid + 1;
- } else {
- right = mid - 1;
}
+
+ if(matched == TRUE) break;
+
+ // Default
+ [output appendString:[pattern objectForKey:@"replace"]];
+ [output appendString:@"(্[যবম])?(্?)([ঃঁ]?)"];
+ cur = end - 1;
+ matched = TRUE;
+ break;
+ }
+ else if ([find length] > [chunk length] ||
+ ([find length] == [chunk length] && [find compare:chunk] == NSOrderedAscending)) {
+ left = mid + 1;
+ } else {
+ right = mid - 1;
}
- if(matched == TRUE) break;
}
+ if(matched == TRUE) break;
}
-
- if(!matched) {
- unichar oldChar = [fixed characterAtIndex:cur];
- [output appendString:[NSString stringWithCharacters:&oldChar length:1]];
- }
- // NSLog(@"cur: %s, start: %s, end: %s, prev: %s\n", cur, start, end, prev);
}
- [output autorelease];
-
- return output;
+ if(!matched) {
+ unichar oldChar = [fixed characterAtIndex:cur];
+ [output appendString:[NSString stringWithCharacters:&oldChar length:1]];
+ }
+ // NSLog(@"cur: %s, start: %s, end: %s, prev: %s\n", cur, start, end, prev);
}
+
+ [output autorelease];
+
+ return output;
}
- (BOOL)isVowel:(unichar)c {
- @synchronized(self) {
- // Making it lowercase for checking
- c = [self smallCap:c];
- int i, len = [_vowel length];
- for (i = 0; i < len; ++i) {
- if ([_vowel characterAtIndex:i] == c) {
- return TRUE;
- }
+ // Making it lowercase for checking
+ c = [self smallCap:c];
+ int i, len = [_vowel length];
+ for (i = 0; i < len; ++i) {
+ if ([_vowel characterAtIndex:i] == c) {
+ return TRUE;
}
- return FALSE;
}
+ return FALSE;
}
- (BOOL)isConsonant:(unichar)c {
- @synchronized(self) {
- // Making it lowercase for checking
- c = [self smallCap:c];
- int i, len = [_consonant length];
- for (i = 0; i < len; ++i) {
- if ([_consonant characterAtIndex:i] == c) {
- return TRUE;
- }
+ // Making it lowercase for checking
+ c = [self smallCap:c];
+ int i, len = [_consonant length];
+ for (i = 0; i < len; ++i) {
+ if ([_consonant characterAtIndex:i] == c) {
+ return TRUE;
}
- return FALSE;
}
+ return FALSE;
}
- (BOOL)isPunctuation:(unichar)c {
- @synchronized(self) {
- return !([self isVowel:c] || [self isConsonant:c]);
- }
+ return !([self isVowel:c] || [self isConsonant:c]);
}
- (BOOL)isCaseSensitive:(unichar)c {
- @synchronized(self) {
- // Making it lowercase for checking
- c = [self smallCap:c];
- int i, len = [_casesensitive length];
- for (i = 0; i < len; ++i) {
- if ([_casesensitive characterAtIndex:i] == c) {
- return TRUE;
- }
+ // Making it lowercase for checking
+ c = [self smallCap:c];
+ int i, len = [_casesensitive length];
+ for (i = 0; i < len; ++i) {
+ if ([_casesensitive characterAtIndex:i] == c) {
+ return TRUE;
}
- return FALSE;
}
+ return FALSE;
}
- (BOOL)isExact:(NSString*) needle heystack:(NSString*)heystack start:(int)start end:(int)end not:(BOOL)not {
- @synchronized(self) {
- int len = end - start;
- return ((start >= 0 && end < [heystack length]
- && [[heystack substringWithRange:NSMakeRange(start, len)] isEqualToString:needle]) ^ not);
- }
+ int len = end - start;
+ return ((start >= 0 && end < [heystack length]
+ && [[heystack substringWithRange:NSMakeRange(start, len)] isEqualToString:needle]) ^ not);
}
- (unichar)smallCap:(unichar) letter {
- @synchronized(self) {
- if(letter >= 'A' && letter <= 'Z') {
- letter = letter - 'A' + 'a';
- }
- return letter;
+ if(letter >= 'A' && letter <= 'Z') {
+ letter = letter - 'A' + 'a';
}
+ return letter;
}
- (NSString*)clean:(NSString *)string {
- @synchronized(self) {
- NSMutableString* fixed = [[NSMutableString alloc] initWithCapacity:0];
- int i, len = [string length];
- for (i = 0; i < len; ++i) {
- unichar c = [string characterAtIndex:i];
- if (![self isCaseSensitive:c]) {
- [fixed appendFormat:@"%C", [self smallCap:c]];
- }
+ NSMutableString* fixed = [[NSMutableString alloc] initWithCapacity:0];
+ int i, len = [string length];
+ for (i = 0; i < len; ++i) {
+ unichar c = [string characterAtIndex:i];
+ if (![self isCaseSensitive:c]) {
+ [fixed appendFormat:@"%C", [self smallCap:c]];
}
- [fixed autorelease];
- return fixed;
}
+ [fixed autorelease];
+ return fixed;
}
+
@end
View
236 Suggestion.m
@@ -19,22 +19,18 @@
@implementation Suggestion
+ (Suggestion *)sharedInstance {
- @synchronized (self) {
- if (sharedInstance == nil) {
- [[self alloc] init]; // assignment not done here, see allocWithZone
- }
- }
+ if (sharedInstance == nil) {
+ [[self alloc] init]; // assignment not done here, see allocWithZone
+ }
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
- @synchronized(self) {
- if (sharedInstance == nil) {
- sharedInstance = [super allocWithZone:zone];
- return sharedInstance; // assignment and return on first allocation
- }
+
+ if (sharedInstance == nil) {
+ sharedInstance = [super allocWithZone:zone];
+ return sharedInstance; // assignment and return on first allocation
}
-
return nil; //on subsequent allocation attempts return nil
}
@@ -59,148 +55,138 @@ - (NSUInteger)retainCount {
}
- (id)init {
- @synchronized(self) {
- self = [super init];
- if (self) {
- _suggestions = [[NSMutableArray alloc] initWithCapacity:0];
- }
- return self;
+ self = [super init];
+ if (self) {
+ _suggestions = [[NSMutableArray alloc] initWithCapacity:0];
}
+ return self;
}
- (void)dealloc {
- @synchronized(self) {
- [_suggestions release];
- [super dealloc];
- }
+ [_suggestions release];
+ [super dealloc];
}
- (NSMutableArray*)getList:(NSString*)term {
- @synchronized(self) {
- if (term && [term length] == 0) {
- return _suggestions;
+ if (term && [term length] == 0) {
+ return _suggestions;
+ }
+
+ // Suggestions from Default Parser
+ NSString* paresedString = [[AvroParser sharedInstance] parse:term];
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"IncludeDictionary"]) {
+ // Saving humanity by reducing a few CPU cycles
+ [_suggestions addObjectsFromArray:[[CacheManager sharedInstance] arrayForKey:term]];
+ if (_suggestions && [_suggestions count] == 0) {
+ // Suggestions form AutoCorrect
+ NSString* autoCorrect = [[AutoCorrect sharedInstance] find:term];
+ if (autoCorrect) {
+ [_suggestions addObject:autoCorrect];
+ }
+
+ // Suggestions from Dictionary
+ NSArray* dicList = [[Database sharedInstance] find:term];
+ if (dicList) {
+ // Remove autoCorrect if it is already in the dictionary
+ // PROPOSAL: don't add the autoCorrect, which matches with the dictionary entry
+ if (autoCorrect && [dicList containsObject:autoCorrect]) {
+ [_suggestions removeObjectIdenticalTo:autoCorrect];
+ }
+ // Sort dicList based on edit distance
+ NSArray* sortedDicList = [dicList sortedArrayUsingComparator:^NSComparisonResult(id left, id right) {
+ int dist1 = [paresedString computeLevenshteinDistanceWithString:(NSString*)left];
+ int dist2 = [paresedString computeLevenshteinDistanceWithString:(NSString*)right];
+ if (dist1 < dist2) {
+ return NSOrderedAscending;
+ }
+ else if (dist1 > dist2) {
+ return NSOrderedDescending;
+ } else {
+ return NSOrderedSame;
+ }
+ }];
+ [_suggestions addObjectsFromArray:sortedDicList];
+ }
+
+ [[CacheManager sharedInstance] setArray:[[_suggestions copy] autorelease] forKey:term];
}
- // Suggestions from Default Parser
- NSString* paresedString = [[AvroParser sharedInstance] parse:term];
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"IncludeDictionary"]) {
- // Saving humanity by reducing a few CPU cycles
- [_suggestions addObjectsFromArray:[[CacheManager sharedInstance] arrayForKey:term]];
- if (_suggestions && [_suggestions count] == 0) {
- // Suggestions form AutoCorrect
- NSString* autoCorrect = [[AutoCorrect sharedInstance] find:term];
- if (autoCorrect) {
- [_suggestions addObject:autoCorrect];
+ // Suggestions with Suffix
+ int i;
+ BOOL alreadySelected = FALSE;
+ [[CacheManager sharedInstance] removeAllBase];
+ for (i = [term length]-1; i > 0; --i) {
+ NSString* suffix = [[Database sharedInstance] banglaForSuffix:[[term substringFromIndex:i] lowercaseString]];
+ if (suffix) {
+ NSString* base = [term substringToIndex:i];
+ NSArray* cached = [[CacheManager sharedInstance] arrayForKey:base];
+ NSString* selected;
+ if (!alreadySelected) {
+ // Base user selection
+ selected = [[CacheManager sharedInstance] stringForKey:base];
}
-
- // Suggestions from Dictionary
- NSArray* dicList = [[Database sharedInstance] find:term];
- if (dicList) {
- // Remove autoCorrect if it is already in the dictionary
- // PROPOSAL: don't add the autoCorrect, which matches with the dictionary entry
- if (autoCorrect && [dicList containsObject:autoCorrect]) {
- [_suggestions removeObjectIdenticalTo:autoCorrect];
- }
- // Sort dicList based on edit distance
- NSArray* sortedDicList = [dicList sortedArrayUsingComparator:^NSComparisonResult(id left, id right) {
- int dist1 = [paresedString computeLevenshteinDistanceWithString:(NSString*)left];
- int dist2 = [paresedString computeLevenshteinDistanceWithString:(NSString*)right];
- if (dist1 < dist2) {
- return NSOrderedAscending;
+ // This should always exist, so it's just a safety check
+ if (cached) {
+ for (NSString *item in cached) {
+ // Skip AutoCorrect English Entry
+ if ([base isEqualToString:item]) {
+ continue;
}
- else if (dist1 > dist2) {
- return NSOrderedDescending;
- } else {
- return NSOrderedSame;
+ NSString* word;
+ // Again saving humanity cause I'm Superman, no I'm not drunk or on weed :D
+ int cutPos = [item length] - 1;
+
+ NSString* itemRMC = [item substringFromIndex:cutPos]; // RMC is Right Most Character
+ NSString* suffixLMC = [suffix substringToIndex:1]; // LMC is Left Most Character
+ // BEGIN :: This part was taken from http://d.pr/zTmF
+ if ([self isVowel:itemRMC] && [self isKar:suffixLMC]) {
+ word = [NSString stringWithFormat:@"%@\u09df%@", item ,suffix];
}
- }];
- [_suggestions addObjectsFromArray:sortedDicList];
- }
-
- [[CacheManager sharedInstance] setArray:[[_suggestions copy] autorelease] forKey:term];
- }
-
- // Suggestions with Suffix
- int i;
- BOOL alreadySelected = FALSE;
- [[CacheManager sharedInstance] removeAllBase];
- for (i = [term length]-1; i > 0; --i) {
- NSString* suffix = [[Database sharedInstance] banglaForSuffix:[[term substringFromIndex:i] lowercaseString]];
- if (suffix) {
- NSString* base = [term substringToIndex:i];
- 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) {
- // Skip AutoCorrect English Entry
- if ([base isEqualToString:item]) {
- continue;
+ else {
+ if ([itemRMC isEqualToString:@"\u09ce"]) {
+ word = [NSString stringWithFormat:@"%@\u09a4%@", [item substringToIndex:cutPos], suffix];
}
- NSString* word;
- // Again saving humanity cause I'm Superman, no I'm not drunk or on weed :D
- int cutPos = [item length] - 1;
-
- NSString* itemRMC = [item substringFromIndex:cutPos]; // RMC is Right Most Character
- NSString* suffixLMC = [suffix substringToIndex:1]; // LMC is Left Most Character
- // BEGIN :: This part was taken from http://d.pr/zTmF
- if ([self isVowel:itemRMC] && [self isKar:suffixLMC]) {
- word = [NSString stringWithFormat:@"%@\u09df%@", item ,suffix];
+ else if ([itemRMC isEqualToString:@"\u0982"]) {
+ word = [NSString stringWithFormat:@"%@\u0999%@", [item substringToIndex:cutPos], suffix];
+ } else {
+ word = [NSString stringWithFormat:@"%@%@", item, suffix];
}
- else {
- if ([itemRMC isEqualToString:@"\u09ce"]) {
- word = [NSString stringWithFormat:@"%@\u09a4%@", [item substringToIndex:cutPos], suffix];
- }
- else if ([itemRMC isEqualToString:@"\u0982"]) {
- word = [NSString stringWithFormat:@"%@\u0999%@", [item substringToIndex:cutPos], suffix];
- } else {
- word = [NSString stringWithFormat:@"%@%@", item, suffix];
- }
- }
- // END
-
- // Reverse Suffix Caching
- [[CacheManager sharedInstance] setBase:[NSArray arrayWithObjects:base, item, nil] forKey:word];
-
- // Check that the WORD is not already in the list
- if (![_suggestions containsObject:word]) {
- // Intelligent Selection
- if (!alreadySelected && selected && [item isEqualToString:selected]) {
- if (![[CacheManager sharedInstance] stringForKey:term]) {
- [[CacheManager sharedInstance] setString:word forKey:term];
- }
- alreadySelected = TRUE;
+ }
+ // END
+
+ // Reverse Suffix Caching
+ [[CacheManager sharedInstance] setBase:[NSArray arrayWithObjects:base, item, nil] forKey:word];
+
+ // Check that the WORD is not already in the list
+ if (![_suggestions containsObject:word]) {
+ // Intelligent Selection
+ if (!alreadySelected && selected && [item isEqualToString:selected]) {
+ if (![[CacheManager sharedInstance] stringForKey:term]) {
+ [[CacheManager sharedInstance] setString:word forKey:term];
}
- [_suggestions addObject:word];
+ alreadySelected = TRUE;
}
+ [_suggestions addObject:word];
}
}
}
}
}
-
- if ([_suggestions containsObject:paresedString] == NO) {
- [_suggestions addObject:paresedString];
- }
-
- return _suggestions;
}
+
+ if ([_suggestions containsObject:paresedString] == NO) {
+ [_suggestions addObject:paresedString];
+ }
+
+ return _suggestions;
}
- (BOOL)isKar:(NSString*)letter {
- @synchronized(self) {
- return [letter isMatchedByRegex:@"^[\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c7\u09c8\u09cb\u09cc\u09c4]$"];
- }
+ return [letter isMatchedByRegex:@"^[\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c7\u09c8\u09cb\u09cc\u09c4]$"];
}
- (BOOL)isVowel:(NSString*)letter {
- @synchronized(self) {
- return [letter isMatchedByRegex:@"^[\u0985\u0986\u0987\u0988\u0989\u098a\u098b\u098f\u0990\u0993\u0994\u098c\u09e1\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c7\u09c8\u09cb\u09cc]$"];
- }
+ return [letter isMatchedByRegex:@"^[\u0985\u0986\u0987\u0988\u0989\u098a\u098b\u098f\u0990\u0993\u0994\u098c\u09e1\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c7\u09c8\u09cb\u09cc]$"];
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.