graph

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2014 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TripleDirections = [4]string{"s", "p", "o", "c"}

List of the valid directions of a triple. TODO(barakmich): Replace all instances of "dir string" in the codebase with an enum of valid directions, to make this less stringly typed.

Functions

func BaseIteratorInit

func BaseIteratorInit(b *BaseIterator)

Called by subclases.

func BasicEquality

func BasicEquality(a, b TSVal) bool

Define an equality function of purely ==, which works for native types.

func CheckLogIn

func CheckLogIn(it Iterator, val TSVal)

Utility logging functions for when an iterator gets called Next upon, or Check upon, as well as what they return. Highly useful for tracing the execution path of a query.

func CheckLogOut

func CheckLogOut(it Iterator, val TSVal, good bool) bool

func NextLogIn

func NextLogIn(it Iterator)

func OutputQueryShapeForIterator

func OutputQueryShapeForIterator(it Iterator, ts TripleStore, outputMap *map[string]interface{})

func PrintResultTreeEvaluator

func PrintResultTreeEvaluator(it Iterator)

func RunIntOp

func RunIntOp(a int64, op ComparisonOperator, b int64) bool

func StringResultTreeEvaluator

func StringResultTreeEvaluator(it Iterator) string

Types

type AndIterator

type AndIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

The And iterator. Consists of a BaseIterator and a number of subiterators, the primary of which will be Next()ed if next is called.

func NewAndIterator

func NewAndIterator() *AndIterator

Creates a new And iterator.

func (*AndIterator) AddSubIterator

func (and *AndIterator) AddSubIterator(sub Iterator)

Add a subiterator to this And iterator.

The first iterator that is added becomes the primary iterator. This is important. Calling Optimize() is the way to change the order based on subiterator statistics. Without Optimize(), the order added is the order used.

func (*AndIterator) Check

func (and *AndIterator) Check(val TSVal) bool

Check a value against the entire iterator, in order.

func (*AndIterator) Clone

func (and *AndIterator) Clone() Iterator

func (*AndIterator) Close

func (and *AndIterator) Close()

Close this iterator, and, by extension, close the subiterators. Close should be idempotent, and it follows that if it's subiterators follow this contract, the And follows the contract.

func (*AndIterator) DebugString

func (and *AndIterator) DebugString(indent int) string

Prints information about this iterator.

func (*AndIterator) GetResultTree

func (and *AndIterator) GetResultTree() *ResultTree

DEPRECATED Returns the ResultTree for this iterator, recurses to it's subiterators.

func (*AndIterator) GetStats

func (and *AndIterator) GetStats() *IteratorStats

and.GetStats() lives here in and-iterator-optimize.go because it may in the future return different statistics based on how it is optimized. For now, however, it's pretty static.

func (*AndIterator) GetSubIterators

func (and *AndIterator) GetSubIterators() *list.List

Returns a list.List of the subiterators, in order (primary iterator first).

func (*AndIterator) Next

func (and *AndIterator) Next() (TSVal, bool)

Returns the Next value from the And iterator. Because the And is the intersection of its subiterators, it must choose one subiterator to produce a candidate, and check this value against the subiterators. A productive choice of primary iterator is therefore very important.

func (*AndIterator) NextResult

func (and *AndIterator) NextResult() bool

An And has no NextResult of its own -- that is, there are no other values which satisfy our previous result that are not the result itself. Our subiterators might, however, so just pass the call recursively.

func (*AndIterator) Optimize

func (and *AndIterator) Optimize() (Iterator, bool)

Optimizes the AndIterator, by picking the most efficient way to Next() and Check() its subiterators. For SQL fans, this is equivalent to JOIN.

func (*AndIterator) Reset

func (and *AndIterator) Reset()

Reset all internal iterators

func (*AndIterator) Size

func (and *AndIterator) Size() (int64, bool)

Returns the approximate size of the And iterator. Because we're dealing with an intersection, we know that the largest we can be is the size of the smallest iterator. This is the heuristic we shall follow. Better heuristics welcome.

func (*AndIterator) TagResults

func (and *AndIterator) TagResults(out *map[string]TSVal)

