semantic

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2017 License: Apache-2.0 Imports: 16 Imported by: 11

Documentation

Overview

Package semantic contains the semantic analysis required to have a semantically valid parser. It includes the data conversion required to turn tokens into valid BadWolf structures. It also provides the hooks implementations required for building an actionable execution plan.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToLiteral

func ToLiteral(ce ConsumedElement) (*literal.Literal, error)

ToLiteral converts the node found by the lexer and converts it into a BadWolf literal.

func ToNode

func ToNode(ce ConsumedElement) (*node.Node, error)

ToNode converts the node found by the lexer and converts it into a BadWolf node.

func ToPredicate

func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error)

ToPredicate converts the node found by the lexer and converts it into a BadWolf predicate.

Types

type AlwaysReturn

type AlwaysReturn struct {
	V bool
}

AlwaysReturn evaluator always return the provided boolean value.

func (*AlwaysReturn) Evaluate

func (a *AlwaysReturn) Evaluate(r table.Row) (bool, error)

Evaluate return the provided value.

type ClauseHook

type ClauseHook func(*Statement, Symbol) (ClauseHook, error)

ClauseHook is a function hook for the parser that gets called on clause wide events.

func GroupByBindingsChecker

func GroupByBindingsChecker() ClauseHook

GroupByBindingsChecker returns the singleton to check that the group by bindings are valid.

func HavingExpressionBuilder

func HavingExpressionBuilder() ClauseHook

HavingExpressionBuilder returns the singleton to collect the tokens that form the having clause.

func InitWorkingConstructClause added in v0.8.0

func InitWorkingConstructClause() ClauseHook

InitWorkingConstructClause returns a clause hook to initialize a new working construct clause.

func InitWorkingConstructClauseHook added in v0.8.0

func InitWorkingConstructClauseHook() ClauseHook

InitWorkingConstructClauseHook returns the singleton for clause accumulation within the construct statement.

func NextWorkingConstructClause added in v0.8.0

func NextWorkingConstructClause() ClauseHook

NextWorkingConstructClause returns a clause hook to close the current working construct clause and start a new working construct clause.

func NextWorkingConstructClauseHook added in v0.8.0

func NextWorkingConstructClauseHook() ClauseHook

NextWorkingConstructClauseHook returns the singleton for clause accumulation within the construct statement.

func NextWorkingConstructPredicateObjectPair added in v0.8.0

func NextWorkingConstructPredicateObjectPair() ClauseHook

NextWorkingConstructPredicateObjectPair returns a clause hook to close the current predicate-object pair and start a new predicate-object pair within the working construct clause.

func NextWorkingConstructPredicateObjectPairClauseHook added in v0.8.0

func NextWorkingConstructPredicateObjectPairClauseHook() ClauseHook

NextWorkingConstructPredicateObjectPairClauseHook returns the singleton for adding the current predicate-object pair to the set of predicate-objects pairs within the working construct statement and initializing a new working predicate-object pair.

func OrderByBindingsChecker

func OrderByBindingsChecker() ClauseHook

OrderByBindingsChecker returns the singleton to check that the group by bindings are valid.

func TypeBindingClauseHook

func TypeBindingClauseHook(t StatementType) ClauseHook

TypeBindingClauseHook returns a ClauseHook that sets the binding type.

func VarBindingsGraphChecker

func VarBindingsGraphChecker() ClauseHook

VarBindingsGraphChecker returns the singleton for checking a query statement for valid bindings in the select variables.

func WhereInitWorkingClauseHook

func WhereInitWorkingClauseHook() ClauseHook

WhereInitWorkingClauseHook returns the singleton for graph accumulation.

func WhereNextWorkingClauseHook

func WhereNextWorkingClauseHook() ClauseHook

WhereNextWorkingClauseHook returns the singleton for graph accumulation.

type ConstructClause added in v0.8.0

type ConstructClause struct {
	S        *node.Node
	SBinding string
	// contains filtered or unexported fields
}

ConstructClause represents a singular clause within a construct statement.

func (*ConstructClause) AddWorkingPredicateObjectPair added in v0.8.0

