-
-
Save jordanekay/5703475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSString (JSRemoveIrrelevantTags) | |
- (NSString *)js_stringByRemovingIrrelevantTags | |
{ | |
NSMutableString *filteredString = [NSMutableString string]; | |
NSSet *filteredLinguisticTags = [NSSet setWithArray:@[NSLinguisticTagDeterminer, NSLinguisticTagPreposition]]; | |
[self enumerateLinguisticTagsInRange:NSMakeRange(0, self.length) | |
scheme:NSLinguisticTagSchemeLexicalClass | |
options:NSLinguisticTaggerJoinNames | NSLinguisticTaggerOmitOther | NSLinguisticTaggerOmitWhitespace | |
orthography:nil | |
usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) { | |
if (![filteredLinguisticTags containsObject:tag]) | |
{ | |
[filteredString appendFormat:@"%@ ", [self substringWithRange:tokenRange]]; | |
} | |
}]; | |
return filteredString; | |
} | |
@end | |
@implementation NSArray (JSNatualSort) | |
- (NSArray *)js_naturallySortedArray | |
{ | |
return [self sortedArrayUsingComparator:^NSComparisonResult(NSString *string1, NSString *string2) { | |
return [[string1 js_stringByRemovingIrrelevantTags] caseInsensitiveCompare:[string2 js_stringByRemovingIrrelevantTags]]; | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment