model

package
v0.0.0-...-8098de6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	// ID of the candidate entity.
	ID EntityID `json:"id"`

	// Name of the candidate entity.
	Name string `json:"name"`

	// Types of the candidate entity.
	Types []*Type `json:"type"`

	// Score indicates how good the match is. Higher is better.
	Score float64 `json:"score"`

	// Match indicates if this is a "good" match or not.
	Match bool `json:"match"`
}

Candidate describes a Reconciliation Query candidate entity.

type DatabaseSource

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

DatabaseSource represents a data source in a database.

func (*DatabaseSource) GetEntity

func (s *DatabaseSource) GetEntity(entityID EntityID) (*Entity, bool)

GetEntity returns the Entity matching the provided ID.

func (*DatabaseSource) IdentifierNS

func (s *DatabaseSource) IdentifierNS() string

IdentifierNS is a universal namespace for Entity identifiers.

func (*DatabaseSource) Name

func (s *DatabaseSource) Name() string

Name of the data Source.

func (*DatabaseSource) Properties

func (s *DatabaseSource) Properties(typeID string) []*Property

Properties returns all supported Properties for Entities with the Type ID given.

func (*DatabaseSource) Query

Query entitities for a match.

func (*DatabaseSource) QueryPrefix

func (s *DatabaseSource) QueryPrefix(text string, limit int) []*Entity

QueryPrefix searches entitities for a prefix match.

func (*DatabaseSource) SchemaNS

func (s *DatabaseSource) SchemaNS() string

SchemaNS is a universal namespace for concept Type identifiers.

func (*DatabaseSource) Types

func (s *DatabaseSource) Types() []*Type

Types returns all supported Entity types.

func (*DatabaseSource) ViewURL

func (s *DatabaseSource) ViewURL() string

ViewURL returns the template for a View URL.

type Entity

type Entity struct {
	// ID is a unique identifier for the entity.
	ID EntityID `json:"id"`

	// Name is a human-readable description of the entity.
	Name string `json:"name"`

	// Description is a human-readable description of the entity.
	Description string `json:"description,omitempty"`

	// Properties is all the other properties of the Entity.
	Properties map[string]interface{} `json:"-"`

	// Types is a (possibly empty) list of entity types for this entity.
	Types []*Type `json:"type,omitempty"`
}

Entity is a record in the data source.

type EntityID

type EntityID string

EntityID is a compound Entity ID that is globally unique due to a prefixed type.

Formed by type_id + ":" + entity_id

func (EntityID) ID

func (x EntityID) ID() string

ID returns the type-specific Entity ID embedded in the EntityID.

func (EntityID) Type

func (x EntityID) Type() string

Type returns the Type ID embedded in the EntityID.

type MemorySource

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

MemorySource represents a data source entirely in memory.

func (*MemorySource) GetEntity

func (s *MemorySource) GetEntity(entityID EntityID) (*Entity, bool)

GetEntity returns the Entity matching the provided ID.

func (*MemorySource) IdentifierNS

func (s *MemorySource) IdentifierNS() string

IdentifierNS is a universal namespace for Entity identifiers.

func (*MemorySource) Name

func (s *MemorySource) Name() string

Name of the data Source.

func (*MemorySource) Properties

func (s *MemorySource) Properties(typeID string) []*Property

Properties returns all supported Properties for Entities with the Type ID given.

func (*MemorySource) Query

func (s *MemorySource) Query(q *QueryRequest) (*QueryResponse, error)

Query entitities for a match.

func (*MemorySource) QueryPrefix

func (s *MemorySource) QueryPrefix(text string, limit int) []*Entity

QueryPrefix searches entitities for a prefix match.

func (*MemorySource) SchemaNS

func (s *MemorySource) SchemaNS() string

SchemaNS is a universal namespace for concept Type identifiers.

func (*MemorySource) Types

func (s *MemorySource) Types() []*Type

Types returns all supported Entity types.

func (*MemorySource) ViewURL

func (s *MemorySource) ViewURL() string

ViewURL returns the template for a View URL.

type Property

type Property struct {
	// ID is a unique identifier for the property.
	ID string `json:"id"`

	// Name is a human-readable name of the property.
	Name string `json:"name"`

	// Description is a human-readable description of the property.
	Description string `json:"description,omitempty"`

	// ValueType expected for Property values.
	ValueType string `json:"-"`
}

