egcl

package module
v0.0.0-...-881411a Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Entity Graph Constraint Language

Data structures, validation engine and utilities for working with the Entity Graph Constraint Language

Library that allows to parse and validate Entity Graph Constraint Language (EGCL) structures into a data model.

With an EGCL model instance it can be used to:

  • generate browseable documentation
  • validate an Entity instance
  • generate SHACL representation
  • generate EGDM representation

In addition, a parser for the YAML shorthand authoring syntax is provided. This can be used to import and create EGCL model instances.

Documentation

Index

Constants

View Source
const (
	EGCLsortable              = EGCLUriExpansion + "sortable"
	EGCLqueryable             = EGCLUriExpansion + "queryable"
	EGCLisunique              = EGCLUriExpansion + "isunique"
	EGCLminCardinality        = EGCLUriExpansion + "minCard"
	EGCLmaxCardinality        = EGCLUriExpansion + "maxCard"
	EGCLrule                  = EGCLUriExpansion + "rule"
	EGCLinverseMinCardinality = EGCLUriExpansion + "inverseMinCard"
	EGCLinverseMaxCardinality = EGCLUriExpansion + "inverseMaxCard"
)
View Source
const EGCLAny = EGCLUriExpansion + "Any"
View Source
const EGCLApplicationConstraint = EGCLUriExpansion + "ApplicationConstraint"
View Source
const EGCLDescription = EGCLUriExpansion + "description"
View Source
const EGCLEntityClass = EGCLUriExpansion + "EntityClass"
View Source
const EGCLInverseReferenceClass = EGCLUriExpansion + "inverseReferenceClass"
View Source
const EGCLIsAbstractConstraint = EGCLUriExpansion + "IsAbstractConstraint"
View Source
const EGCLLabel = EGCLUriExpansion + "label"
View Source
const EGCLPropertyConstraint = EGCLUriExpansion + "PropertyConstraint"
View Source
const EGCLReferenceConstraint = EGCLUriExpansion + "ReferenceConstraint"
View Source
const EGCLUriExpansion = "http://data.mimiro.io/egcl/"
View Source
const EGCLallowedReferencedClass = EGCLUriExpansion + "referencedEntityClass"
View Source
const EGCLdatatype = EGCLUriExpansion + "datatype"
View Source
const EGCLentityClass = EGCLUriExpansion + "entityClass"
View Source
const EGCLpropertyClass = EGCLUriExpansion + "propertyClass"
View Source
const EGCLreferenceClass = EGCLUriExpansion + "referenceClass"
View Source
const EGCLsubclassOf = EGCLUriExpansion + "subClassOf"
View Source
const MaxInt = math.MaxInt32

for our purposes, we can use math.MaxInt32 as infinity

View Source
const RDFUriExpansion = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
View Source
const RDfTypeURI = RDFUriExpansion + "type"

Variables

View Source
var (
	ErrMissingParent = errors.New("referenced super class is not defined in the schema")
)

Functions

This section is empty.

Types

type ApplicationConstraint

type ApplicationConstraint struct {
	Constraint
}

func (*ApplicationConstraint) GetRule

func (c *ApplicationConstraint) GetRule() string

func (*ApplicationConstraint) Match

func (c *ApplicationConstraint) Match(namespaceManager egdm.NamespaceManager, rule string) bool

type Constraint

type Constraint struct {
	Entity                   *egdm.Entity
	ConstraintTypeIdentifier string
}

type ConstraintViolation

type ConstraintViolation struct {
	Constraint    any
	Entity        *egdm.Entity
	ViolationType ViolationType
	Message       string
}

func NewConstraintViolation

func NewConstraintViolation(constraint any, entity *egdm.Entity, violationType ViolationType, message string) *ConstraintViolation

type DataProvider

type DataProvider interface {
	Hop(sourceEntityId string, reference string, datasets []string, inverse bool, limit int) (datahub.EntityIterator, error)
	GetEntity(entityId string, datasets []string) (*egdm.Entity, error)
	GetDatasetEntities(dataset string) (datahub.EntityIterator, error)
}

type EntityClass

type EntityClass struct {
	Entity *egdm.Entity
}

func NewEntityClass

func NewEntityClass(entity *egdm.Entity) *EntityClass

func (*EntityClass) GetDescription

func (entityClass *EntityClass) GetDescription() string

func (*EntityClass) GetLabel

func (entityClass *EntityClass) GetLabel() string

type InverseReferenceConstraint

type InverseReferenceConstraint struct {
	Constraint
}

