parser

package module
v0.0.0-...-5b021f6 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: MIT Imports: 9 Imported by: 0

README

Fintracts English Parser

Build Go Report Card Documentation

Fintracts parser for the english grammar specification. Translates an english contract to the common JSON format.

Install With Go

If you have Go installed, you can simply run:

go install github.com/hacdias/fintracts/parser/cmd/fintracts

Run Directly

First, install the necessary dependencies:

go mod download

Then, build the executable:

make build

An executable can be found on ./parser, which can be executed:

./parser < ./path/to/contract.txt

Run With Docker

To build:

docker build . -t fintracts/parser

You can now run the parser inside the docker image:

docker run -i fintracts/parser < ./path/to/contract.txt

License

MIT © Henrique Dias

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agreement

type Agreement struct {
	BondPurchase     *BondPurchase     `` /* 129-byte string literal not displayed */
	InterestRateSwap *InterestRateSwap `` /* 132-byte string literal not displayed */
	CurrencySwap     *CurrencySwap     `parser:"| 'a' 'Currency' 'Swap' 'Transaction' 'Agreement' 'defined' 'as' 'follows' ':' @@ )" json:"currencySwap,omitempty"`
}

type BondPurchase

type BondPurchase struct {
	Issuer       string   `parser:"@Ident 'agrees' 'on' 'issuing' 'and' 'selling'" json:"issuer"`
	FaceValue    Money    `parser:"'a' 'bond' 'of' @@" json:"faceValue"`
	Underwriter  string   `parser:"'to' @Ident" json:"underwriter"`
	IssuePrice   Money    `parser:"'for' @@ '.'" json:"issuePrice"`
	MaturityDate *Date    `parser:"'The' 'aforementioned' 'bond' 'reaches' 'maturity' 'on' 'the' @@ '.'" json:"maturityDate"`
	Coupons      *Coupons `parser:"('The' 'bond' 'pays' 'coupons' @@)?" json:"coupons,omitempty"`
}

type Contract

type Contract struct {
	Parties    []Party      `parser:"'The' 'parties' ':' @@ ';' 'and' (@@ ';' 'and')* @@ '.'" json:"parties"`
	Agreements []*Agreement `parser:"@@+" json:"agreements"`
	Signatures []*Signature `parser:"@@+" json:"signatures"`
}

Contract represents a contract with parties, agreements and a signature.

func Parse

func Parse(contract []byte) (*Contract, error)

Parse parses the contract in English to an internal specification. You can call .String() on the result to get the common JSON spec format.

func (*Contract) String

func (c *Contract) String() (string, error)

type Coupons

type Coupons struct {
	Rate  float64 `parser:"'with' 'an' 'interest' 'rate' 'of' (@Float | @Integer) '%'" json:"rate"`
	Dates []*Date `parser:"'paid' 'on' 'the' 'following' 'dates' ':' (@@ ',' | @@ | 'and' @@)+ '.'" json:"dates"`
}

type CurrencySwap

type CurrencySwap struct {
	EffectiveDate       *Date              `parser:"'The' 'parties' 'agree' 'on' 'a' 'currency' 'swap' 'transaction' 'effective' 'as' 'of' 'the' @@" json:"effectiveDate"`
	MaturityDate        *Date              `parser:"'and' 'termination' 'on' 'the' @@ '.'" json:"maturityDate"`
	PayerA              string             `parser:"@Ident 'will' 'pay' 'a'" json:"payerA"`
	PrincipalA          Money              `parser:"'principal' 'amount' 'of' @@ ','" json:"principalA"`
	PayerB              string             `parser:"'and' 'the' @Ident 'will' 'pay' 'a'" json:"payerB"`
	PrincipalB          Money              `parser:"'principal' 'amount' 'of' @@ '.'" json:"principalB"`
	ImpliedExchangeRate ExchangeRate       `parser:"" json:"impliedExchangeRate"`
	EndExchangeRate     *ExchangeRate      `` /* 166-byte string literal not displayed */
	Interest            []*InterestPayment `parser:"@@*" json:"interest,omitempty"`
}

type Date

type Date struct {
	Day   int    `parser:"@Integer" json:"day"`
	Month string `parser:"('th' | 'rd' | 'st') 'of' @Ident" json:"month"`
	Year  int    `parser:"@Integer" json:"year"`
	// contains filtered or unexported fields
}

Date is a date in the format '1st of September 2022'. It marshals in JSON in the RFC3339 format.

func (*Date) MarshalJSON

func (d *Date) MarshalJSON() ([]byte, error)

type ExchangeRate

type ExchangeRate struct {
	BaseCurrency    string  `parser:"@Ident" json:"baseCurrency"`
	CounterCurrency string  `parser:"'/' @Ident" json:"counterCurrency"`
	Rate            float64 `parser:"@Float" json:"rate"`
}

type InterestPayment

type InterestPayment struct {
	Payer       string    `parser:"@Ident 'will' 'pay' 'a'" json:"payer"`
	FixedRate   float64   `parser:"( 'fixed' 'rate' 'interest' 'of' (@Float | @Integer) '%' " json:"fixedRate"`
	InitialRate float64   `parser:"| 'floating' 'rate' 'interest' ',' 'initially' 'defined' 'as' (@Float | @Integer) '%' ',' ) " json:"initialRate"`
	Dates       []*Date   `parser:"'over' 'the' 'notational' 'amount' 'on' 'the' 'following' 'dates' ':' (@@ ',' | @@ | 'and' @@)+ '.'" json:"dates"`
	RateOption  LongIdent `parser:"('The' 'floating' 'rate' 'option' 'is' @(~'.')+ '.')?" json:"rateOption"`
}

type InterestRateSwap

type InterestRateSwap struct {
	NotationalAmount Money              `` /* 155-byte string literal not displayed */
	EffectiveDate    *Date              `parser:"'with' 'an' 'effective' 'date' 'as' 'of' 'the' @@" json:"effectiveDate"`
	MaturityDate     *Date              `parser:"'and' 'termination' 'on' 'the' @@ '.'" json:"maturityDate"`
	Interest         []*InterestPayment `parser:"@@+" json:"interest"`
}

type LongIdent

type LongIdent string

LongIdent is an identifier that spans across multiple token yieldings.

func (*LongIdent) Capture

func (en *LongIdent) Capture(values []string) error

type Money

type Money struct {
	Currency string      `parser:"@Ident" json:"currency"`
	Amount   MoneyAmount `parser:"(@Money | @Float)" json:"amount"`
}

Money represents a monetary amount of a certain currency.

type MoneyAmount

type MoneyAmount float64

MoneyAmount is the the type of a monetary amount.

func (*MoneyAmount) Capture

func (b *MoneyAmount) Capture(values []string) error

type Party

type Party struct {
	Name       LongIdent `parser:"@(~',')+" json:"name"`
	Identifier string    `parser:"',' 'undermentioned' 'as' @Ident" json:"identifier"`
}

Party represents a party and its identifier.

type Signature

type Signature struct {
	Parties []string `parser:"'Signed' 'by'  @Ident (',' @Ident)* ('and' @Ident)*" json:"parties"`
	Date    *Date    `parser:"'on' 'the' @@ '.'" json:"date"`
}

Signature represents a signature parsed from the format 'Signed by <Party>, [<Party>, ...] and <Party> on <Date>.'

The signature does not need the parties per se. They are only used to semantically validate the English text. The marshalled output is a Date object.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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