Overrides BaseIterator TagResults, as it needs to add it's own results and recurse down it's subiterators.

func (*AndIterator) Type

func (and *AndIterator) Type() string

Register this as an "and" iterator.

type BaseIterator

type BaseIterator struct {
	Last TSVal
	// contains filtered or unexported fields
}

The Base iterator is the iterator other iterators inherit from to get some default functionality.

func (*BaseIterator) AddFixedTag

func (b *BaseIterator) AddFixedTag(tag string, value TSVal)

func (*BaseIterator) AddTag

func (b *BaseIterator) AddTag(tag string)

Adds a tag to the iterator. Most iterators don't need to override.

func (*BaseIterator) Check

func (n *BaseIterator) Check(v TSVal) bool

Nothing in a base iterator.

func (*BaseIterator) CopyTagsFrom

func (b *BaseIterator) CopyTagsFrom(other_it Iterator)

func (*BaseIterator) DebugString

func (n *BaseIterator) DebugString(indent int) string

Prints a silly debug string. Most classes override.

func (*BaseIterator) FixedTags

func (b *BaseIterator) FixedTags() map[string]TSVal

func (*BaseIterator) GetResultTree

func (b *BaseIterator) GetResultTree() *ResultTree

DEPRECATED

func (*BaseIterator) GetStats

func (n *BaseIterator) GetStats() *IteratorStats

Base iterators should never appear in a tree if they are, select against them.

func (*BaseIterator) GetSubIterators

func (n *BaseIterator) GetSubIterators() *list.List

No subiterators. Only those with subiterators need to do anything here.

func (*BaseIterator) GetUid

func (b *BaseIterator) GetUid() int

func (*BaseIterator) LastResult

func (n *BaseIterator) LastResult() TSVal

Returns the last result of an iterator.

func (*BaseIterator) Next

func (n *BaseIterator) Next() (TSVal, bool)

Nothing in a base iterator.

func (*BaseIterator) NextResult

func (n *BaseIterator) NextResult() bool

func (*BaseIterator) Nextable

func (b *BaseIterator) Nextable() bool

Accessor

func (*BaseIterator) Reset

func (a *BaseIterator) Reset()

func (*BaseIterator) Size

func (n *BaseIterator) Size() (int64, bool)

If you're empty and you know it, clap your hands.

func (*BaseIterator) TagResults

func (a *BaseIterator) TagResults(out_map *map[string]TSVal)

Fill the map based on the tags assigned to this iterator. Default functionality works well for most iterators.

func (*BaseIterator) Tags

func (b *BaseIterator) Tags() []string

Returns the tags.

type ComparisonOperator

type ComparisonOperator int

type Equality

type Equality func(a, b TSVal) bool

Define the signature of an equality function.

type FixedIterator

type FixedIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

A Fixed iterator consists of it's values, an index (where it is in the process of Next()ing) and an equality function.

func NewFixedIteratorWithCompare

func NewFixedIteratorWithCompare(compareFn Equality) *FixedIterator

Creates a new Fixed iterator with a custom comparitor.

func (*FixedIterator) AddValue

func (f *FixedIterator) AddValue(v TSVal)

Add a value to the iterator. The array now contains this value. TODO(barakmich): This ought to be a set someday, disallowing repeated values.

func (*FixedIterator) Check

func (f *FixedIterator) Check(v TSVal) bool

Check if the passed value is equal to one of the values stored in the iterator.

func (*FixedIterator) Clone

func (f *FixedIterator) Clone() Iterator

func (*FixedIterator) Close

func (f *FixedIterator) Close()

func (*FixedIterator) DebugString

func (f *FixedIterator) DebugString(indent int) string

Print some information about the iterator.

func (*FixedIterator) GetStats

func (a *FixedIterator) GetStats() *IteratorStats

As we right now have to scan the entire list, Next and Check are linear with the size. However, a better data structure could remove these limits.

func (*FixedIterator) Next

func (f *FixedIterator) Next() (TSVal, bool)

Return the next stored value from the iterator.

func (*FixedIterator) Optimize

func (f *FixedIterator) Optimize() (Iterator, bool)

Optimize() for a Fixed iterator is simple. Returns a Null iterator if it's empty (so that other iterators upstream can treat this as null) or there is no optimization.