type IsAbstractConstraint

type IsAbstractConstraint struct {
	Constraint
}

func (*IsAbstractConstraint) GetEntityClass

func (c *IsAbstractConstraint) GetEntityClass() string

type NamespaceResolver

type NamespaceResolver interface {
	ResolveNamespace(prefix string) (string, error)
}

type PropertyConstraint

type PropertyConstraint struct {
	Constraint
}

func (*PropertyConstraint) GetConstrainedEntityClass

func (c *PropertyConstraint) GetConstrainedEntityClass() (string, error)

func (*PropertyConstraint) GetConstrainedPropertyClass

func (c *PropertyConstraint) GetConstrainedPropertyClass() (string, error)

func (*PropertyConstraint) GetDataType

func (c *PropertyConstraint) GetDataType() string

func (*PropertyConstraint) GetIsQueryable

func (c *PropertyConstraint) GetIsQueryable() bool

func (*PropertyConstraint) GetIsUnique

func (c *PropertyConstraint) GetIsUnique() bool

func (*PropertyConstraint) GetMaxAllowedOccurrences

func (c *PropertyConstraint) GetMaxAllowedOccurrences() int

func (*PropertyConstraint) GetMinAllowedOccurrences

func (c *PropertyConstraint) GetMinAllowedOccurrences() int

func (*PropertyConstraint) GetSortable

func (c *PropertyConstraint) GetSortable() string

type PropertyValueConstraint

type PropertyValueConstraint struct {
}

type QueryConstraint

type QueryConstraint struct {
	Constraint
}

type ReferenceConstraint

type ReferenceConstraint struct {
	Constraint
}

func (*ReferenceConstraint) GetAllowedReferencedClass

func (aReferenceConstraint *ReferenceConstraint) GetAllowedReferencedClass() (string, error)

func (*ReferenceConstraint) GetConstrainedEntityClass

func (aReferenceConstraint *ReferenceConstraint) GetConstrainedEntityClass() (string, error)

func (*ReferenceConstraint) GetConstrainedPropertyClass

func (aReferenceConstraint *ReferenceConstraint) GetConstrainedPropertyClass() (string, error)

func (*ReferenceConstraint) GetInverseConstrainedPropertyClass

func (aReferenceConstraint *ReferenceConstraint) GetInverseConstrainedPropertyClass() (string, error)

func (*ReferenceConstraint) GetMaxAllowedOccurrences

func (aReferenceConstraint *ReferenceConstraint) GetMaxAllowedOccurrences() int

func (*ReferenceConstraint) GetMinAllowedOccurrences

func (aReferenceConstraint *ReferenceConstraint) GetMinAllowedOccurrences() int

type RemoteDataProvider

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

func NewRemoteDataProvider

func NewRemoteDataProvider(client *datahub.Client) (*RemoteDataProvider, error)

func (*RemoteDataProvider) GetDatasetEntities

func (r *RemoteDataProvider) GetDatasetEntities(name string) (datahub.EntityIterator, error)

func (*RemoteDataProvider) GetEntity

func (r *RemoteDataProvider) GetEntity(id string, datasets []string) (*egdm.Entity, error)

func (*RemoteDataProvider) Hop

func (r *RemoteDataProvider) Hop(sourceEntityId string, reference string, datasets []string, inverse bool, limit int) (datahub.EntityIterator, error)

type Schema

type Schema struct {
	EntityCollection *egdm.EntityCollection
	EntityClasses    []*EntityClass
	Constraints      []any
	BaseURI          string
	Description      string
}

func NewSchema

func NewSchema(entities *egdm.EntityCollection) *Schema

func NewSchemaFromYaml

func NewSchemaFromYaml(yaml string) (*Schema, error)

func (*Schema) GetConstraintsForEntityClass

func (aSchema *Schema) GetConstraintsForEntityClass(entityClassIdentifier string, inherited bool) []any

func (*Schema) GetEntityClassById

func (aSchema *Schema) GetEntityClassById(entityClassIdentifier string) *EntityClass

func (*Schema) GetEntityClassClassHierarchy

func (aSchema *Schema) GetEntityClassClassHierarchy(entityClassIdentifier string) ([]string, error)

func (*Schema) GetOutgoingInverseConstraintsForEntityClass

func (aSchema *Schema) GetOutgoingInverseConstraintsForEntityClass(entityClassIdentifier string, inherited bool) []any

Get any reference constraints that are inverse and thus outgoing for the specific entityClassIdentifer

func (*Schema) IsAbstract