func (c *ConstructClause) AddWorkingPredicateObjectPair()

AddWorkingPredicateObjectPair adds the working predicate-object pair to the set of predicate-object pairs belonging to the construct clause.

func (*ConstructClause) IsEmpty added in v0.8.0

func (c *ConstructClause) IsEmpty() bool

IsEmpty will return true if there are no set values in the construct clause.

func (*ConstructClause) PredicateObjectPairs added in v0.8.0

func (c *ConstructClause) PredicateObjectPairs() []*ConstructPredicateObjectPair

PredicateObjectPairs returns the list of predicate-object pairs within the construct clause.

func (*ConstructClause) ResetWorkingPredicateObjectPair added in v0.8.0

func (c *ConstructClause) ResetWorkingPredicateObjectPair()

ResetWorkingPredicateObjectPair resets the working predicate-object pair in the construct clause.

func (*ConstructClause) String added in v0.8.0

func (c *ConstructClause) String() string

String returns a readable representation of a construct clause.

func (*ConstructClause) WorkingPredicateObjectPair added in v0.8.0

func (c *ConstructClause) WorkingPredicateObjectPair() *ConstructPredicateObjectPair

WorkingPredicateObjectPair returns the working predicate-object pair in the construct clause.

type ConstructPredicateObjectPair added in v0.8.0

type ConstructPredicateObjectPair struct {
	P              *predicate.Predicate
	PBinding       string
	PID            string
	PAnchorBinding string
	PTemporal      bool

	O              *triple.Object
	OBinding       string
	OID            string
	OAnchorBinding string
	OTemporal      bool
}

ConstructPredicateObjectPair represents a predicate-object pair within a CONSTRUCT clause.

func (*ConstructPredicateObjectPair) IsEmpty added in v0.8.0

func (c *ConstructPredicateObjectPair) IsEmpty() bool

IsEmpty will return true if there are no set values in the predicate-object pair.

func (*ConstructPredicateObjectPair) String added in v0.8.0

String returns a readable representation of a ConstructPredicateObjectPair.

type ConsumedElement

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

ConsumedElement groups the current element being processed by the parser.

func NewConsumedSymbol

func NewConsumedSymbol(s Symbol) ConsumedElement

NewConsumedSymbol create a new consumed element that boxes a symbol.

func NewConsumedToken

func NewConsumedToken(tkn *lexer.Token) ConsumedElement

NewConsumedToken create a new consumed element that boxes a token.

func (ConsumedElement) IsSymbol

func (c ConsumedElement) IsSymbol() bool

IsSymbol returns true if the boxed element is a symbol; false otherwise.

func (ConsumedElement) Symbol

func (c ConsumedElement) Symbol() Symbol

Symbol returns the boxed symbol.

func (ConsumedElement) Token

func (c ConsumedElement) Token() *lexer.Token

Token returns the boxed token.

type ElementHook

type ElementHook func(*Statement, ConsumedElement) (ElementHook, error)

ElementHook is a function hook for the parser that gets called after an Element is confused.

func CollectGlobalBounds

func CollectGlobalBounds() ElementHook

CollectGlobalBounds returns the global temporary bounds hook.

func ConstructObjectHook added in v0.8.0

func ConstructObjectHook() ElementHook

ConstructObjectHook returns the singleton for populating the object in the current predicate-object pair in the working construct clause.

func ConstructPredicateHook added in v0.8.0

func ConstructPredicateHook() ElementHook

ConstructPredicateHook returns the singleton for populating the predicate in the current predicate-object pair in the working construct clause.

func ConstructSubjectHook added in v0.8.0

func ConstructSubjectHook() ElementHook

ConstructSubjectHook returns the singleton for populating the subject in the working construct clause.

func DataAccumulatorHook

func DataAccumulatorHook() ElementHook

DataAccumulatorHook returns the singleton for data accumulation.

func GraphAccumulatorHook

func GraphAccumulatorHook() ElementHook

GraphAccumulatorHook returns the singleton for graph accumulation.

func GroupByBindings

func GroupByBindings() ElementHook

GroupByBindings returns the singleton for collecting all the group by bindings.

func HavingExpression

func HavingExpression() ElementHook

HavingExpression returns the singleton to collect the tokens that form the having clause.

func InputGraphAccumulatorHook added in v0.8.0

func InputGraphAccumulatorHook() ElementHook

InputGraphAccumulatorHook returns the singleton for input graph accumulation.

func LimitCollection

func LimitCollection() ElementHook

LimitCollection returns the limit collection hook.

func OrderByBindings

func OrderByBindings() ElementHook

OrderByBindings returns the singleton for collecting all the group by bindings.

func OutputGraphAccumulatorHook added in v0.8.0

func OutputGraphAccumulatorHook() ElementHook

OutputGraphAccumulatorHook returns the singleton for output graph accumulation.

func VarAccumulatorHook

func VarAccumulatorHook() ElementHook

VarAccumulatorHook returns the singleton for accumulating variable projections.

func WhereObjectClauseHook

func WhereObjectClauseHook() ElementHook

WhereObjectClauseHook returns the singleton for working clause hooks that populates the object.

func WherePredicateClauseHook

func WherePredicateClauseHook() ElementHook

WherePredicateClauseHook returns the singleton for working clause hooks that populates the predicate.

func WhereSubjectClauseHook

func WhereSubjectClauseHook() ElementHook

WhereSubjectClauseHook returns the singleton for working clause hooks that populates the subject.

type Evaluator

type Evaluator interface {
	// Evaluate computes the boolean value of the expression given a certain
	// results table row. It will return an
	// error if it could not be evaluated for the provided table row.
	Evaluate(r table.Row) (bool, error)
}

Evaluator interface computes the evaluation of a boolean expression.

func NewBinaryBooleanExpression

func NewBinaryBooleanExpression(op OP, lE, rE Evaluator) (Evaluator, error)

NewBinaryBooleanExpression creates a new binary boolean evaluator.

func NewEvaluationExpression

func NewEvaluationExpression(op OP, lB, rB string) (Evaluator, error)

NewEvaluationExpression creates a new evaluator for two bindings in a row.

func NewEvaluator

func NewEvaluator(ce []ConsumedElement) (Evaluator, error)

NewEvaluator construct an evaluator given a sequence of tokens. It will return a descriptive error if it could build it properly.

func NewUnaryBooleanExpression

func NewUnaryBooleanExpression(op OP, lE Evaluator) (Evaluator, error)

NewUnaryBooleanExpression creates a new unary boolean evaluator.

type GraphClause

type GraphClause struct {
	S          *node.Node
	SBinding   string
	SAlias     string
	STypeAlias string
	SIDAlias   string

	P                *predicate.Predicate
	PID              string
	PBinding         string
	PAlias           string
	PIDAlias         string
	PAnchorBinding   string
	PAnchorAlias     string
	PLowerBound      *time.Time
	PUpperBound      *time.Time
	PLowerBoundAlias string
	PUpperBoundAlias string
	PTemporal        bool

	O                *triple.Object
	OBinding         string
	OAlias           string
	OID              string
	OTypeAlias       string
	OIDAlias         string
	OAnchorBinding   string
	OAnchorAlias     string
	OLowerBound      *time.Time
	OUpperBound      *time.Time
	OLowerBoundAlias string
	OUpperBoundAlias string
	OTemporal        bool
}

GraphClause represents a clause of a graph pattern in a where clause.

func (*GraphClause) Bindings

func (c *GraphClause) Bindings() []string

Bindings returns the list of unique bindings listed in the graph clause.

func (*GraphClause) BindingsMap

func (c *GraphClause) BindingsMap() map[string]int

BindingsMap returns the binding map for the graph clause.

func (*GraphClause) IsEmpty

func (c *GraphClause) IsEmpty() bool

IsEmpty will return true if the are no set values in the clause.

func (*GraphClause) Specificity

func (c *GraphClause) Specificity() int

Specificity return

func (*GraphClause) String added in v0.7.0

func (c *GraphClause) String() string