func (*FixedIterator) Reset

func (f *FixedIterator) Reset()

func (*FixedIterator) Size

func (f *FixedIterator) Size() (int64, bool)

Size is the number of values stored.

func (*FixedIterator) Type

func (f *FixedIterator) Type() string

Register this iterator as a Fixed iterator.

type HasaIterator

type HasaIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

A HasaIterator consists of a reference back to the TripleStore that it references, a primary subiterator, a direction in which the triples for that subiterator point, and a temporary holder for the iterator generated on Check().

func NewHasaIterator

func NewHasaIterator(ts TripleStore, subIt Iterator, dir string) *HasaIterator

Construct a new HasA iterator, given the triple subiterator, and the triple direction for which it stands.

func (*HasaIterator) Check

func (h *HasaIterator) Check(val TSVal) bool

Check a value against our internal iterator. In order to do this, we must first open a new iterator of "triples that have `val` in our direction", given to us by the triple store, and then Next() values out of that iterator and Check() them against our subiterator.

func (*HasaIterator) Clone

func (h *HasaIterator) Clone() Iterator

func (*HasaIterator) Close

func (h *HasaIterator) Close()

Close the subiterator, the result iterator (if any) and the HasA.

func (*HasaIterator) DebugString

func (h *HasaIterator) DebugString(indent int) string

Print some information about this iterator.

func (*HasaIterator) Direction

func (h *HasaIterator) Direction() string

Direction accessor.

func (*HasaIterator) GetCheckResult

func (h *HasaIterator) GetCheckResult() bool

GetCheckResult() is shared code between Check() and GetNextResult() -- calls next on the result iterator (a triple iterator based on the last checked value) and returns true if another match is made.

func (*HasaIterator) GetResultTree

func (h *HasaIterator) GetResultTree() *ResultTree

DEPRECATED Return results in a ResultTree.

func (*HasaIterator) GetStats

func (h *HasaIterator) GetStats() *IteratorStats

GetStats() returns the statistics on the HasA iterator. This is curious. Next cost is easy, it's an extra call or so on top of the subiterator Next cost. CheckCost involves going to the TripleStore, iterating out values, and hoping one sticks -- potentially expensive, depending on fanout. Size, however, is potentially smaller. we know at worst it's the size of the subiterator, but if there are many repeated values, it could be much smaller in totality.

func (*HasaIterator) GetSubIterators

func (h *HasaIterator) GetSubIterators() *list.List

Return our sole subiterator, in a list.List.

func (*HasaIterator) Next

func (h *HasaIterator) Next() (TSVal, bool)

Get the next result from this iterator. This is simpler than Check. We have a subiterator we can get a value from, and we can take that resultant triple, pull our direction out of it, and return that.

func (*HasaIterator) NextResult

func (h *HasaIterator) NextResult() bool

Get the next result that matches this branch.

func (*HasaIterator) Optimize

func (h *HasaIterator) Optimize() (Iterator, bool)

Pass the Optimize() call along to the subiterator. If it becomes Null, then the HasA becomes Null (there are no triples that have any directions).

func (*HasaIterator) Reset

func (h *HasaIterator) Reset()

func (*HasaIterator) TagResults

func (h *HasaIterator) TagResults(out *map[string]TSVal)

Pass the TagResults down the chain.

func (*HasaIterator) Type

func (h *HasaIterator) Type() string

Register this iterator as a HasA.

type HttpSession

type HttpSession interface {
	// Return whether the string is a valid expression.
	InputParses(string) (ParseResult, error)
	// Runs the query and returns individual results on the channel.
	ExecInput(string, chan interface{}, int)
	GetQuery(string, chan map[string]interface{})
	BuildJson(interface{})
	GetJson() (interface{}, error)
	ClearJson()
	ToggleDebug()
}

type Int64AllIterator

type Int64AllIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

An All iterator across a range of int64 values, from `max` to `min`.

func NewInt64AllIterator

func NewInt64AllIterator(min, max int64) *Int64AllIterator

Creates a new Int64AllIterator with the given range.

func (*Int64AllIterator) Check

