natural

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package natural helps parsing durations

Index

Constants

This section is empty.

Variables

View Source
var ErrLangNotSupported = errors.New("lang not supported")

ErrLangNotSupported is returned when the language is not supported

Functions

func Duration

func Duration(symbols []interface{}) (duration *durations.Duration, err error)

Duration translates a list of symbols into a duration

Types

type Corpus

type Corpus interface {
	Symbols(string) ([]interface{}, error)
}

Corpus holds data about translating text to string

func PrefixedEn

func PrefixedEn() Corpus

PrefixedEn returns a Prefixed corpus for the english language

func PrefixedFr

func PrefixedFr() Corpus

PrefixedFr returns a Prefixed corpus for the french language

type Modifier

type Modifier int

Modifier is a length of time that applies to the last unit

const (
	Half Modifier = iota
	Quarter
	Plus
	Minus
)

All possible modifiers

type Number

type Number float32

Number is the symbol for numbers

type Parser

type Parser map[string]Corpus

Parser has the functions

func (Parser) Duration

func (p Parser) Duration(lang, raw string) (*durations.Duration, error)

Duration parses a duration from natural text

type PrefixedCorpus

type PrefixedCorpus []prefix

PrefixedCorpus tries to use the beginning of words to match them

func (PrefixedCorpus) Symbols

func (c PrefixedCorpus) Symbols(str string) ([]interface{}, error)

Symbols implements the corpus interface

type Unit

type Unit int

Unit represents a unit of time

const (
	Year Unit = iota
	Month
	Week
	Day
	Hour
	Minute
	Second
)

All possible units

Jump to

Keyboard shortcuts

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