hashtag

package module
v0.0.0-...-0679bce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2017 License: Apache-2.0 Imports: 2 Imported by: 1

README

hashtag

Package hashtag implements extraction of Twitter type hashtags, mentions and replies form text in Go. This package partially ports extraction routines from Twitter's official Java package to Go and runs most of the standard twitter-text conformance tests. It does not yet implement URL extraction (and hence URL/Hashtag overlaps), cashtags and lists

Since the package attempts to closely follow the Twitter-Text Java API, function names may be longer than typical Go package function names

Installation

Note: As the package matures, I plan to move this to gopkg.in

go get github.com/srinathh/hashtag

Usage

Import the package as

import "github.com/srinathh/hashtag"

This package supports the following functions to extract hashtags and mentions with or without position markers. The functions omit # and @ characters (and also their higher unicode number counterparts @ and #) from return values

  • ExtractHashtags(text string) []string
  • ExtractHashtagsWithIndices(text string) []Entity
  • ExtractMentions(text string) []string
  • ExtractMentionsWithIndices(text string) []Entity
  • ExtractReply(text string) string

Documentation

Read the full documentation and examples on GoDoc

Documentation

Overview

Package hashtag implements extraction of Twitter type hashtags, mentions and replies form text in Go. This package partially ports extraction routines from Twitter's official Java package at https://github.com/twitter/twitter-text to Go and runs most of the standard twitter-text conformance tests. It does not yet implement URL extraction (and hence URL/Hashtag overlaps), cashtags and lists

Since the package attempts to closely follow the Twitter-Text Java API, function names may be longer than typical Go package function names

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractHashtags

func ExtractHashtags(text string) []string

ExtractHashtags extracts hashtags without the hash markers from input text and returns them as a slice of strings.

Example
fmt.Println(ExtractHashtags("this is a #hashtag and this too #http://example.com"))
Output:
[hashtag http://example.com]

func ExtractMentions

func ExtractMentions(text string) []string

ExtractMentions extracts mentions without the @ markers from input text and returns them as a slice of strings.

Example
fmt.Println(ExtractMentions("mention @username1 @username2 but not user@example.com"))
Output:
[username1 username2]

func ExtractReply

func ExtractReply(text string) string

ExtractReply extracts reply username without the @ marker from input text and returns it as a string. Empty string signals no reply username

Example
fmt.Println(ExtractReply("@username1 reply something but not to @username2"))
Output:
username1

Types

type Entity

type Entity struct {
	Start int
	End   int
	Value string
}

Entity is used by ExtractXXXXWithIndices functions to return the position and text extracted. This may be expanded in the future to support List slugs

func ExtractHashtagsWithIndices

func ExtractHashtagsWithIndices(text string) []Entity

ExtractHashtagsWithIndices extracts hashtags without the hash markers from input text and returns them as a slice of Entities containing start/end positions.

Example
fmt.Println(ExtractHashtagsWithIndices("this is a #hashtag and this too #http://example.com"))
Output:
[{11 18 hashtag} {33 51 http://example.com}]

func ExtractMentionsWithIndices

func ExtractMentionsWithIndices(text string) []Entity

ExtractMentionsWithIndices extracts mentions without the @ markers from input text and returns them as a slice of Entities containing start/end positions.

Example
fmt.Println(ExtractMentionsWithIndices("mention @username1 @username2 but not user@example.com"))
Output:
[{9 18 username1} {20 29 username2}]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL