relations

package module
v0.0.0-...-d01ad1e Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2016 License: MIT Imports: 7 Imported by: 0

README

regular relations

GoDoc Go Report Card

Construct a subsequential transducer from a regular expression.

Background

Finite-state automata equate to regular languages and finite-state transducers equate to regular relations.

Regular relations are closed under concatenation, union and Kleene star (closure), here denoted as ., + and * respectively.

A finite-state transducer corresponds to a function from strings to strings. Therefore, to construct a subsequential transducer from a regular expression the base elements of that expression must be pairs of strings (input/output).

Implementation

The subsequential transducer is constructed in two steps:

  • Build a finite-state automata (effectively a finite-state non-deterministic transducer) from the regular expression using the Berry-Sethi construction by treating string pairs as distinct symbols.
  • Construct an equivalent 2-subsequential transducer from the non-deterministic transducer as described in Finitely Subsequential Transducers.

Example

  regexp := strings.NewReader(`<foo,bar>+<none,>`)
  transducer, _ := relations.Build(regexp)
  
  transducer.Transduce("foo")     // [bar], true
  transducer.Transduce("missing") // [], false
Notes

The regular expression must represent a subsequential function. Otherwise the algorithm will never finish the construction.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RegularRelation

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

RegularRelation is a struct containing the initial state of the subsequential transducer that recognizes the input regular relation.

func Build

func Build(source io.Reader) (*RegularRelation, error)

Build builds a RegularRelation subsequential transducer from the input regular relation expression. NOTE: All operations must be explicitly written in the regular expression.

func (*RegularRelation) Transduce

func (s *RegularRelation) Transduce(input string) ([]string, bool)

Transduce feeds the input string into the RegularRelation transducer and returns all possible results from the output transducer tape.

Jump to

Keyboard shortcuts

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