Property represents a type of attribute that entities can have within the data source.

type PropertyValue

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

PropertyValue is a specific value associated to an entity property. In this implementation, the value MUST be one of the following Go types:

string, bool, int64, float64, or Entity

func (PropertyValue) Bool

func (p PropertyValue) Bool() bool

Bool attempts to coerce the value into a bool. For bool, int64, and float64 returns true if non-zero. String values of "YES", "TRUE", "T", "ON", or "1" return true. All other values return false.

func (PropertyValue) Entity

func (p PropertyValue) Entity(e *Entity) bool

Entity copies the entity data into the provided structure and returns true, If the value is not an entity simply returns false.

func (PropertyValue) Float64

func (p PropertyValue) Float64() float64

Float64 attempts to coerce the value into a 64-bit floating point value. bool values are converted to 0 or 1 int64 values are casted to float64. String and Entity ID values attempt string conversion to

float64 using base 10 representation.

All other values return 0.

func (PropertyValue) Int64

func (p PropertyValue) Int64() int64

Int64 attempts to coerce the value into a 64-bit integer. bool values are converted to 0 or 1 float64 values are truncated to integers. String and Entity ID values attempt string conversion to

int64 using base 10 representation.

All other values return 0.

func (PropertyValue) String

func (p PropertyValue) String() string

String coerces the value into a string no matter what. For Entity values, returns the ID.

type QueryProperty

type QueryProperty struct {
	// ID is the property ID.
	ID string `json:"pid"`

	// Value is the text to search for in the Property.
	Value interface{} `json:"v"`
}

QueryProperty depicts a query against a property value.

type QueryRequest

type QueryRequest struct {
	// ID to refer to the query.
	ID string `json:"id"`

	// Text is the search text to query for.
	Text string `json:"query"`

	// Type is the Type ID to query over (if present).
	Type string `json:"type"`

	// Limit the results to the first N results.
	Limit int `json:"limit"`

	// Properties lists the various property values to query over.
	Properties []*QueryProperty `json:"properties"`

	// Strictness should be set to "any", "all", or "should"
	Strictness string `json:"type_strict,omitempty"`
}

QueryRequest describes a Reconciliation Query request.

type QueryResponse

type QueryResponse struct {
	// ID of the QueryRequest this is responding to.
	ID string `json:"id"`

	// Results lists the Candidates matching the query.
	Results []*Candidate `json:"result"`
}

QueryResponse describes a Reconciliation Query reponse.

type Source

type Source interface {
	// Name of the data Source.
	Name() string

	// IdentifierNS is a universal namespace for Entity identifiers.
	IdentifierNS() string

	// SchemaNS is a universal namespace for concept Type identifiers.
	SchemaNS() string

	// ViewURL returns the template for a View URL.
	ViewURL() string

	// Types returns all supported Entity types.
	Types() []*Type

	// Properties returns all supported Properties for Entities with the Type ID given.
	Properties(typeID string) []*Property

	// GetEntity returns the Entity matching the provided ID.
	GetEntity(entityID EntityID) (*Entity, bool)

	// Query entitities for a match.
	Query(q *QueryRequest) (*QueryResponse, error)

	// QueryPrefix searches entitities for a prefix match.
	QueryPrefix(text string, limit int) []*Entity
}

Source represents a data source.

func Load

func Load(filename string) (Source, error)

Load a data source from a flat file. Format is tab-separated values in 4 columns with a 1-line header.

Header:

0: Identifier Namespace URI
1: Name of the data source
2: Schema Namespace URI
3: JSON list of types [{id: "", name: "", description: "", url: "%s"}, ...]

Properties:

0: Property ID
1: Name of the Property
2: comma-separated list of "property" + Entity Type IDs it applies to
3: JSON object of property settings {description: "", ...}

Entities:

0: Entity ID
1: Entity Name
2: comma-separated list of Entity Type IDs
3: JSON object of properties {description: "", ...}

type Type

type Type struct {
	// ID is a unique identifier for the type.
	ID string `json:"id"`

	// Name is a human-readable description of the type.
	Name string `json:"name"`

	// Description is a human-readable description of the type.
	Description string `json:"description,omitempty"`

	// ViewURL describes how to turn an Entity ID into a permalink.
	ViewURL string `json:"url"`
}

Type represents a category of entities.

Jump to

Keyboard shortcuts

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