deregexp

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

README

Deregexp

GoDoc Build Status

Deregexp converts a regexp to an expression with substring matches. This expression does not express exactly the same as the regexp, but a superset. It can be used for a cheap first pass filter, or for index lookups.

Examples

$ go run cmd/test/test.go "Mary.+had.+a.+little.+(lamb|sheep)"
"little" AND "Mary" AND "had" AND ("sheep" OR "lamb")

Note that the "a" has been dropped because it is implied by "Mary" and "had".

$ go run cmd/test/test.go "Mary.+had.+(a|no).+little.+(lamb|sheep)"
"little" AND "Mary" AND "had" AND ("sheep" OR "lamb")

Note that the "(a|no)" has been dropped because the "a" is implied by "Mary" and "had", and (TRUE OR "no") is always true.

Known limitations

Case insensitivity is not supported. You can of course use the resulting expression case insensitively, but controlling case sensitivity with (?i) is not supported. Patches are welcome.

Documentation

Overview

Package deregexp converts a regexp to an expression with substring matches. This expression does not express exactly the same as the regexp, but a superset. It can be used for a cheap first pass filter, or for index lookups.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndNode

type AndNode struct {
	Words    []string
	Children []OrNode
}

AndNode expresses a set of words and OrNodes that must all match for this node to match.

func (AndNode) Expr

func (n AndNode) Expr() string

Expr converts this node to a string.

type Node

type Node interface {
	Expr() string
}

Node is either an AndNode or OrNode in the tree. The tree describes an expression of ANDs and ORs and words.

func Deregexp

func Deregexp(regex string) (Node, error)

func Treeify

func Treeify(sequences [][]string) Node

Treeify simplifies all possible options passed in into a node tree. Treeify tries to make the tree as simple as possible.

type OrNode

type OrNode struct {
	Words    []string
	Children []AndNode
}

OrNode expresses a set of words and AndNodes of which at least one must match for this node to match.

func (OrNode) Expr

func (n OrNode) Expr() string

Expr converts this node to a string.

Directories

Path Synopsis
cmd
test
Binary test prints the expression tree from the regexp given as argv[1].
Binary test prints the expression tree from the regexp given as argv[1].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL