Documentation
¶
Overview ¶
Package mdl provides an api for building the database used by the tapestry runtime. The Reader*() functions provide csv style output for use with testing. For the definitions of the tables see tapestry/tables/model.sql
Index ¶
- Constants
- Variables
- func AddNamedNoun(pen NounMaker, longName, kind string) (ret string, err error)
- func AddNounNames(pen NounMaker, noun string, names []string) (err error)
- func MakeNames(source string) (out []string)
- func MakePath(path ...string) string
- func ReadAssignments(db *sql.DB) ([]string, error)
- func ReadDomain(db *sql.DB, n string) (ret []string, err error)
- func ReadDomains(db *sql.DB) ([]string, error)
- func ReadFields(db *sql.DB) ([]string, error)
- func ReadGrammar(db *sql.DB) ([]string, error)
- func ReadKinds(db *sql.DB) (ret []string, err error)
- func ReadLocals(db *sql.DB) ([]string, error)
- func ReadNames(db *sql.DB) ([]string, error)
- func ReadNouns(db *sql.DB) ([]string, error)
- func ReadPairs(db *sql.DB) ([]string, error)
- func ReadPatterns(db *sql.DB) ([]string, error)
- func ReadPlurals(db *sql.DB) ([]string, error)
- func ReadRelations(db *sql.DB) ([]string, error)
- func ReadRules(db *sql.DB) ([]string, error)
- func ReadValues(db *sql.DB) ([]string, error)
- type DomainValueError
- type FieldInfo
- type Log
- type MatchedField
- type MatchedKind
- type MatchedNoun
- type MatchedTrait
- type Modeler
- type NounMaker
- type Pattern
- type PatternBuilder
- type Pen
- func (pen *Pen) AddAspectTraits(aspect string, traits []string) (err error)
- func (pen *Pen) AddCheck(name string, value literal.LiteralValue, prog []rt.Execute) (err error)
- func (pen *Pen) AddDefaultValue(kind, field string, value rt.Assignment) (err error)
- func (pen *Pen) AddDependency(requires string) (err error)
- func (pen *Pen) AddFact(key string, partsAndValue ...string) (okay bool, err error)
- func (pen *Pen) AddGrammar(name string, prog *grammar.Directive) (err error)
- func (pen *Pen) AddKind(name, parent string) (err error)
- func (pen *Pen) AddKindFields(kind string, fields []FieldInfo) error
- func (pen *Pen) AddKindTrait(kind, trait string) (err error)
- func (pen *Pen) AddNounKind(noun, kind string) (err error)
- func (pen *Pen) AddNounName(noun, name string, rank int) (err error)
- func (pen *Pen) AddNounPair(rel, oneNoun, otherNoun string) (err error)
- func (pen *Pen) AddNounPath(noun string, path []string, value literal.LiteralValue) (err error)
- func (pen *Pen) AddNounValue(noun, field string, value rt.Assignment) (err error)
- func (pen *Pen) AddPattern(pat Pattern) (err error)
- func (pen *Pen) AddPlural(many, one string) (err error)
- func (pen *Pen) AddRelation(name, oneKind, otherKind string, amany bool, bmany bool) (err error)
- func (pen *Pen) AddTestField(kind, field string, aff affine.Affinity, cls string) (err error)
- func (pen *Pen) AddTestParameter(kind, field string, aff affine.Affinity, cls string) (err error)
- func (pen *Pen) AddTestResult(kind, field string, aff affine.Affinity, cls string) (err error)
- func (pen *Pen) AddTestRule(pattern string, rank int, prog string) (err error)
- func (pen *Pen) AddTestValue(noun string, final bool, path, out string) (err error)
- func (pen *Pen) ExtendPattern(pat Pattern) (err error)
- func (pen *Pen) GetClosestNoun(name string) (ret MatchedNoun, err error)
- func (pen *Pen) GetNounValue(noun, field string) (ret []byte, err error)
- func (pen *Pen) GetPartialField(kind, field string) (ret MatchedField, err error)
- func (pen *Pen) GetPartialKind(str string) (ret MatchedKind, err error)
- func (pen *Pen) GetPartialNoun(name, kind string) (ret MatchedNoun, err error)
- func (pen *Pen) GetPartialTrait(str string) (ret MatchedTrait, err error)
- func (pen *Pen) GetRelativeNouns(noun, relation string, primary bool) (ret []string, err error)
- type ProvisionalAssignment
- type ProvisionalLiteral
- type Rule
- type Warnings
Constants ¶
const Conflict = errutil.Error("Conflict")
when the definition would contradict existing information: the returned error wraps this tag. errors.Is can be used to detect it.
const Duplicate = errutil.NoPanicError("Duplicate")
when the definition would repeat existing information: the returned error wraps this tag. errors.Is can be used to detect it.
const Missing = errutil.NoPanicError("Missing")
when the definition can't find some required information: the returned error wraps this tag. errors.Is can be used to detect it.
Variables ¶
var LogWarning = func(e error) { log.Println("Warning:", e) }
Functions ¶
func AddNamedNoun ¶
given an author specified name generate a new noun and its names
func MakeNames ¶
generate names for a noun; the standard rules use these for printing when no specific printed names exist; and for finding nouns that were specified by authors in a story.
func ReadDomain ¶
an array of dependencies
func ReadFields ¶
domain, kind, field name, affinity, subtype sorted by kind and within each kind, the field name
func ReadKinds ¶
domain, kind, expanded materialized path ordered by domain, length of path, and name ( that erases their natural, dependency order --
but independent siblings dont otherwise have a consistent order for testing )
func ReadLocals ¶
domain, kind, name, serialized initialization
func ReadPairs ¶
domain, relation, noun, other noun original order was domain, and alpha relation name
func ReadPatterns ¶
domain, pattern, labels, result field
func ReadRelations ¶
domain, relation, one kind, other kind, cardinality ordered by name of the relation for test consistency.
Types ¶
type DomainValueError ¶
type DomainValueError struct {
Noun, Field string
Value rt.Assignment
}
func (DomainValueError) Error ¶
func (e DomainValueError) Error() string
type MatchedField ¶
type MatchedField struct {
Name string // name of the trait in the db
}
type MatchedKind ¶
type MatchedKind struct { Name string // the name of the kind in the db Base kindsOf.Kinds // which of the built-in kinds is the returned kind most like? Match string // the word(s) (singular or plural) used to match }
func (MatchedKind) WordCount ¶
func (m MatchedKind) WordCount() int
type MatchedNoun ¶
type MatchedNoun struct { Name string // the id of the noun in the db Kind string // the noun's kind Match string // the words used to match }
func (MatchedNoun) WordCount ¶
func (m MatchedNoun) WordCount() int
type MatchedTrait ¶
type MatchedTrait struct {
Name string // name of the trait in the db
}
func (MatchedTrait) WordCount ¶
func (m MatchedTrait) WordCount() int
the returned name is the name of the trait from the db it was used to match the front of the passed string so the words in the trait are the words in the string.
type Modeler ¶
type Modeler struct {
// contains filtered or unexported fields
}
Modeler wraps writing to the model table so the implementation can handle verifying dependent names when needed.
func NewModelerWithWarnings ¶
func (*Modeler) PrecachePaths ¶
func (m *Modeler) PrecachePaths()
meant for tests which inject their own data outside of weave
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
public snapshot of the desired pattern
type PatternBuilder ¶
type PatternBuilder struct {
Pattern
}
func NewPatternBuilder ¶
func NewPatternBuilder(name string) *PatternBuilder
func NewPatternSubtype ¶
func NewPatternSubtype(name string, parent string) *PatternBuilder
func (*PatternBuilder) AddLocals ¶
func (b *PatternBuilder) AddLocals(fs []FieldInfo)
defers execution; so no return value.
func (*PatternBuilder) AddParams ¶
func (b *PatternBuilder) AddParams(fs []FieldInfo)
defers execution; so no return value.
func (*PatternBuilder) AddResult ¶
func (b *PatternBuilder) AddResult(f FieldInfo)
defers execution; so no return value.
func (*PatternBuilder) AppendRule ¶
func (b *PatternBuilder) AppendRule(rank int, rule rt.Rule)
defers execution; so no return value. expects target class name to be normalized.
type Pen ¶
type Pen struct {
// contains filtered or unexported fields
}
func (*Pen) AddAspectTraits ¶
func (*Pen) AddDefaultValue ¶
func (pen *Pen) AddDefaultValue(kind, field string, value rt.Assignment) (err error)
the top level fields of kinds can hold runtime evaluated assignments.
func (*Pen) AddDependency ¶
pairs of domain name and (domain) dependencies fix: are we forcing/checking parent domains to exist before writing? that might be cool .... but maybe this is the wrong level?
func (*Pen) AddFact ¶
arbitrary key-value storage returns true if its a new fact, false otherwise or on error.
func (*Pen) AddGrammar ¶
player input parsing
func (*Pen) AddKind ¶
plural name of kind and materialized hierarchy of ancestors separated by commas this (somewhat) duplicates the algorithm used by Noun()
func (*Pen) AddKindTrait ¶
func (*Pen) AddNounKind ¶
add a noun with the passed identifier and kind ( both normalized ) the kind must exist. note: returns mdl.Duplicate if the noun is already know. see also: the utility function AddNamedNoun()
func (*Pen) AddNounName ¶
currently negative ranks are runtime aliases, and positive values are weave time.
func (*Pen) AddNounPair ¶
currently assumes exact noun names
func (*Pen) AddNounPath ¶
store a literal value somewhere within a record held by a noun. note: assumes noun is an exact name fix: merge with AddNounValue; use the bits inside marshalAssignment ... and strip assignment down to a literal value
func (*Pen) AddNounValue ¶
func (pen *Pen) AddNounValue(noun, field string, value rt.Assignment) (err error)
the top level fields of nouns can hold runtime evaluated assignments. wrap with "ProvisionalAssignment" to assign implied values that can be overridden by explicit statements. note: assumes noun is an exact name
func (*Pen) AddPattern ¶
func (*Pen) AddPlural ¶
a plural word (many) can have at most one singular definition per domain ie. people and persons are valid plurals of person, but people as a singular can only be defined as person ( not also human ) error
func (*Pen) AddRelation ¶
relation and constraint between two kinds
func (*Pen) AddTestField ¶
for testing: a generic field of the kind
func (*Pen) AddTestParameter ¶
func (*Pen) AddTestResult ¶
func (*Pen) AddTestRule ¶
public for tests:
func (*Pen) AddTestValue ¶
unmarshaled version of AddValue for testing.
func (*Pen) ExtendPattern ¶
func (*Pen) GetClosestNoun ¶
func (pen *Pen) GetClosestNoun(name string) (ret MatchedNoun, err error)
prefer runtime meta.ObjectId
func (*Pen) GetNounValue ¶
return a specific field of a specific noun. this is a more limited form of the runtime version; it doesn't attempt to unpack records.
func (*Pen) GetPartialField ¶
func (pen *Pen) GetPartialField(kind, field string) (ret MatchedField, err error)
match the passed words with the known fields of all in-scope kinds. return the full name of the field that matched. an unmatched noun returns the empty string and no error.
func (*Pen) GetPartialKind ¶
func (pen *Pen) GetPartialKind(str string) (ret MatchedKind, err error)
searches for the kind which uses the most number of words from the front of the passed string. for example: the words "container of the apocalypse" would match the kind "container." assumes the words are lowercased and whitespace is normalized.
func (*Pen) GetPartialNoun ¶
func (pen *Pen) GetPartialNoun(name, kind string) (ret MatchedNoun, err error)
if specified, kind must match exactly an unmatched noun returns the empty string and no error.
func (*Pen) GetPartialTrait ¶
func (pen *Pen) GetPartialTrait(str string) (ret MatchedTrait, err error)
an unmatched trait returns the empty string and no error tbd: technically there's some possibility that there might be three traits: "wood", "veneer", and "wood veneer" -- subset names with the first two applying to one kind, and the third applying to a different kind; all in scope. this would always match the second -- even if its not applicable. ( i guess that's where commas can be used by the user to separate things )
type ProvisionalAssignment ¶
type ProvisionalAssignment struct {
rt.Assignment
}
type ProvisionalLiteral ¶
type ProvisionalLiteral struct {
literal.LiteralValue
}
type Warnings ¶
type Warnings []error