func (aSchema *Schema) IsAbstract(entityClass *EntityClass) bool

func (*Schema) IsOfType

func (aSchema *Schema) IsOfType(entity *egdm.Entity, typeURI string) bool

type SchemaValidator

type SchemaValidator interface {
	ValidateEntity(schema *Schema, entity *egdm.Entity) (ok bool, exceptions []*ConstraintViolation, err error)
	ValidateDataset(schema *Schema, datasetName string) (ok bool, exceptions []*ConstraintViolation, err error)
	ValidateSchema(schema *Schema) (ok bool, exceptions []*ConstraintViolation, err error)
	ValidateEntityCollection(schema *Schema, entityCollection *egdm.EntityCollection) (ok bool, exceptions []*ConstraintViolation, err error)
}

type Validator

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

func NewValidator

func NewValidator() *Validator

func (*Validator) CheckConstraint

func (v *Validator) CheckConstraint(schema *Schema, constraint any, entity *egdm.Entity) (bool, *ConstraintViolation, error)

CheckConstraint checks if the given constraint is violated for the given entity. Returns false if the constraint is ok and true and a constraint violation struct if not. Error is returned if something went wrong while checking the constraint.

func (*Validator) CheckEntityIsAbstractConstraint

func (v *Validator) CheckEntityIsAbstractConstraint(schema *Schema, entity *egdm.Entity, constraint *IsAbstractConstraint) (bool, *ConstraintViolation, error)

func (*Validator) CheckExistenceAndTypeOfReferencedEntity

func (v *Validator) CheckExistenceAndTypeOfReferencedEntity(entityId string, expectedType string) (valid bool, violation *ConstraintViolation, err error)

func (*Validator) CheckGlobalIsAbstractConstraint

func (v *Validator) CheckGlobalIsAbstractConstraint(constraint *IsAbstractConstraint) (bool, *ConstraintViolation, error)

func (*Validator) CheckInverseReferenceConstraint

func (v *Validator) CheckInverseReferenceConstraint(entity *egdm.Entity, constraint *InverseReferenceConstraint) (bool, *ConstraintViolation, error)

func (*Validator) CheckPropertyConstraint

func (v *Validator) CheckPropertyConstraint(entity *egdm.Entity, constraint *PropertyConstraint) (valid bool, violation *ConstraintViolation, err error)

func (*Validator) CheckReferenceConstraint

func (v *Validator) CheckReferenceConstraint(entity *egdm.Entity, constraint *ReferenceConstraint) (bool, *ConstraintViolation, error)

func (*Validator) ValidateDataset

func (v *Validator) ValidateDataset(schema *Schema, datasetName string) (ok bool, exceptions []*ConstraintViolation, err error)

ValidateDataset validates the given schema against the data in the named dataset

func (*Validator) ValidateEntity

func (v *Validator) ValidateEntity(schema *Schema, entity *egdm.Entity) (ok bool, exceptions []*ConstraintViolation, err error)

func (*Validator) ValidateEntityCollection

func (v *Validator) ValidateEntityCollection(schema *Schema, entityCollection *egdm.EntityCollection) (ok bool, exceptions []*ConstraintViolation, err error)

ValidateEntityCollection validates the given entity collection against the given schema

func (*Validator) ValidateSchema

func (v *Validator) ValidateSchema(schema *Schema) (ok bool, exceptions []*ConstraintViolation, err error)

ValidateSchema validates the given schema against data accessible to this validator

func (*Validator) WithDataProvider

func (v *Validator) WithDataProvider(provider DataProvider) *Validator

func (*Validator) WithSettings

func (v *Validator) WithSettings(settings *ValidatorSettings) *Validator

type ValidatorSettings

type ValidatorSettings struct {
	// StrictValidation will cause the validator to fail if an entity has properties or references that are not defined in the schema
	StrictValidation bool
	// ValidateRelated enables validation of referenced entities, specifically that they exist and are of the correct type
	ValidateRelated bool
	// datasetsContext defines the set of datasets that are in play when checking referenced entities
	DatasetsContext []string
}

type ViolationType

type ViolationType int
const (
	MinPropertyOccurrenceNotMet ViolationType = iota
	MaxPropertyOccurrenceExceeded
	MinReferenceOccurrenceNotMet
	MaxReferenceOccurrenceExceeded
	ReferenceNotFound
	ReferenceTypeMismatch
	AbstractEntityClassViolation
)

Directories

Path Synopsis
cmd
schema command

Jump to

Keyboard shortcuts

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