Prepare for @type to contextually resolve.
- Remove unused 'as' ontology - Outline new GetByName for ontologies - Fix bugs - Prepare the type to use the RDFRegistry
このコミットが含まれているのは:
コミット
864616542c
|
@ -5,7 +5,6 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/as"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/owl"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/rdfs"
|
||||
"github.com/cjslep/activity/tools/exp/rdf/schema"
|
||||
|
@ -25,7 +24,6 @@ func mustAddOntology(o rdf.Ontology) {
|
|||
}
|
||||
|
||||
func init() {
|
||||
mustAddOntology(&as.ActivityStreamsOntology{})
|
||||
mustAddOntology(&xsd.XMLOntology{})
|
||||
mustAddOntology(&owl.OWLOntology{})
|
||||
mustAddOntology(&rdf.RDFOntology{})
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package as
|
||||
|
||||
import (
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
)
|
||||
|
||||
type ActivityStreamsOntology struct{}
|
||||
|
||||
func (o *ActivityStreamsOntology) SpecURI() string {
|
||||
return "https://www.w3.org/ns/activitystreams"
|
||||
}
|
||||
|
||||
func (o *ActivityStreamsOntology) Load() ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *ActivityStreamsOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *ActivityStreamsOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *ActivityStreamsOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
|
@ -15,24 +15,22 @@ const (
|
|||
|
||||
// jsonLDNodes contains the well-known set of nodes as defined by the JSON-LD
|
||||
// specification.
|
||||
var jsonLDNodes []RDFNode
|
||||
|
||||
func init() {
|
||||
func jsonLDNodes(r *RDFRegistry) []RDFNode {
|
||||
// Order matters -- we want to be able to distinguish the types of
|
||||
// things first, for example, to be able to have the parsing context
|
||||
// applied correctly.
|
||||
jsonLDNodes = []RDFNode{
|
||||
return []RDFNode{
|
||||
&AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: typeSpec,
|
||||
Delegate: &typeLD{},
|
||||
Delegate: &typeLD{r: r},
|
||||
},
|
||||
&AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: typeActivityStreamsSpec,
|
||||
Delegate: &typeLD{},
|
||||
Delegate: &typeLD{r: r},
|
||||
},
|
||||
&AliasedDelegate{
|
||||
Spec: "",
|
||||
|
@ -87,21 +85,29 @@ func (i *idLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool,
|
|||
|
||||
var _ RDFNode = &typeLD{}
|
||||
|
||||
type typeLD struct{}
|
||||
type typeLD struct {
|
||||
r *RDFRegistry
|
||||
}
|
||||
|
||||
func (t *typeLD) Enter(key string, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (t *typeLD) Exit(key string, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (t *typeLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
fmt.Printf("@type key=%s, value=%v\n", key, value)
|
||||
vs, ok := value.(string)
|
||||
if !ok {
|
||||
return true, fmt.Errorf("@type is not string")
|
||||
}
|
||||
n, e := t.r.getNode(vs)
|
||||
if e != nil {
|
||||
return true, e
|
||||
}
|
||||
return n.Apply(vs, nil, ctx)
|
||||
}
|
||||
|
||||
var _ RDFNode = &ContainerLD{}
|
||||
|
|
|
@ -2,6 +2,7 @@ package rdf
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -81,6 +82,13 @@ func (o *RDFOntology) LoadElement(name string, payload map[string]interface{}) (
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *RDFOntology) GetByName(name string) (RDFNode, error) {
|
||||
name = strings.TrimPrefix(name, o.SpecURI())
|
||||
switch name {
|
||||
}
|
||||
return nil, fmt.Errorf("rdf ontology could not find node for name %s", name)
|
||||
}
|
||||
|
||||
var _ RDFNode = &langstring{}
|
||||
|
||||
type langstring struct{}
|
||||
|
|
|
@ -3,6 +3,7 @@ package owl
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -212,6 +213,14 @@ func (o *OWLOntology) LoadElement(name string, payload map[string]interface{}) (
|
|||
return []rdf.RDFNode{node}, nil
|
||||
}
|
||||
|
||||
func (o *OWLOntology) GetByName(name string) (rdf.RDFNode, error) {
|
||||
name = strings.TrimPrefix(name, o.SpecURI())
|
||||
switch name {
|
||||
// TODO
|
||||
}
|
||||
return nil, fmt.Errorf("owl ontology could not find node for name %s", name)
|
||||
}
|
||||
|
||||
var _ rdf.RDFNode = &members{}
|
||||
|
||||
type members struct{}
|
||||
|
|
|
@ -120,7 +120,7 @@ func ParseVocabulary(registry *RDFRegistry, input JSONLD) (vocabulary *ParsedVoc
|
|||
// Prepend well-known JSON LD parsing nodes. Order matters, so that the
|
||||
// parser can understand things like types first, and populate it with
|
||||
// data afterwards.
|
||||
nodes = append(jsonLDNodes, nodes...)
|
||||
nodes = append(jsonLDNodes(registry), nodes...)
|
||||
err = apply(nodes, input, ctx)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ func splitAlias(s string) []string {
|
|||
type Ontology interface {
|
||||
// SpecURI refers to the URI location of this ontology.
|
||||
SpecURI() string
|
||||
|
||||
// The Load methods deal with determining how best to apply an ontology
|
||||
// based on the context specified by the data. This is before the data
|
||||
// is actually processed.
|
||||
|
||||
// Load loads the entire ontology.
|
||||
Load() ([]RDFNode, error)
|
||||
// LoadAsAlias loads the entire ontology with a specific alias.
|
||||
|
@ -57,6 +62,16 @@ type Ontology interface {
|
|||
// LoadElement loads a specific element of the ontology based on the
|
||||
// object definition.
|
||||
LoadElement(name string, payload map[string]interface{}) ([]RDFNode, error)
|
||||
|
||||
// The Get methods deal with determining how best to apply an ontology
|
||||
// during processing. This is a result of certain nodes having highly
|
||||
// contextual effects.
|
||||
|
||||
// GetByName returns an RDFNode associated with the given name. Note
|
||||
// that the name may either be fully-qualified (in the case it was not
|
||||
// aliased) or it may be just the element name (in the case it was
|
||||
// aliased).
|
||||
GetByName(name string) (RDFNode, error)
|
||||
}
|
||||
|
||||
// aliasedNode represents a context element that has a special reserved alias.
|
||||
|
@ -128,6 +143,8 @@ func (r *RDFRegistry) AddOntology(o Ontology) error {
|
|||
}
|
||||
|
||||
// getFor gets RDFKeyers based on a context's string.
|
||||
//
|
||||
// Package public.
|
||||
func (r *RDFRegistry) getFor(s string) (n []RDFNode, e error) {
|
||||
ontology, ok := r.ontologies[s]
|
||||
if !ok {
|
||||
|
@ -138,6 +155,8 @@ func (r *RDFRegistry) getFor(s string) (n []RDFNode, e error) {
|
|||
}
|
||||
|
||||
// getForAliased gets RDFKeyers based on a context's string.
|
||||
//
|
||||
// Private to this file.
|
||||
func (r *RDFRegistry) getForAliased(alias, s string) (n []RDFNode, e error) {
|
||||
ontology, ok := r.ontologies[s]
|
||||
if !ok {
|
||||
|
@ -149,6 +168,8 @@ func (r *RDFRegistry) getForAliased(alias, s string) (n []RDFNode, e error) {
|
|||
|
||||
// getAliased gets RDFKeyers based on a context string and its
|
||||
// alias.
|
||||
//
|
||||
// Package public.
|
||||
func (r *RDFRegistry) getAliased(alias, s string) (n []RDFNode, e error) {
|
||||
strs := splitAlias(s)
|
||||
if len(strs) == 1 {
|
||||
|
@ -172,6 +193,8 @@ func (r *RDFRegistry) getAliased(alias, s string) (n []RDFNode, e error) {
|
|||
|
||||
// getAliasedObject gets RDFKeyers based on a context object and
|
||||
// its alias and definition.
|
||||
//
|
||||
// Package public.
|
||||
func (r *RDFRegistry) getAliasedObject(alias string, object map[string]interface{}) (n []RDFNode, e error) {
|
||||
raw, ok := object[ID]
|
||||
if !ok {
|
||||
|
@ -200,3 +223,34 @@ func (r *RDFRegistry) getAliasedObject(alias string, object map[string]interface
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
// getNode fetches a node based on a string. It may be aliased or not.
|
||||
//
|
||||
// Package public.
|
||||
func (r *RDFRegistry) getNode(s string) (n RDFNode, e error) {
|
||||
strs := splitAlias(s)
|
||||
if len(strs) == 2 {
|
||||
if ontName, ok := r.aliases[strs[0]]; !ok {
|
||||
e = fmt.Errorf("no alias to ontology for %s", strs[0])
|
||||
return
|
||||
} else if ontology, ok := r.ontologies[ontName]; !ok {
|
||||
e = fmt.Errorf("no ontology named %s for alias %s", ontName, strs[0])
|
||||
return
|
||||
} else {
|
||||
n, e = ontology.GetByName(strs[1])
|
||||
return
|
||||
}
|
||||
} else if len(strs) == 1 {
|
||||
for _, ontology := range r.ontologies {
|
||||
if strings.HasPrefix(s, ontology.SpecURI()) {
|
||||
n, e = ontology.GetByName(s)
|
||||
return
|
||||
}
|
||||
}
|
||||
e = fmt.Errorf("getNode could not find ontology for %s", s)
|
||||
return
|
||||
} else {
|
||||
e = fmt.Errorf("getNode given unhandled node name: %s", s)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package rdfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RDFSchemaOntology struct{}
|
||||
|
@ -25,3 +27,11 @@ func (o *RDFSchemaOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNo
|
|||
func (o *RDFSchemaOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *RDFSchemaOntology) GetByName(name string) (rdf.RDFNode, error) {
|
||||
name = strings.TrimPrefix(name, o.SpecURI())
|
||||
switch name {
|
||||
// TODO
|
||||
}
|
||||
return nil, fmt.Errorf("rdfs ontology could not find node for name %s", name)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package schema
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -98,6 +99,14 @@ func (o *SchemaOntology) LoadElement(name string, payload map[string]interface{}
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *SchemaOntology) GetByName(name string) (rdf.RDFNode, error) {
|
||||
name = strings.TrimPrefix(name, o.SpecURI())
|
||||
switch name {
|
||||
// TODO
|
||||
}
|
||||
return nil, fmt.Errorf("schema ontology could not find node for name %s", name)
|
||||
}
|
||||
|
||||
var _ rdf.RDFNode = &example{}
|
||||
|
||||
type example struct{}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package xsd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type XMLOntology struct{}
|
||||
|
@ -25,3 +27,11 @@ func (o *XMLOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, er
|
|||
func (o *XMLOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *XMLOntology) GetByName(name string) (rdf.RDFNode, error) {
|
||||
name = strings.TrimPrefix(name, o.SpecURI())
|
||||
switch name {
|
||||
// TODO
|
||||
}
|
||||
return nil, fmt.Errorf("xsd ontology could not find node for name %s", name)
|
||||
}
|
||||
|
|
読み込み中…
新しいイシューから参照