func (a *Int64AllIterator) Check(tsv TSVal) bool

Check() for an Int64AllIterator is merely seeing if the passed value is withing the range, assuming the value is an int64.

func (*Int64AllIterator) Clone

func (a *Int64AllIterator) Clone() Iterator

func (*Int64AllIterator) Close

func (a *Int64AllIterator) Close()

func (*Int64AllIterator) DebugString

func (a *Int64AllIterator) DebugString(indent int) string

Prints the All iterator as just an "all".

func (*Int64AllIterator) GetStats

func (a *Int64AllIterator) GetStats() *IteratorStats

Stats for an Int64AllIterator are simple. Super cheap to do any operation, and as big as the range.

func (*Int64AllIterator) Next

func (a *Int64AllIterator) Next() (TSVal, bool)

Next() on an Int64 all iterator is a simple incrementing counter. Return the next integer, and mark it as the result.

func (*Int64AllIterator) Optimize

func (a *Int64AllIterator) Optimize() (Iterator, bool)

There's nothing to optimize about this little iterator.

func (*Int64AllIterator) Reset

func (a *Int64AllIterator) Reset()

Start back at the beginning

func (*Int64AllIterator) Size

func (a *Int64AllIterator) Size() (int64, bool)

The number of elements in an Int64AllIterator is the size of the range. The size is exact.

func (*Int64AllIterator) Type

func (a *Int64AllIterator) Type() string

The type of this iterator is an "all". This is important, as it puts it in the class of "all iterators.

type Iterator

type Iterator interface {
	// Tags are the way we handle results. By adding a tag to an iterator, we can
	// "name" it, in a sense, and at each step of iteration, get a named result.
	// TagResults() is therefore the handy way of walking an iterator tree and
	// getting the named results.
	//
	// Tag Accessors.
	AddTag(string)
	Tags() []string
	AddFixedTag(string, TSVal)
	FixedTags() map[string]TSVal
	CopyTagsFrom(Iterator)
	// Fills a tag-to-result-value map.
	TagResults(*map[string]TSVal)
	// Returns the current result.
	LastResult() TSVal
	// DEPRECATED -- Fills a ResultTree struct with Result().
	GetResultTree() *ResultTree

	// These methods are the heart and soul of the iterator, as they constitute
	// the iteration interface.
	//
	// To get the full results of iteraton, do the following:
	// while (!Next()):
	//   emit result
	//   while (!NextResult()):
	//       emit result
	//
	// All of them should set iterator.Last to be the last returned value, to
	// make results work.
	//
	// Next() advances the iterator and returns the next valid result. Returns
	// (<value>, true) or (nil, false)
	Next() (TSVal, bool)
	// NextResult() advances iterators that may have more than one valid result,
	// from the bottom up.
	NextResult() bool
	// Check(), given a value, returns whether or not that value is within the set
	// held by this iterator.
	Check(TSVal) bool
	// Start iteration from the beginning
	Reset()
	// Create a new iterator just like this one
	Clone() Iterator
	// These methods relate to choosing the right iterator, or optimizing an
	// iterator tree
	//
	// GetStats() returns the relative costs of calling the iteration methods for
	// this iterator, as well as the size. Roughly, it will take NextCost * Size
	// "cost units" to get everything out of the iterator. This is a wibbly-wobbly
	// thing, and not exact, but a useful heuristic.
	GetStats() *IteratorStats
	// Helpful accessor for the number of things in the iterator. The first return
	// value is the size, and the second return value is whether that number is exact,
	// or a conservative estimate.
	Size() (int64, bool)
	// Returns a string relating to what the function of the iterator is. By
	// knowing the names of the iterators, we can devise optimization strategies.
	Type() string
	// Optimizes an iterator. Can replace the iterator, or merely move things
	// around internally. if it chooses to replace it with a better iterator,
	// returns (the new iterator, true), if not, it returns (self, false).
	Optimize() (Iterator, bool)
	// Return a list of the subiterators for this iterator.
	GetSubIterators() *list.List

	// Return a string representation of the iterator, indented by the given amount.
	DebugString(int) string
	// Return whether this iterator is relaiably nextable. Most iterators are.
	// However, some iterators, like "not" are, by definition, the whole database
	// except themselves. Next() on these is unproductive, if impossible.
	Nextable() bool
	// Close the iterator and do internal cleanup.
	Close()
	GetUid() int
}

