2018-11-29 07:50:07 +09:00
|
|
|
package rdf
|
|
|
|
|
|
|
|
import (
|
2018-12-02 02:31:35 +09:00
|
|
|
"fmt"
|
2018-11-29 07:50:07 +09:00
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2018-11-29 09:22:56 +09:00
|
|
|
// ParsedVocabulary is the internal data structure produced after parsing the
|
2018-11-29 07:50:07 +09:00
|
|
|
// definition of an ActivityStream vocabulary. It is the intermediate
|
|
|
|
// understanding of the specification in the context of certain ontologies. It
|
|
|
|
// also contains additional scratch space for use by the parser.
|
|
|
|
//
|
2018-11-29 09:22:56 +09:00
|
|
|
// At the end of parsing, the ParsedVocabulary is not guaranteed to be
|
|
|
|
// semantically valid, just that the parser resolved all important ontological
|
|
|
|
// details.
|
|
|
|
type ParsedVocabulary struct {
|
|
|
|
Vocab Vocabulary
|
2018-11-29 07:50:07 +09:00
|
|
|
References map[string]Vocabulary
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vocabulary contains the type, property, and value definitions for a single
|
|
|
|
// ActivityStreams or extension vocabulary.
|
|
|
|
type Vocabulary struct {
|
|
|
|
Types map[string]VocabularyType
|
|
|
|
Properties map[string]VocabularyProperty
|
|
|
|
Values map[string]VocabularyValue
|
|
|
|
}
|
|
|
|
|
2018-12-02 02:31:35 +09:00
|
|
|
func (v *Vocabulary) SetType(name string, a *VocabularyType) error {
|
|
|
|
if v.Types == nil {
|
|
|
|
v.Types = make(map[string]VocabularyType, 1)
|
|
|
|
}
|
|
|
|
if _, has := v.Types[name]; has {
|
|
|
|
return fmt.Errorf("name already exists for vocabulary Types")
|
|
|
|
}
|
|
|
|
v.Types[name] = *a
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Vocabulary) SetProperty(name string, a *VocabularyProperty) error {
|
|
|
|
if v.Properties == nil {
|
|
|
|
v.Properties = make(map[string]VocabularyProperty, 1)
|
|
|
|
}
|
|
|
|
if _, has := v.Properties[name]; has {
|
|
|
|
return fmt.Errorf("name already exists for vocabulary Properties")
|
|
|
|
}
|
|
|
|
v.Properties[name] = *a
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Vocabulary) SetValue(name string, a *VocabularyValue) error {
|
|
|
|
if v.Values == nil {
|
|
|
|
v.Values = make(map[string]VocabularyValue, 1)
|
|
|
|
}
|
|
|
|
if _, has := v.Values[name]; has {
|
|
|
|
return fmt.Errorf("name already exists for vocabulary Values")
|
|
|
|
}
|
|
|
|
v.Values[name] = *a
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-11-29 07:50:07 +09:00
|
|
|
// VocabularyValue represents a value type that properties can take on.
|
|
|
|
type VocabularyValue struct {
|
|
|
|
Name string
|
|
|
|
URI *url.URL
|
|
|
|
DefinitionType string
|
|
|
|
Zero string
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:53:48 +09:00
|
|
|
func (v *VocabularyValue) SetName(s string) {
|
|
|
|
v.Name = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyValue) SetURI(s string) error {
|
|
|
|
var e error
|
|
|
|
v.URI, e = url.Parse(s)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ NameSetter = &VocabularyValue{}
|
|
|
|
_ URISetter = &VocabularyValue{}
|
|
|
|
)
|
|
|
|
|
2018-11-29 07:50:07 +09:00
|
|
|
// VocabularyType represents a single ActivityStream type in a vocabulary.
|
|
|
|
type VocabularyType struct {
|
|
|
|
Name string
|
|
|
|
URI *url.URL
|
|
|
|
Notes string
|
|
|
|
DisjointWith []VocabularyReference
|
2018-11-30 06:53:48 +09:00
|
|
|
Extends []VocabularyReference // TODO: Object improperly extends Link
|
2018-11-29 07:50:07 +09:00
|
|
|
Properties []VocabularyReference // TODO: Check for duplication
|
|
|
|
WithoutProperties []VocabularyReference // TODO: Missing for IntransitiveActivity
|
|
|
|
Examples []VocabularyExample
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:53:48 +09:00
|
|
|
func (v *VocabularyType) SetName(s string) {
|
|
|
|
v.Name = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyType) SetURI(s string) error {
|
|
|
|
var e error
|
|
|
|
v.URI, e = url.Parse(s)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyType) SetNotes(s string) {
|
|
|
|
v.Notes = s
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ NameSetter = &VocabularyType{}
|
|
|
|
_ URISetter = &VocabularyType{}
|
|
|
|
_ NotesSetter = &VocabularyType{}
|
|
|
|
)
|
|
|
|
|
2018-11-29 07:50:07 +09:00
|
|
|
// VocabularyProperty represents a single ActivityStream property type in a
|
|
|
|
// vocabulary.
|
|
|
|
type VocabularyProperty struct {
|
|
|
|
Name string
|
|
|
|
URI *url.URL
|
|
|
|
Notes string
|
|
|
|
Domain []VocabularyReference
|
|
|
|
Range []VocabularyReference
|
2018-11-29 09:22:56 +09:00
|
|
|
// SubpropertyOf is ignorable as long as data is set up correctly TODO: Is this still correct?
|
2018-11-29 07:50:07 +09:00
|
|
|
SubpropertyOf VocabularyReference // Must be a VocabularyProperty
|
|
|
|
Functional bool
|
|
|
|
NaturalLanguageMap bool
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:53:48 +09:00
|
|
|
func (v *VocabularyProperty) SetName(s string) {
|
|
|
|
v.Name = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyProperty) SetURI(s string) error {
|
|
|
|
var e error
|
|
|
|
v.URI, e = url.Parse(s)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyProperty) SetNotes(s string) {
|
|
|
|
v.Notes = s
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ NameSetter = &VocabularyProperty{}
|
|
|
|
_ URISetter = &VocabularyProperty{}
|
|
|
|
_ NotesSetter = &VocabularyProperty{}
|
|
|
|
)
|
|
|
|
|
2018-11-29 07:50:07 +09:00
|
|
|
// VocabularyExample documents an Example for an ActivityStream type or property
|
|
|
|
// in the vocabulary.
|
|
|
|
type VocabularyExample struct {
|
|
|
|
Name string
|
|
|
|
URI *url.URL
|
|
|
|
Example map[string]interface{}
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:53:48 +09:00
|
|
|
func (v *VocabularyExample) SetName(s string) {
|
|
|
|
v.Name = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyExample) SetURI(s string) error {
|
|
|
|
var e error
|
|
|
|
v.URI, e = url.Parse(s)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ NameSetter = &VocabularyExample{}
|
|
|
|
_ URISetter = &VocabularyExample{}
|
|
|
|
)
|
|
|
|
|
2018-11-29 07:50:07 +09:00
|
|
|
// VocabularyReference refers to another Vocabulary reference, either a
|
|
|
|
// VocabularyType, VocabularyValue, or a VocabularyProperty. It may refer to
|
|
|
|
// another Vocabulary's type or property entirely.
|
|
|
|
type VocabularyReference struct {
|
2018-11-29 09:22:56 +09:00
|
|
|
Name string
|
|
|
|
URI *url.URL
|
|
|
|
Vocab string // If present, must match key in ParsedVocabulary.References
|
2018-11-29 07:50:07 +09:00
|
|
|
}
|
2018-11-30 06:53:48 +09:00
|
|
|
|
|
|
|
func (v *VocabularyReference) SetName(s string) {
|
|
|
|
v.Name = s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VocabularyReference) SetURI(s string) error {
|
|
|
|
var e error
|
|
|
|
v.URI, e = url.Parse(s)
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ NameSetter = &VocabularyReference{}
|
|
|
|
_ URISetter = &VocabularyReference{}
|
|
|
|
)
|