String returns a readable representation of a graph clause.

type OP

type OP int8

OP the operation to be use in the expression evaluation.

const (
	// LT represents '<'
	LT OP = iota
	// GT represents '>”
	GT
	// EQ represents '=”
	EQ
	// NOT represents 'not'
	NOT
	// AND represents 'and'
	AND
	// OR represents 'or'
	OR
)

func (OP) String

func (o OP) String() string

String returns a readable string of the operation.

type Projection

type Projection struct {
	Binding  string
	Alias    string
	OP       lexer.TokenType // The information about what function to use.
	Modifier lexer.TokenType // The modifier for the selected op.
}

Projection contains the information required to project the outcome of querying with GraphClauses. It also contains the information of what aggregation function should be used.

func (*Projection) IsEmpty

func (p *Projection) IsEmpty() bool

IsEmpty checks if the given projection is empty.

func (*Projection) String

func (p *Projection) String() string

String returns a readable form of the projection.

type Statement

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

Statement contains all the semantic information extract from the parsing

func (*Statement) AddData

func (s *Statement) AddData(d *triple.Triple)

AddData adds a triple to a given statement's data.

func (*Statement) AddGraph

func (s *Statement) AddGraph(g string)

AddGraph adds a graph to a given statement.

func (*Statement) AddInputGraph added in v0.8.0

func (s *Statement) AddInputGraph(g string)

AddInputGraph adds an input graph to a given statement.

func (*Statement) AddOutputGraph added in v0.8.0

func (s *Statement) AddOutputGraph(g string)

AddOutputGraph adds an output graph to a given statement.

func (*Statement) AddWorkingConstructClause added in v0.8.0

func (s *Statement) AddWorkingConstructClause()

AddWorkingConstructClause adds the current working construct clause to the set of construct clauses that form the construct statement.

func (*Statement) AddWorkingGraphClause added in v0.5.0

func (s *Statement) AddWorkingGraphClause()

AddWorkingGraphClause adds the current working graph clause to the set of clauses that form the graph pattern.

func (*Statement) AddWorkingProjection

func (s *Statement) AddWorkingProjection()

AddWorkingProjection adds the current projection variable to the set of projects that this statement.

func (*Statement) BindType

func (s *Statement) BindType(st StatementType)

BindType sets the type of a statement.

func (*Statement) Bindings

func (s *Statement) Bindings() []string

Bindings returns the list of bindings available on the graph clauses for he statement.

func (*Statement) BindingsMap

func (s *Statement) BindingsMap() map[string]int

BindingsMap returns the set of bindings available on the graph clauses for the statement.

func (*Statement) ConstructClauses added in v0.8.0

func (s *Statement) ConstructClauses() []*ConstructClause

ConstructClauses returns the list of construct clauses in the statement.

func (*Statement) Data

func (s *Statement) Data() []*triple.Triple

Data returns the data available for the given statement.

func (*Statement) GlobalLookupOptions

func (s *Statement) GlobalLookupOptions() *storage.LookupOptions

GlobalLookupOptions returns the global lookup options available in the statement.

func (*Statement) GraphNames added in v0.7.0

func (s *Statement) GraphNames() []string

GraphNames returns the list of graphs listed on the statement.

func (*Statement) GraphPatternClauses

func (s *Statement) GraphPatternClauses() []*GraphClause

GraphPatternClauses returns the list of graph pattern clauses

func (*Statement) Graphs

func (s *Statement) Graphs() []storage.Graph

Graphs returns the list of graphs listed on the statement.

func (*Statement) GroupBy added in v0.7.0

func (s *Statement) GroupBy() []string

GroupBy returns the available group by binding in the statement.

func (*Statement) GroupByBindings

func (s *Statement) GroupByBindings() []string

GroupByBindings returns the bindings used on the group by statement.

func (*Statement) HasHavingClause

func (s *Statement) HasHavingClause() bool

HasHavingClause returns true if there is a having clause.

func (*Statement) HasLimit added in v0.7.0

func (s *Statement) HasLimit() bool

HasLimit returns true if there is valid limit.