type IteratorStats

type IteratorStats struct {
	CheckCost int64
	NextCost  int64
	Size      int64
}
type Link struct {
	Source   int `json:"source"`
	Target   int `json:"target"`
	Pred     int `json:"type"`
	LinkNode int `json:"link_node"`
}

type LinksToIterator

type LinksToIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

A LinksTo has a reference back to the TripleStore (to create the iterators for each node) the subiterator, and the direction the iterator comes from. `next_it` is the tempoarary iterator held per result in `primary_it`.

func NewLinksToIterator

func NewLinksToIterator(ts TripleStore, it Iterator, dir string) *LinksToIterator

Construct a new LinksTo iterator around a direction and a subiterator of nodes.

func (*LinksToIterator) Check

func (l *LinksToIterator) Check(val TSVal) bool

If it checks in the right direction for the subiterator, it is a valid link for the LinksTo.

func (*LinksToIterator) Clone

func (l *LinksToIterator) Clone() Iterator

func (*LinksToIterator) Close

func (l *LinksToIterator) Close()

Close our subiterators.

func (*LinksToIterator) DebugString

func (l *LinksToIterator) DebugString(indent int) string

Print the iterator.

func (*LinksToIterator) Direction

func (l *LinksToIterator) Direction() string

Return the direction under consideration.

func (*LinksToIterator) GetResultTree

func (l *LinksToIterator) GetResultTree() *ResultTree

DEPRECATED

func (*LinksToIterator) GetStats

func (l *LinksToIterator) GetStats() *IteratorStats

Return a guess as to how big or costly it is to next the iterator.

func (*LinksToIterator) GetSubIterators

func (lto *LinksToIterator) GetSubIterators() *list.List

Return a list containing only our subiterator.

func (*LinksToIterator) Next

func (l *LinksToIterator) Next() (TSVal, bool)

Next()ing a LinksTo operates as described above.

func (*LinksToIterator) NextResult

func (l *LinksToIterator) NextResult() bool

We won't ever have a new result, but our subiterators might.

func (*LinksToIterator) Optimize

func (lto *LinksToIterator) Optimize() (Iterator, bool)

Optimize the LinksTo, by replacing it if it can be.

func (*LinksToIterator) Reset

func (l *LinksToIterator) Reset()

func (*LinksToIterator) TagResults

func (l *LinksToIterator) TagResults(out *map[string]TSVal)

Tag these results, and our subiterator's results.

func (*LinksToIterator) Type

func (l *LinksToIterator) Type() string

Register the LinksTo.

type Node

type Node struct {
	Id         int      `json:"id"`
	Tags       []string `json:"tags,omitempty"`
	Values     []string `json:"values,omitempty"`
	IsLinkNode bool     `json:"is_link_node"`
	IsFixed    bool     `json:"is_fixed"`
}

type NullIterator

type NullIterator struct {
	BaseIterator
}

Here we define the simplest base iterator -- the Null iterator. It contains nothing. It is the empty set. Often times, queries that contain one of these match nothing, so it's important to give it a special iterator.

func NewNullIterator

func NewNullIterator() *NullIterator

Fairly useless New function.

func (*NullIterator) Clone

func (n *NullIterator) Clone() Iterator

func (*NullIterator) Close

func (a *NullIterator) Close()

Nothing to clean up. func (a *BaseIterator) Close() {}

func (*NullIterator) DebugString

func (n *NullIterator) DebugString(indent int) string

Print the null iterator.

func (*NullIterator) GetStats

func (n *NullIterator) GetStats() *IteratorStats

A null iterator costs nothing. Use it!

func (*NullIterator) Optimize

func (n *NullIterator) Optimize() (Iterator, bool)

A good iterator will close itself when it returns true. Null has nothing it needs to do.

func (*NullIterator) Type

func (n *NullIterator) Type() string

Name the null iterator.

type OptionalIterator

type OptionalIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

An optional iterator has the subconstraint iterator we wish to be optional and whether the last check we received was true or false.

