datetime

package
v0.0.0-...-b6f9ca8 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package datetime has the utilities required for interpreting date/time from a nlp query

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duckling

type Duckling struct {
	// contains filtered or unexported fields
}

Duckling is a datetime service

func NewDuckling

func NewDuckling() (*Duckling, error)

NewDuckling returns a duckling service instance. If it couldn't be initialized due to missing env variables - DUCKLING_SERVER holding host address will return an error

func (*Duckling) Query

func (d *Duckling) Query(query []rune) chan Results

Query returns a channel of Response. Which will return the reponse in an concurrent environment

type Response

type Response struct {
	//Start index of the words denoting date-time in the given query
	Start int `json:"start,omitempty"`
	//End index of the words denoting date-time in the given query
	End int `json:"end,omitempty"`
	//Dim is the dimension of the response. We are intrested only if the Dim is time
	Dim string `json:"dim,omitempty"`
	//Value stores the value of the response.
	Value Value `json:"value,omitempty"`
	//Body is the string from which date is referred
	Body string `json:"body,omiempty"`
}

Response is the response of the package for external use

func (*Response) IsValid

func (r *Response) IsValid() bool

IsValid denotes whether the response valid or not. It is valid only if the underlying value is valid and dimension is time

type Results

type Results struct {
	//Res has the list of response
	Res []Response
}

Results has list of responses from the service

func (*Results) IsValid

func (r *Results) IsValid() bool

IsValid will check and update the state of the results

type Service

type Service interface {
	Query(query []rune) chan Results
}

Service interface produces the querying service

func DefaultService

func DefaultService() (Service, error)

DefaultService will return a service to provide the interpretation of datetime

type TimeValue

type TimeValue struct {
	//String value of the time
	Value string `json:"value,omitempty"`
	//Gran of the time to like hour, day etc described by the text
	Gran string `json:"gran,omitempty"`
	//Time stores the time value
	Time *time.Time `json:"-"`
	//Error will be set once isvalid is run if parsing failed
	Error error `json:"-"`
}

TimeValue is the Value of the time stored

func (*TimeValue) IsValid

func (tv *TimeValue) IsValid() bool

IsValid checks whether the time value is valid or not

type Value

type Value struct {
	//To indicates the to interval
	To *TimeValue `json:"to,omitempty"`
	//From indicates the from interval
	From *TimeValue `json:"from,omitempty"`
	//Type of value
	Type string `json:"type,omitempty"`
	//String value of the time
	Value string `json:"value,omitempty"`
	//Gran of the time to like hour, day etc described by the text
	Gran string `json:"gran,omitempty"`
	//Time stores the time value
	Time *time.Time `json:"-"`
	//Error will be set once isvalid is run if parsing failed
	Error error `json:"-"`
}

Value is the value struct holding the time

func (*Value) IsValid

func (v *Value) IsValid() bool

IsValid checks whether the value is valid or not

Jump to

Keyboard shortcuts

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