func (*Statement) HavingEvaluator

func (s *Statement) HavingEvaluator() Evaluator

HavingEvaluator returns the evaluator constructed for the provided having clause.

func (*Statement) HavingExpression added in v0.7.0

func (s *Statement) HavingExpression() []ConsumedElement

HavingExpression returns the avaible tokens in the haaving expression.

func (*Statement) Init added in v0.7.0

func (s *Statement) Init(ctx context.Context, st storage.Store) error

Init initializes all graphs given the graph names.

func (*Statement) InputBindings

func (s *Statement) InputBindings() []string

InputBindings returns the list of incoming bindings feed from a where clause.

func (*Statement) InputGraphNames added in v0.8.0

func (s *Statement) InputGraphNames() []string

InputGraphNames returns the list of input graphs listed on the statement.

func (*Statement) InputGraphs added in v0.8.0

func (s *Statement) InputGraphs() []storage.Graph

InputGraphs returns the list of input graphs listed on the statement.

func (*Statement) IsLimitSet

func (s *Statement) IsLimitSet() bool

IsLimitSet returns true if the limit is set.

func (*Statement) Limit

func (s *Statement) Limit() int64

Limit returns the limit value set in the limit clause.

func (*Statement) OrderBy added in v0.7.0

func (s *Statement) OrderBy() table.SortConfig

OrderBy returns the available order by binding in the statement.

func (*Statement) OrderByConfig

func (s *Statement) OrderByConfig() table.SortConfig

OrderByConfig returns the sort configuration specified by the order by statement.

func (*Statement) OutputBindings

func (s *Statement) OutputBindings() []string

OutputBindings returns the list of binding that a query will return.

func (*Statement) OutputGraphNames added in v0.8.0

func (s *Statement) OutputGraphNames() []string

OutputGraphNames returns the list of output graphs listed on the statement.

func (*Statement) OutputGraphs added in v0.8.0

func (s *Statement) OutputGraphs() []storage.Graph

OutputGraphs returns the list of output graphs listed on the statement.

func (*Statement) Projection added in v0.7.0

func (s *Statement) Projection() []*Projection

Projection returns the available projections in the statement.

func (*Statement) Projections

func (s *Statement) Projections() []*Projection

Projections returns all the available projections.

func (*Statement) ResetProjection

func (s *Statement) ResetProjection()

ResetProjection resets the current working variable projection.

func (*Statement) ResetWorkingConstructClause added in v0.8.0

func (s *Statement) ResetWorkingConstructClause()

ResetWorkingConstructClause resets the current working construct clause.

func (*Statement) ResetWorkingGraphClause

func (s *Statement) ResetWorkingGraphClause()

ResetWorkingGraphClause resets the current working graph clause.

func (*Statement) SortedGraphPatternClauses

func (s *Statement) SortedGraphPatternClauses() []*GraphClause

SortedGraphPatternClauses return the list of graph pattern clauses

func (*Statement) Type

func (s *Statement) Type() StatementType

Type returns the type of the statement.

func (*Statement) WorkingClause

func (s *Statement) WorkingClause() *GraphClause

WorkingClause returns the current working clause.

func (*Statement) WorkingConstructClause added in v0.8.0

func (s *Statement) WorkingConstructClause() *ConstructClause

WorkingConstructClause returns the current working construct clause.

func (*Statement) WorkingProjection

func (s *Statement) WorkingProjection() *Projection

WorkingProjection returns the current working variable projection.

type StatementType

type StatementType int8

StatementType describes the type of statement being represented.

const (
	// Query statement.
	Query StatementType = iota
	// Insert statement.
	Insert
	// Delete statement.
	Delete
	// Create statement.
	Create
	// Drop statement.
	Drop
	// Construct statement.
	Construct
)

func (StatementType) String

func (t StatementType) String() string

String provides a readable version of the StatementType.

type Symbol

type Symbol string

Symbol of the LLk left factored grammar.

func (Symbol) String

func (s Symbol) String() string

String returns a string representation of the symbol

Jump to

Keyboard shortcuts

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