func NewOptionalIterator

func NewOptionalIterator(it Iterator) *OptionalIterator

Creates a new optional iterator.

func (*OptionalIterator) Check

func (o *OptionalIterator) Check(val TSVal) bool

Check() is the real hack of this iterator. It always returns true, regardless of whether the subiterator matched. But we keep track of whether the subiterator matched for results purposes.

func (*OptionalIterator) Clone

func (o *OptionalIterator) Clone() Iterator

func (*OptionalIterator) Close

func (o *OptionalIterator) Close()

func (*OptionalIterator) DebugString

func (o *OptionalIterator) DebugString(indent int) string

Prints the optional and it's subiterator.

func (*OptionalIterator) GetStats

func (o *OptionalIterator) GetStats() *IteratorStats

We're only as expensive as our subiterator. Except, we can't be nexted.

func (*OptionalIterator) Next

func (o *OptionalIterator) Next() (TSVal, bool)

Nexting the iterator is unsupported -- error and return an empty set. (As above, a reasonable alternative would be to Next() an all iterator)

func (*OptionalIterator) NextResult

func (o *OptionalIterator) NextResult() bool

An optional iterator only has a next result if, (a) last time we checked we had any results whatsoever, and (b) there was another subresult in our optional subbranch.

func (*OptionalIterator) Optimize

func (o *OptionalIterator) Optimize() (Iterator, bool)

There's nothing to optimize for an optional. Optimize the subiterator and potentially replace it.

func (*OptionalIterator) Reset

func (o *OptionalIterator) Reset()

func (*OptionalIterator) TagResults

func (o *OptionalIterator) TagResults(out *map[string]TSVal)

If we failed the check, then the subiterator should not contribute to the result set. Otherwise, go ahead and tag it.

func (*OptionalIterator) Type

func (o *OptionalIterator) Type() string

Registers the optional iterator.

type OptionsDict

type OptionsDict map[string]interface{}

func (OptionsDict) GetIntKey

func (d OptionsDict) GetIntKey(key string) (int, bool)

func (OptionsDict) GetStringKey

func (d OptionsDict) GetStringKey(key string) (string, bool)

type OrIterator

type OrIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

func NewOrIterator

func NewOrIterator() *OrIterator

func NewShortCircuitOrIterator

func NewShortCircuitOrIterator() *OrIterator

func (*OrIterator) AddSubIterator

func (or *OrIterator) AddSubIterator(sub Iterator)

Add a subiterator to this Or iterator. Order matters.

func (*OrIterator) Check

func (or *OrIterator) Check(val TSVal) bool

Check a value against the entire iterator, in order.

func (*OrIterator) Clone

func (or *OrIterator) Clone() Iterator

func (*OrIterator) Close

func (or *OrIterator) Close()

Close this iterator, and, by extension, close the subiterators. Close should be idempotent, and it follows that if it's subiterators follow this contract, the And follows the contract.

func (*OrIterator) DebugString

func (or *OrIterator) DebugString(indent int) string

Prints information about this iterator.

func (*OrIterator) GetResultTree

func (or *OrIterator) GetResultTree() *ResultTree

DEPRECATED Returns the ResultTree for this iterator, recurses to it's subiterators.

func (*OrIterator) GetStats

func (or *OrIterator) GetStats() *IteratorStats

func (*OrIterator) GetSubIterators

func (or *OrIterator) GetSubIterators() *list.List

Returns a list.List of the subiterators, in order.

func (*OrIterator) Next

func (or *OrIterator) Next() (TSVal, bool)

Returns the Next value from the Or iterator. Because the Or is the union of its subiterators, it must produce from all subiterators -- unless it's shortcircuiting, in which case, it's the first one that returns anything.

func (*OrIterator) NextResult

func (or *OrIterator) NextResult() bool

An Or has no NextResult of its own -- that is, there are no other values which satisfy our previous result that are not the result itself. Our subiterators might, however, so just pass the call recursively. In the case of shortcircuiting, only allow new results from the currently checked iterator

func (*OrIterator) Optimize

func (or *OrIterator) Optimize() (Iterator, bool)

func (*OrIterator) Reset

