Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swelham/social_parser
A small library for parsing out common social elements such as hashtags, mentions and urls.
https://github.com/swelham/social_parser
elixir hashtag mentions parser parsing url
Last synced: about 2 months ago
JSON representation
A small library for parsing out common social elements such as hashtags, mentions and urls.
- Host: GitHub
- URL: https://github.com/swelham/social_parser
- Owner: swelham
- License: mit
- Created: 2016-10-31T23:00:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-22T14:50:56.000Z (almost 5 years ago)
- Last Synced: 2024-09-22T10:05:17.557Z (3 months ago)
- Topics: elixir, hashtag, mentions, parser, parsing, url
- Language: Elixir
- Homepage:
- Size: 26.4 KB
- Stars: 17
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SocialParser
[![Join the chat at https://gitter.im/swelham/social_parser](https://badges.gitter.im/swelham/social_parser.svg)](https://gitter.im/swelham/social_parser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/swelham/social_parser.svg?branch=master)](https://travis-ci.org/swelham/social_parser) [![Hex Version](https://img.shields.io/hexpm/v/social_parser.svg)](https://hex.pm/packages/social_parser)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`:
```elixir
def deps do
[{:social_parser, "~> 1.1.0"}]
end
```You can then parse out the social components like so:
```elixir
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