knowledge

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAndOrExpressionFromLinks(links AndOrLinks) (string, error)

func MeasureDuration

func MeasureDuration(Func func()) time.Duration

func StringSliceElementsEqual

func StringSliceElementsEqual(s1 []string, s2 []string) bool

Types

type AndOrLinks struct {
	And  []AndOrLinks
	Or   []AndOrLinks
	Link *QueryLink
}

type Asset

type Asset AssetKey

Asset represent the asset with details

func NewAsset

func NewAsset(assetType schema.AssetType, assetKey string) Asset

NewAsset create a new asset from type and key

type AssetKey

type AssetKey struct {
	Type schema.AssetType `json:"type"`
	Key  string           `json:"key"`
}

AssetKey represent the key of the asset

type AssetWithID

type AssetWithID struct {
	ID    string `json:"_id"`
	Asset `json:",inline"`
}

func (AssetWithID) String

func (a AssetWithID) String() string

type Cursor

type Cursor interface {
	HasMore() bool
	Read(ctx context.Context, doc interface{}) error
	Close() error
}

Cursor is a cursor over the results

type ExpressionBuilder

type ExpressionBuilder struct {
	NodeRepository     *QueryNodeRepository
	RelationRepository *QueryRelationRepository

	Aggregation    bool
	ExpressionType ExpressionType
}

func NewExpressionBuilder

func NewExpressionBuilder(nodeRepo *QueryNodeRepository, relationRepo *QueryRelationRepository) *ExpressionBuilder

type ExpressionType

type ExpressionType int
const (
	NodeExprType     ExpressionType = iota
	EdgeExprType     ExpressionType = iota
	PropertyExprType ExpressionType = iota
)

type Graph

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

Graph represent a Graph

func NewGraph

func NewGraph() *Graph

NewGraph create a graph

func (*Graph) AddAsset

func (g *Graph) AddAsset(assetType schema.AssetType, assetKey string) AssetKey

AddAsset add an asset to the graph

func (*Graph) AddRelation

func (g *Graph) AddRelation(from AssetKey, relationType schema.RelationKeyType, to AssetKey) Relation

AddRelation add a relation to the graph

func (*Graph) Assets

func (g *Graph) Assets() []Asset

Assets return the assets in the graph

func (*Graph) Copy

func (g *Graph) Copy() *Graph

Copy perform a deep copy of the graph

func (*Graph) Equal

func (g *Graph) Equal(other *Graph) bool

Equal return true if graphs are equal, otherwise return false

func (*Graph) ExtractSchema

func (g *Graph) ExtractSchema() schema.SchemaGraph

func (*Graph) HasAsset

func (g *Graph) HasAsset(asset Asset) bool

HasAsset return true if the asset is in the graph, false otherwise.

func (*Graph) HasRelation

func (g *Graph) HasRelation(relation Relation) bool

HasRelation return true if the relation is in the graph, false otherwise.

func (*Graph) MarshalJSON

func (sg *Graph) MarshalJSON() ([]byte, error)

func (*Graph) Merge

func (g *Graph) Merge(other *Graph)

Merge merge other graph into the current graph

func (*Graph) Relations

func (g *Graph) Relations() []Relation

Relations return the relations in the graph

func (*Graph) UnmarshalJSON

func (sg *Graph) UnmarshalJSON(b []byte) error

type GraphAPI

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

GraphEmitter an emitter of full source graph

func NewGraphAPI

func NewGraphAPI(url, authToken string, skipVerify bool) *GraphAPI

NewGraphEmitter create an emitter of graph

func (*GraphAPI) ReadCurrentGraph

func (gapi *GraphAPI) ReadCurrentGraph() (*Graph, error)

ReadCurrentGraph read the current graph stored in graph kb

func (*GraphAPI) UpdateGraph

func (gapi *GraphAPI) UpdateGraph(sg schema.SchemaGraph, updates GraphUpdatesBulk) error

type GraphBinder

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

GraphBinder represent a graph builder which bind assets and relations to graph schema provided by the source

func NewGraphBinder

func NewGraphBinder(graph *Graph) *GraphBinder

NewGraphBinder create an instance of graph binder

func (*GraphBinder) Bind

func (gb *GraphBinder) Bind(asset string, assetType schema.AssetType)

Bind bind one asset to a type

func (*GraphBinder) Relate

func (gb *GraphBinder) Relate(from string, relationType schema.RelationType, to string)

Relate relate one asset to another

type GraphDB

type GraphDB interface {
	Close() error

	InitializeSchema() error

	UpdateGraph(source string, bulk *GraphUpdatesBulk) error
	ReadGraph(source string, graph *Graph) error

	FlushAll() error

	CountAssets() (int64, error)
	CountRelations() (int64, error)

	Query(ctx context.Context, query *query.QueryIL) (*GraphQueryResult, error)
}

GraphDB an interface to a graph DB such as Arango or neo4j

type GraphImporter

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

GraphImporter an interface for importers allowing to read current graph and push graph updates

