linker

package
v0.0.0-...-90229f9 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSegmented = errors.New("document not segmented")

ErrNotSegmented .

Functions

This section is empty.

Types

type Accessor

type Accessor struct {
	Linker
	ID string
}

Accessor stores a Linker instance and it's access information It is a helper type for working with pooled linkers

type Edge

type Edge struct {
	Source *Node   `json:"source"`
	Target *Node   `json:"target"`
	Weight float32 `json:"weight"`
	// contains filtered or unexported fields
}

Edge between two nodes

func (*Edge) Hash

func (e *Edge) Hash() string

Hash returns a unique reproducible hash for each edge

func (*Edge) String

func (e *Edge) String() string

type InstanceCreator

type InstanceCreator func(ctx context.Context, storage Storage) (Linker, error)

InstanceCreator defines the function called to initialize new Linkers

type Linker

type Linker interface {
	Run(context.Context) error
	InsertDocument(ctx context.Context, doc *document.Document) error
	ListDocuments(ctx context.Context) []*document.Document
	ListLinks(ctx context.Context) []*Edge
}

Linker stores all documents and compares them for building a link matrix

type Metadata

type Metadata struct {
	ID        string  `json:"id"`
	Rater     string  `json:"rater"`
	Threshold float32 `json:"threshold"`
}

Metadata for storing linker settings

type Node

type Node struct {
	Doc string `json:"doc"`
	Seg int    `json:"seg"`
	// contains filtered or unexported fields
}

Node in the link graph

func (*Node) Hash

func (n *Node) Hash() string

Hash returns a unique reproducible hash for each node

func (*Node) String

func (n *Node) String() string

type Pool

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

Pool offers management for multiple linker instances It takes care of creating new ones and accessing existing ones

func New

func New(ctx context.Context, storageManager StorageManager, creator InstanceCreator) *Pool

New initializes the pool and prepares for storing instances

func (*Pool) Create

func (p *Pool) Create(ctx context.Context, raterURL string, threshold float32) (*Accessor, error)

Create new linker, store it in the pool and start running it's background process

func (*Pool) Get

func (p *Pool) Get(ctx context.Context, uuid string) *Accessor

Get linker accessor by its uuid

func (*Pool) List

func (p *Pool) List(ctx context.Context) []Linker

List all linker instances

func (*Pool) Load

func (p *Pool) Load(ctx context.Context) error

Load existing instances from the storage manager

type Segment

type Segment struct {
	*Node
	Text string `json:"text"`
}

Segment is the linker internal segment type containing a document link as well

type Storage

type Storage interface {
	SetMetadata(ctx context.Context, meta *Metadata)
	Metadata(ctx context.Context) (*Metadata, error)

	InsertDocument(ctx context.Context, doc *document.Document)
	InsertSegment(ctx context.Context, doc *Segment)
	InsertLink(ctx context.Context, doc *Edge)

	Documents(ctx context.Context) (map[string]*document.Document, error)
	Segments(ctx context.Context) (map[string]*Segment, error)
	Links(ctx context.Context) (map[string]*Edge, error)
}

Storage defines the minimal interface for a linker persistence layer

type StorageManager

type StorageManager interface {
	New(ctx context.Context, id string) (Storage, error)
	List(ctx context.Context) (map[string]Storage, error)
}

StorageManager defines the interface required to manage Storage instances

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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