Giter Club home page Giter Club logo

mnchatlexer's Introduction

Build Status

MNChatLexer

  • 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.

Parsing on pressing button

Live Parsing

Requirements

  • Xcode 7 or higher
  • iOS 7.0 or higher
  • ARC
  • Objective-C

Installation

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

Usage

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;
}];

Configuring Parser Rules

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];

Todo

  • Add network checks
  • Add Unit Tests
  • Add UI Tests

Author

Muhammad Nabeel Arif

License

MNChatLexer is available under the MIT license. See the LICENSE file for more info.

mnchatlexer's People

Contributors

nabeelarif avatar

Stargazers

 avatar James Laurenstin avatar Arslan Anwar avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.