func NewGraphImporter

func NewGraphImporter(api *GraphAPI) *GraphImporter

NewGraphEmitter create an emitter of graph

func (*GraphImporter) CreateTransaction

func (gi *GraphImporter) CreateTransaction(currentGraph *Graph) *Transaction

CreateTransaction create a full graph transaction. This kind of transaction will diff the new graph with previous version of it.

func (*GraphImporter) ReadCurrentGraph

func (gi *GraphImporter) ReadCurrentGraph() (*Graph, error)

type GraphJSON

type GraphJSON struct {
	Assets    []Asset    `json:"assets"`
	Relations []Relation `json:"relations"`
}

GraphJSON is the json representation of a graph

type GraphQueryResult

type GraphQueryResult struct {
	Cursor      Cursor
	Projections []Projection
}

type GraphUpdateRequestBody

type GraphUpdateRequestBody struct {
	Updates *GraphUpdatesBulk  `json:"updates"`
	Schema  schema.SchemaGraph `json:"schema"`
}

type GraphUpdater

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

SourceListener represents the source listener waiting for source events

func NewGraphUpdater

func NewGraphUpdater(graphDB GraphDB, schemaPersistor schema.Persistor) *GraphUpdater

NewGraphUpdater create a new instance of graph updater

func (*GraphUpdater) Listen

func (sl *GraphUpdater) Listen(updatesC chan SourceSubGraphUpdates) chan struct{}

Listen events coming from the event bus

type GraphUpdatesBulk

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

GraphUpdatesBulk represent a bulk of asset and relation updates to perform on the graph

func GenerateGraphUpdatesBulk

func GenerateGraphUpdatesBulk(previousGraph *Graph, newGraph *Graph) *GraphUpdatesBulk

GenerateGraphUpdatesBulk generate a graph update bulk by taking the difference between new graph and previous graph. It means the updates would transform previous graph into new graph.

func NewGraphUpdatesBulk

func NewGraphUpdatesBulk() *GraphUpdatesBulk

NewGraphUpdatesBulk create an instance of graph updates

func (*GraphUpdatesBulk) Clear

func (gub *GraphUpdatesBulk) Clear()

func (*GraphUpdatesBulk) GetAssetRemovals

func (gub *GraphUpdatesBulk) GetAssetRemovals() []Asset

func (*GraphUpdatesBulk) GetAssetUpserts

func (gub *GraphUpdatesBulk) GetAssetUpserts() []Asset

func (*GraphUpdatesBulk) GetRelationRemovals

func (gub *GraphUpdatesBulk) GetRelationRemovals() []Relation

func (*GraphUpdatesBulk) GetRelationUpserts

func (gub *GraphUpdatesBulk) GetRelationUpserts() []Relation

func (*GraphUpdatesBulk) HasAssetRemoval

func (gub *GraphUpdatesBulk) HasAssetRemoval(asset Asset) bool

func (*GraphUpdatesBulk) HasAssetUpsert

func (gub *GraphUpdatesBulk) HasAssetUpsert(asset Asset) bool

func (*GraphUpdatesBulk) HasRelationRemoval

func (gub *GraphUpdatesBulk) HasRelationRemoval(relation Relation) bool

func (*GraphUpdatesBulk) HasRelationUpsert

func (gub *GraphUpdatesBulk) HasRelationUpsert(relation Relation) bool

func (*GraphUpdatesBulk) MarshalJSON

func (gub *GraphUpdatesBulk) MarshalJSON() ([]byte, error)

func (*GraphUpdatesBulk) RemoveAsset

func (gub *GraphUpdatesBulk) RemoveAsset(asset Asset)

RemoveAsset create an operation to remove an asset

func (*GraphUpdatesBulk) RemoveAssets

func (gub *GraphUpdatesBulk) RemoveAssets(assets ...Asset)

RemoveAssets create multiple asset removal operations

func (*GraphUpdatesBulk) RemoveRelation

func (gub *GraphUpdatesBulk) RemoveRelation(relation Relation)

RemoveRelation create an operation to remove a relation

func (*GraphUpdatesBulk) RemoveRelations

func (gub *GraphUpdatesBulk) RemoveRelations(relations ...Relation)

RemoveRelations create multiple relation removal operations

func (*GraphUpdatesBulk) UnmarshalJSON

func (gub *GraphUpdatesBulk) UnmarshalJSON(bytes []byte) error

func (*GraphUpdatesBulk) UpsertAsset

func (gub *GraphUpdatesBulk) UpsertAsset(asset Asset)

UpsertAsset create an operation to upsert an asset

func (*GraphUpdatesBulk) UpsertAssets

func (gub *GraphUpdatesBulk) UpsertAssets(assets ...Asset)

UpsertAssets append multiple assets to upsert

func (*GraphUpdatesBulk) UpsertRelation

func (gub *GraphUpdatesBulk) UpsertRelation(relation Relation)

UpsertRelation create an operation to upsert an relation

func (*GraphUpdatesBulk) UpsertRelations

