// Basic test of some LSM framework features, by Nathan Vander Wilt // Public domain #import #import // gcc -framework Cocoa -framework LatentSemanticMapping lsmtest.m -o test_lsm int main() { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; LSMMapRef map = LSMMapCreate(NULL, 0); LSMCategory good_category = LSMMapAddCategory(map); LSMCategory bad_category = LSMMapAddCategory(map); LSMTextRef good_sample = LSMTextCreate(NULL, map); LSMTextRef bad_sample = LSMTextCreate(NULL, map); LSMTextAddWords(good_sample, (CFStringRef)@"happy nice nerdy", NULL, 0); LSMTextAddWords(bad_sample, (CFStringRef)@"bad ugly nerdy gross", NULL, 0); LSMTextAddWords(good_sample, (CFStringRef)@"wonderful excellent nerdy", NULL, 0); LSMTextAddWords(bad_sample, (CFStringRef)@"death taxes", NULL, 0); OSStatus err; err = LSMMapAddText(map, good_sample, good_category); if (err) NSLog(@"Error adding %i", err); err = LSMMapAddText(map, bad_sample, bad_category); if (err) NSLog(@"Error adding %i", err); err = LSMMapCompile(map); if (err) NSLog(@"Error compiling %i", err); /* this was to test states err = LSMMapStartTraining(map); if (err) NSLog(@"Error training %i", err); err = LSMMapCompile(map); if (err) NSLog(@"Error compiling %i", err); */ CFRelease(good_sample); CFRelease(bad_sample); NSOutputStream* outstream = [NSOutputStream outputStreamToFileAtPath:@"test_lsm.txt" append:NO]; [outstream open]; err = LSMMapWriteToStream(map, NULL, (CFWriteStreamRef)outstream, 0); if (err) NSLog(@"Error writing %i", err); [outstream close]; CFRelease(map); [pool release]; }