- MNSChatLexer addresses one of the challenges to programmers to extract valuable information from provided text strings. It is designed in a customizable way, so that future users can include their own rules 'MNLexeme' elements into 'MNParser'.
- It also has a URLTitleManager, which executes an NSURLSessionDataTask to grab title of a given URL.
- The Facade API i.e MNParserAPI interact with 'MNParser' and URLTitleManager to provide a single interface to end user.
- Problem Statement Explains the problem in more detail.
- Xcode 7 or higher
- iOS 7.0 or higher
- ARC
- Objective-C
Copy the project from git OR Git Clone using following command
$ git clone https://github.com/nabeelarif100/MNChatLexer.git
You need to install pods before running the project
$ pod install
Import the header file
#import "MNParserAPI.h"
Call the Facade API i.e ParserKit - A shared instance of MNParser to parser input text
NSString *text = @"@nabeel (success) twitter.com";
[ParserKit parseText:text isFinal:YES completion:^(NSDictionary * _Nonnull result, NSString * _Nonnull originalText) {
//Parsing complete
NSString *jsonString = [MNParserAPI jsonForDictionary:result prettyPrint:YES];
weakSelf.tvOutput.text = jsonString;
}];
Create a parser object
MNParser *parser = [[MNParser alloc] init];
Add Rules i.e MNLexeme elements to parser object
//Lexeme for @mention
MNLexeme *lexemeMention = [[MNLexeme alloc] init];
[lexemeMention setRegexWithQuery:@"(?<=^|\\W)@([\\w]+)(?=$|[^a-zA-Z0-9_.])"];
lexemeMention.numberOfComponentToUse = 1;
//Lexeme for URLs
MNLexeme *lexemeUrl = [[MNLexeme alloc] init];
lexemeUrl.regex = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
lexemeUrl.parseLexeme = ^id(NSTextCheckingResult * match,NSUInteger numberOfComponentToUse, NSString *text)
{
NSMutableDictionary *urlDictionary;
if ([match resultType] == NSTextCheckingTypeLink) {
//Ignore emails we only need urls
if (([[match.URL scheme] isEqualToString:@"mailto"]==NO)) {
urlDictionary = [NSMutableDictionary new];
[urlDictionary setObject:[text substringWithRange:match.range] forKey:kParserKeyUrl];
[urlDictionary setObject:@"" forKey:kParserKeyTitle];
}
}
return urlDictionary;
};
[parser setLexeme:lexemeMention forKey:kParserKeyMentions];
[parser setLexeme:lexemeUrl forKey:kParserKeyLinks];
- Add network checks
- Add Unit Tests
- Add UI Tests
Muhammad Nabeel Arif
MNChatLexer is available under the MIT license. See the LICENSE file for more info.