fmr

package module
v0.1.1-0...-76ac419 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

README

FMR: Functional Meaning Representation & Semantic Parsing Framework

GoDocGo Report Card

Projects that uses FMR

mathsolver

What is semantic parsing?

Semantic parsing is the process of mapping a natural language sentence into an intermediate logical form which is a formal representation of its meaning.

The formal representation should be a detailed representation of the complete meaning of the natural language sentence in a fully formal language that:

  • Has a rich ontology of types, properties, and relations.
  • Supports automated reasoning or execution.

Representation languages

Early semantic parsers used highly domain-specific meaning representation languages, with later systems using more extensible languages like Prolog, lambda calculus, lambda dependancy-based compositional semantics (λ-DCS), SQL, Python, Java, and the Alexa Meaning Representation Language. Some work has used more exotic meaning representations, like query graphs or vector representations.

FMR, a formal meaning representation language

Tasks

  • Grammar checkers
  • Dialogue management
  • Question answering
  • Information extraction
  • Machine translation

References

Documentation

Index

Constants

View Source
const DOT = "\u2022" // "\u00B7"

DOT indicates the current position inside a TableState

View Source
const GammaRule = "\u0263" // "\u0194"

GammaRule is the name of the special "gamma" rule added by the algorithm (this is unicode for 'LATIN SMALL LETTER GAMMA')

Variables

View Source
var Debug = false

Debug flag

Functions

func Call

func Call(fn string, args ...interface{}) (interface{}, error)

Call funcs by name fn and args

func NLP

func NLP() *ling.Pipeline

NLP returns handler for the ling nlp toolkit

Types

type Arg

type Arg struct {
	Type  string      `json:"type"`
	Value interface{} `json:"value"`
}

Arg is the type of argument for functions

type FMR

type FMR struct {
	Fn   string `json:"fn,omitempty"`
	Args []*Arg `json:"args,omitempty"`
}

FMR stands for Funtional Meaning Representation

func (*FMR) Equal

func (f *FMR) Equal(fmr *FMR) bool

Equal func for FMR

func (*FMR) String

func (f *FMR) String() string

type Grammar

type Grammar struct {
	Name    string            `json:"name"`
	Rules   map[string]*Rule  `json:"rules"`
	Frames  map[string]*Rule  `json:"frames"`
	Regexps map[string]string `json:"regexps"`
	Refined bool              `json:"refined"`
	// contains filtered or unexported fields
}

A Grammar stores a Context-Free Grammar

func GrammarFromFile

func GrammarFromFile(file string) (*Grammar, error)

GrammarFromFile constructs the Context-Free Grammar from file

func GrammarFromString

func GrammarFromString(d, name string) (*Grammar, error)

GrammarFromString constructs the Contex-Free Grammar from string d with name

func (*Grammar) EarleyParse

func (g *Grammar) EarleyParse(text string, starts ...string) (*Parse, error)

EarleyParse parses text for rule <start> at beginning

func (*Grammar) EarleyParseAll

func (g *Grammar) EarleyParseAll(text string, starts ...string) ([]*Parse, error)

EarleyParseAll extracts all submatches in text for rule <start>

func (*Grammar) EarleyParseAny

func (g *Grammar) EarleyParseAny(text string, starts ...string) (*Parse, error)

EarleyParseAny parses text for rule <start> at any position

func (*Grammar) EarleyParseMaxAll

func (g *Grammar) EarleyParseMaxAll(text string, starts ...string) ([]*Parse, error)

EarleyParseMaxAll extracts all submatches in text for rule <start>

func (*Grammar) ExtractAll

func (g *Grammar) ExtractAll(text string, starts ...string) ([]*Node, error)

ExtractAll extracts all parse trees in text for rule <start>

func (*Grammar) ExtractMaxAll

func (g *Grammar) ExtractMaxAll(text string, starts ...string) ([]*Node, error)

ExtractMaxAll extracts all parse trees in text for rule <start>

func (*Grammar) FrameFMR

func (g *Grammar) FrameFMR(text string) ([]string, error)

FrameFMR parses NL text to FMR

func (*Grammar) MatchFrames

func (g *Grammar) MatchFrames(text string) (map[RbKey]*SlotFilling, error)

MatchFrames returns the matched frames for NL text

func (*Grammar) Parse

func (g *Grammar) Parse(text string, starts ...string) ([]*Node, error)

Parse returns parse trees for rule <start> at beginning

func (*Grammar) ParseAny

func (g *Grammar) ParseAny(text string, starts ...string) ([]*Node, error)

ParseAny returns parse trees for rule <start> at any position

type Index