func (or *OrIterator) Reset()

Reset all internal iterators

func (*OrIterator) Size

func (or *OrIterator) Size() (int64, bool)

Returns the approximate size of the Or iterator. Because we're dealing with a union, we know that the largest we can be is the sum of all the iterators, or in the case of short-circuiting, the longest.

func (*OrIterator) TagResults

func (or *OrIterator) TagResults(out *map[string]TSVal)

Overrides BaseIterator TagResults, as it needs to add it's own results and recurse down it's subiterators.

func (*OrIterator) Type

func (or *OrIterator) Type() string

Register this as an "or" iterator.

type ParseResult

type ParseResult int
const (
	Parsed ParseResult = iota
	ParseMore
	ParseFail
)

type ResultTree

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

func NewResultTree

func NewResultTree(result TSVal) *ResultTree

func (*ResultTree) AddSubtree

func (tree *ResultTree) AddSubtree(sub *ResultTree)

func (*ResultTree) ToString

func (tree *ResultTree) ToString() string

type Session

type Session interface {
	// Return whether the string is a valid expression.
	InputParses(string) (ParseResult, error)
	ExecInput(string, chan interface{}, int)
	ToText(interface{}) string
	ToggleDebug()
}

type TSVal

type TSVal interface{}

Defines an opaque "triple store value" type. However the backend wishes to implement it, a TSVal is merely a token to a triple or a node that the backing store itself understands, and the base iterators pass around.

For example, in a very traditional, graphd-style graph, these are int64s (guids of the primitives). In a very direct sort of graph, these could be pointers to structs, or merely triples, or whatever works best for the backing store.

func NextLogOut

func NextLogOut(it Iterator, val TSVal, ok bool) (TSVal, bool)

type TestTripleStore

type TestTripleStore struct {
	mock.Mock
}

func (*TestTripleStore) AddTriple

func (ts *TestTripleStore) AddTriple(*Triple)

func (*TestTripleStore) AddTripleSet

func (ts *TestTripleStore) AddTripleSet([]*Triple)

func (*TestTripleStore) Close

func (ts *TestTripleStore) Close()

func (*TestTripleStore) DebugPrint

func (ts *TestTripleStore) DebugPrint()

func (*TestTripleStore) GetIdFor

func (ts *TestTripleStore) GetIdFor(s string) TSVal

func (*TestTripleStore) GetIteratorByString

func (ts *TestTripleStore) GetIteratorByString(string, string, string) Iterator

func (*TestTripleStore) GetNameFor

func (ts *TestTripleStore) GetNameFor(v TSVal) string

func (*TestTripleStore) GetNodesAllIterator

func (ts *TestTripleStore) GetNodesAllIterator() Iterator

func (*TestTripleStore) GetTriple

func (ts *TestTripleStore) GetTriple(TSVal) *Triple

func (*TestTripleStore) GetTripleDirection

func (ts *TestTripleStore) GetTripleDirection(TSVal, string) TSVal

func (*TestTripleStore) GetTripleIterator

func (ts *TestTripleStore) GetTripleIterator(s string, i TSVal) Iterator

func (*TestTripleStore) GetTriplesAllIterator

func (ts *TestTripleStore) GetTriplesAllIterator() Iterator

func (*TestTripleStore) MakeFixed

func (ts *TestTripleStore) MakeFixed() *FixedIterator

func (*TestTripleStore) OptimizeIterator

func (ts *TestTripleStore) OptimizeIterator(it Iterator) (Iterator, bool)

func (*TestTripleStore) RemoveTriple

func (ts *TestTripleStore) RemoveTriple(t *Triple)

func (*TestTripleStore) Size

func (ts *TestTripleStore) Size() int64

type Triple

type Triple struct {
	Sub        string `json:"subject"`
	Pred       string `json:"predicate"`
	Obj        string `json:"object"`
	Provenance string `json:"provenance,omitempty"`
}

Our triple struct, used throughout.

func MakeTriple

func MakeTriple(sub string, pred string, obj string, provenance string) *Triple

func NewTriple

func NewTriple() *Triple

func (*Triple) Equals

func (t *Triple) Equals(other *Triple) bool

