Giter VIP home page Giter VIP logo

social_parser's Introduction

SocialParser

Join the chat at https://gitter.im/swelham/social_parser Build Status Hex Version

A small library for parsing out common social elements such as hashtags, mentions and urls.

Usage

Add social_parser to your list of dependencies in mix.exs:

def deps do
  [{:social_parser, "~> 1.1.0"}]
end

You can then parse out the social components like so:

defmodule SocialParserTest do
  def do_social_stuff() do
    message = "hi @you checkout http://example.com/ that +someone hosted #example"

    # parse out all components into an array
    components = SocialParser.parse(message)

    IO.inspect(components)
    # [
    #   {:text, "hi ", {0, 3}},
    #   {:mention, "@you", {4, 8}},
    #   {:text, " checkout ", {9, 19}},
    #   {:link, "http://example.com/", {20, 39}},
    #   {:text, " that ", {40, 46}},
    #   {:mention, "+someone", {47, 55}},
    #   {:text, " hosted ", {56, 64}},
    #   {:hashtag, "#example", {65, 73}}
    # ]

    # extract targeted components
    some_components = SocialParser.extract(message, [:hashtags, :mentions])

    IO.inspect(some_components)
    #%{
    #   hashtags: ["#example"],
    #   mentions: ["@you", "+someone"]
    #}
  end
end

TODO

  • Merge the private parse and parse_components functions as there is some duplication of code

social_parser's People

Contributors

princemaple avatar swelham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

social_parser's Issues

Detecting Emoji Type

Side-note: This project just saved me hours of porting TwitterText into Elixir; thank you!

I've looked at the regex and it looks like handling emoji type (:emoji:) is pretty feasible. How open are you to a PR for that? It could be up to the caller to do whatever with the resulting text - so no need to do actual emoji lookups (and allow for users to define 'custom' emoji).

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.