func (gub *GraphUpdatesBulk) UpsertRelations(relations ...Relation)

UpsertRelations create multiple relation upsert operations

type GraphUpdatesBulkJSON

type GraphUpdatesBulkJSON struct {
	AssetUpserts     []Asset    `json:"asset_upserts"`
	AssetRemovals    []Asset    `json:"asset_removals"`
	RelationUpserts  []Relation `json:"relation_upserts"`
	RelationRemovals []Relation `json:"relation_removals"`
}

GraphUpdatesBulkJSON represent a bulk in JSON form

type Projection

type Projection struct {
	Alias          string
	ExpressionType ExpressionType
}

type Querier

type Querier struct {
	GraphDB GraphDB
}

func NewQuerier

func NewQuerier(db GraphDB) *Querier

func (*Querier) Query

func (q *Querier) Query(ctx context.Context, cypherQuery string) (*QuerierResult, error)

type QuerierResult

type QuerierResult struct {
	Cursor      Cursor
	Projections []Projection
	Statistics  Statistics
}
type QueryLink struct {
	From  int
	To    int
	Index int
}

type QueryNode

type QueryNode struct {
	Labels []string
}

QueryNode represent a node type

type QueryNodeRepository

type QueryNodeRepository struct {
	All           []QueryNode
	Anonymous     []QueryNode
	Named         map[string]QueryNode
	NamedPosition map[string]int
}

QueryNodeRepository represent a node repository

func NewQueryNodeRepository

func NewQueryNodeRepository() *QueryNodeRepository

NewQueryNodeRepository create a node repository

func (*QueryNodeRepository) ByName

func (qnr *QueryNodeRepository) ByName(name string) (*QueryNode, int)

ByName return the query node attached to given variable name

func (*QueryNodeRepository) Nodes

func (qnr *QueryNodeRepository) Nodes() []QueryNode

Nodes return the list of nodes contained in repository

func (*QueryNodeRepository) PushNode

func (qnr *QueryNodeRepository) PushNode(q *query.QueryNodePattern) (int, error)

PushNode push a node in the repository

type QueryRelation

type QueryRelation struct {
	Labels []string
}

QueryRelation represent a relation

type QueryRelationRepository

type QueryRelationRepository struct {
	All           []QueryRelation
	Anonymous     []QueryRelation
	Named         map[string]QueryRelation
	NamedPosition map[string]int
}

QueryRelationRepository is a repository of relations

func NewQueryRelationRepository

func NewQueryRelationRepository() *QueryRelationRepository

NewQueryRelationRepository create a relation repository

func (*QueryRelationRepository) ByName

func (qnr *QueryRelationRepository) ByName(name string) (*QueryRelation, int)

ByName return the relation attached to given variable name

func (*QueryRelationRepository) PushRelation

PushRelation push a relation into the repository

func (*QueryRelationRepository) Relations

func (qnr *QueryRelationRepository) Relations() []QueryRelation

Relations return the list of relations contained in the repository

type Relation

type Relation RelationKey

Relation represent the relation with details

type RelationKey

type RelationKey struct {
	Type schema.RelationKeyType `json:"type"`
	From AssetKey               `json:"from"`
	To   AssetKey               `json:"to"`
}

RelationKey a relation key of the KB

type RelationWithID

type RelationWithID struct {
	ID   string                 `json:"_id"`
	From string                 `json:"from_id"`
	To   string                 `json:"to_id"`
	Type schema.RelationKeyType `json:"type"`
}

func (RelationWithID) String

func (r RelationWithID) String() string

type SQLQueryTranslator

type SQLQueryTranslator struct {
	NodeRepository     *QueryNodeRepository
	RelationRepository *QueryRelationRepository
}

func NewSQLQueryTranslator

func NewSQLQueryTranslator() *SQLQueryTranslator

func (*SQLQueryTranslator) Translate

func (sqt *SQLQueryTranslator) Translate(queryIL *query.QueryIL) (*SQLTranslation, error)

type SQLTranslation

type SQLTranslation struct {
	Query           string
	ProjectionTypes []Projection
}

type SourceSubGraphUpdates

type SourceSubGraphUpdates struct {
	Updates GraphUpdatesBulk
	Schema  schema.SchemaGraph
	Source  string
}

SourceSubGraphUpdates represents the updates to perform on a source subgraph

type Statistics

type Statistics struct {
	Parsing   time.Duration
	Execution time.Duration
}

type Transaction

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

Transaction represent a transaction generating updates by diffing the provided graph against the previous version.

func (*Transaction) Bind

func (cgt *Transaction) Bind(asset string, assetType schema.AssetType)

Bind bind one asset to an asset type from the schema

func (*Transaction) Commit

func (cgt *Transaction) Commit() (*Graph, error)

Commit commit the transaction and gives ownership to the source for caching.

func (*Transaction) Relate

func (cgt *Transaction) Relate(from string, relationType schema.RelationType, to string)

Relate create a relation between two assets

Jump to

Keyboard shortcuts

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