func (*Triple) Get

func (t *Triple) Get(dir string) string

Per-field accessor for triples

func (*Triple) IsValid

func (t *Triple) IsValid() bool

func (*Triple) ToNTriple

func (t *Triple) ToNTriple() string

Prints a triple in N-Triple format.

func (*Triple) ToString

func (t *Triple) ToString() string

Pretty-prints a triple.

type TripleStore

type TripleStore interface {
	// Add a triple to the store.
	AddTriple(*Triple)

	// Add a set of triples to the store, atomically if possible.
	AddTripleSet([]*Triple)

	// Removes a triple matching the given one  from the database,
	// if it exists. Does nothing otherwise.
	RemoveTriple(*Triple)

	// Given an opaque token, returns the triple for that token from the store.
	GetTriple(TSVal) *Triple

	// Given a direction and a token, creates an iterator of links which have
	// that node token in that directional field.
	GetTripleIterator(string, TSVal) Iterator

	// Returns an iterator enumerating all nodes in the graph.
	GetNodesAllIterator() Iterator

	// Returns an iterator enumerating all links in the graph.
	GetTriplesAllIterator() Iterator

	// Given a node ID, return the opaque token used by the TripleStore
	// to represent that id.
	GetIdFor(string) TSVal

	// Given an opaque token, return the node that it represents.
	GetNameFor(TSVal) string

	// Returns the number of triples currently stored.
	Size() int64

	// Creates a Fixed iterator which can compare TSVals
	MakeFixed() *FixedIterator

	// Optimize an iterator in the context of the triple store.
	// Suppose we have a better index for the passed tree; this
	// gives the TripleStore the oppotunity to replace it
	// with a more efficient iterator.
	OptimizeIterator(it Iterator) (Iterator, bool)

	// Close the triple store and clean up. (Flush to disk, cleanly
	// sever connections, etc)
	Close()

	// Convienence function for speed. Given a triple token and a direction
	// return the node token for that direction. Sometimes, a TripleStore
	// can do this without going all the way to the backing store, and
	// gives the TripleStore the opportunity to make this optimization.
	//
	// Iterators will call this. At worst, a valid implementation is
	// self.GetIdFor(self.GetTriple(triple_id).Get(dir))
	GetTripleDirection(triple_id TSVal, dir string) TSVal
}

type ValueComparisonIterator

type ValueComparisonIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

func NewValueComparisonIterator

func NewValueComparisonIterator(
	subIt Iterator,
	operator ComparisonOperator,
	value interface{},
	ts TripleStore) *ValueComparisonIterator

func (*ValueComparisonIterator) Check

func (vc *ValueComparisonIterator) Check(val TSVal) bool

func (*ValueComparisonIterator) Clone

func (vc *ValueComparisonIterator) Clone() Iterator

func (*ValueComparisonIterator) Close

func (vc *ValueComparisonIterator) Close()

func (*ValueComparisonIterator) DebugString

func (vc *ValueComparisonIterator) DebugString(indent int) string

Prints the value-comparison and its subiterator.

func (*ValueComparisonIterator) GetStats

func (vc *ValueComparisonIterator) GetStats() *IteratorStats

We're only as expensive as our subiterator. Again, optimized value comparison iterators should do better.

func (*ValueComparisonIterator) Next

func (vc *ValueComparisonIterator) Next() (TSVal, bool)

func (*ValueComparisonIterator) NextResult

func (vc *ValueComparisonIterator) NextResult() bool

func (*ValueComparisonIterator) Optimize

func (vc *ValueComparisonIterator) Optimize() (Iterator, bool)

There's nothing to optimize, locally, for a value-comparison iterator. Replace the underlying iterator if need be. potentially replace it.

func (*ValueComparisonIterator) Reset

func (vc *ValueComparisonIterator) Reset()

func (*ValueComparisonIterator) TagResults

func (vc *ValueComparisonIterator) TagResults(out *map[string]TSVal)

If we failed the check, then the subiterator should not contribute to the result set. Otherwise, go ahead and tag it.

func (*ValueComparisonIterator) Type

func (vc *ValueComparisonIterator) Type() string

Registers the value-comparison iterator.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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