type Index struct {
	Frames map[RbKey]struct{}
	Rules  map[RbKey]struct{}
}

An Index contains two sets for frames' names and rules' names

type Node

type Node struct {
	Value    *TableState `json:"value"`
	Children []*Node     `json:"children,omitempty"`
	// contains filtered or unexported fields
}

Node is the AST of tree structure

func (*Node) Eval

func (n *Node) Eval() (interface{}, error)

Eval returns the denotation of Node n

func (*Node) F

func (n *Node) F() *FMR

F returns the FMR signature of node

func (*Node) NL

func (n *Node) NL() string

NL returns the normalized text of Node n

func (*Node) OriginalText

func (n *Node) OriginalText() string

OriginalText returns the original text of Node n

func (*Node) Pos

func (n *Node) Pos() *Pos

Pos returns the corresponding pos of Node n in original text

func (*Node) Print

func (n *Node) Print(out io.Writer)

Print this tree to out

func (*Node) Semantic

func (n *Node) Semantic() (string, error)

Semantic returns the stringified FMR of Node n

func (*Node) String

func (n *Node) String() string

func (*Node) Term

func (n *Node) Term() *Term

Term returns the root Term of tree node

type Parse

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

Parse stores a parse chart by grammars

func (*Parse) Boundary

func (p *Parse) Boundary(finalState *TableState) *Pos

Boundary returns the start, end position in NL for finalState

func (*Parse) GetFinalStates

func (p *Parse) GetFinalStates() []*TableState

GetFinalStates returns the final states of p

func (*Parse) GetTrees

func (p *Parse) GetTrees(finalState *TableState) []*Node

GetTrees returns all possible parse results

func (*Parse) String

func (p *Parse) String() string

func (*Parse) Tag

func (p *Parse) Tag(finalState *TableState) string

Tag returns the Nonterminal name of finalState

type Pos

type Pos struct {
	StartByte int `json:"start_byte"`
	EndByte   int `json:"end_byte"`
}

A Pos specifies the start and end positions

type RbKey

type RbKey struct {
	RuleName string `json:"rule_name"`
	BodyID   uint64 `json:"body_id"`
}

A RbKey identifies a specific RuleBody by name and id

type Rule

type Rule struct {
	Name string               `json:"-"`
	Body map[uint64]*RuleBody `json:"body,omitempty"`
}

A Rule stores a set of production rules of Name

type RuleBody

type RuleBody struct {
	Terms []*Term `json:"terms"`
	F     *FMR    `json:"f,omitempty"`
}

A RuleBody is one production rule

func (*RuleBody) Equal

func (r *RuleBody) Equal(rb *RuleBody) bool

Equal func for RuleBody

type Slot

type Slot struct {
	Pos
	Trees []*Node
}

A Slot contains the Pos and its corresponding parse trees

type SlotFilling

type SlotFilling struct {
	Fillings map[uint64][]*Slot
	Complete bool
}

A SlotFilling is a frame consists of Slots

func (*SlotFilling) String

func (s *SlotFilling) String() string

type TableColumn

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

TableColumn is the TableState set

func (*TableColumn) String

func (tc *TableColumn) String() (out string)

type TableState

type TableState struct {
	Term  *Term     `json:"term"`
	Rb    *RuleBody `json:"rb,omitempty"`
	Start int       `json:"start"`
	End   int       `json:"end"`
	Dot   int       `json:"dot"`
}

TableState uses Earley's dot notation: given a production X → αβ, the notation X → α • β represents a condition in which α has already been parsed and β is expected.

func (*TableState) Equal

func (s *TableState) Equal(ts *TableState) bool

Equal func for TableState

func (*TableState) String

func (ts *TableState) String() string

type Term

type Term struct {
	Value string      `json:"value"`
	Type  TermType    `json:"type"`
	Meta  interface{} `json:"meta"`
}

A Term is the component of RuleBody

func (*Term) Equal

func (t *Term) Equal(t1 *Term) bool

Equal func for Term

func (*Term) Key

func (t *Term) Key() uint64

Key returns a unique key for Term t

type TermType

type TermType byte

TermType of grammar terms

const (
	EOF TermType = iota
	Nonterminal
	Terminal
	Any
	List
)

definition of TermTypes

func (TermType) MarshalJSON

func (r TermType) MarshalJSON() ([]byte, error)

MarshalJSON is generated so TermType satisfies json.Marshaler.

func (TermType) String

func (i TermType) String() string

func (*TermType) UnmarshalJSON

func (r *TermType) UnmarshalJSON(data []byte) error

UnmarshalJSON is generated so TermType satisfies json.Unmarshaler.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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