Fix aliasing specific elements.
Also adds some placeholders for the schema ontology. Eliminated some dead code in the RDF manager thing. Next step is to get mainEntity parsing to ignore the rest of the values, which should be easier to do, maybe.
このコミットが含まれているのは:
コミット
30f9f6a16b
|
@ -18,6 +18,10 @@ 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
|
||||
}
|
||||
|
|
|
@ -111,17 +111,22 @@ type ContainerLD struct {
|
|||
}
|
||||
|
||||
func (c *ContainerLD) Enter(key string, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
if ctx.OnlyApplyThisNodeNextLevel != nil {
|
||||
return true, fmt.Errorf("@container parsing context exit already has non-nil node")
|
||||
}
|
||||
ctx.SetOnlyApplyThisNodeNextLevel(c.ContainsNode)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (c *ContainerLD) Exit(key string, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
if ctx.OnlyApplyThisNodeNextLevel == nil {
|
||||
return true, fmt.Errorf("@container parsing context exit already has nil node")
|
||||
}
|
||||
ctx.ResetOnlyAppliedThisNodeNextLevel()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (c *ContainerLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
@ -130,16 +135,13 @@ var _ RDFNode = &IndexLD{}
|
|||
type IndexLD struct{}
|
||||
|
||||
func (i *IndexLD) Enter(key string, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (i *IndexLD) Exit(key string, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (i *IndexLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -44,6 +44,39 @@ func (o *RDFOntology) LoadAsAlias(s string) ([]RDFNode, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (o *RDFOntology) LoadSpecificAsAlias(alias, name string) ([]RDFNode, error) {
|
||||
switch name {
|
||||
case langstringSpec:
|
||||
return []RDFNode{
|
||||
&AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &langstring{},
|
||||
},
|
||||
}, nil
|
||||
case propertySpec:
|
||||
return []RDFNode{
|
||||
&AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &property{},
|
||||
},
|
||||
}, nil
|
||||
case valueSpec:
|
||||
return []RDFNode{
|
||||
&AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &value{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("rdf ontology cannot find %q to make alias %q", name, alias)
|
||||
}
|
||||
|
||||
func (o *RDFOntology) LoadElement(name string, payload map[string]interface{}) ([]RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -83,6 +83,84 @@ func (o *OWLOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (o *OWLOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, error) {
|
||||
switch name {
|
||||
case membersSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &members{},
|
||||
},
|
||||
}, nil
|
||||
case disjointWithSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &disjointWith{},
|
||||
},
|
||||
}, nil
|
||||
case unionOfSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &unionOf{},
|
||||
},
|
||||
}, nil
|
||||
case importsSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &imports{},
|
||||
},
|
||||
}, nil
|
||||
case ontologySpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &ontology{},
|
||||
},
|
||||
}, nil
|
||||
case classSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &class{},
|
||||
},
|
||||
}, nil
|
||||
case objectPropertySpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &objectProperty{},
|
||||
},
|
||||
}, nil
|
||||
case functionalPropertySpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &functionalProperty{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("owl ontology cannot find %q to alias to %q", name, alias)
|
||||
}
|
||||
|
||||
func (o *OWLOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
// First, detect if an idValue exists
|
||||
var idValue interface{}
|
||||
|
|
|
@ -19,6 +19,30 @@ type ParsingContext struct {
|
|||
Current interface{}
|
||||
Name string
|
||||
Stack []interface{}
|
||||
// For processing manipulation
|
||||
OnlyApplyThisNodeNextLevel RDFNode
|
||||
OnlyApplied bool
|
||||
}
|
||||
|
||||
func (p *ParsingContext) SetOnlyApplyThisNodeNextLevel(n RDFNode) {
|
||||
p.OnlyApplyThisNodeNextLevel = n
|
||||
p.OnlyApplied = false
|
||||
}
|
||||
|
||||
func (p *ParsingContext) GetNextNodes(n []RDFNode) []RDFNode {
|
||||
if p.OnlyApplyThisNodeNextLevel == nil {
|
||||
return n
|
||||
} else if p.OnlyApplied {
|
||||
return n
|
||||
} else {
|
||||
p.OnlyApplied = true
|
||||
return []RDFNode{p.OnlyApplyThisNodeNextLevel}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParsingContext) ResetOnlyAppliedThisNodeNextLevel() {
|
||||
p.OnlyApplyThisNodeNextLevel = nil
|
||||
p.OnlyApplied = false
|
||||
}
|
||||
|
||||
func (p *ParsingContext) Push() {
|
||||
|
@ -90,34 +114,39 @@ func apply(nodes []RDFNode, input JSONLD, ctx *ParsingContext) error {
|
|||
if k == JSON_LD_CONTEXT {
|
||||
continue
|
||||
}
|
||||
// Hijacked processing: Only use the ParsingContext's node to
|
||||
// handle all elements.
|
||||
recurNodes := nodes
|
||||
enterApplyExitNodes := ctx.GetNextNodes(nodes)
|
||||
// Normal recursive processing
|
||||
if mapValue, ok := v.(map[string]interface{}); ok {
|
||||
if err := enterFirstNode(nodes, k, ctx); err != nil {
|
||||
if err := enterFirstNode(enterApplyExitNodes, k, ctx); err != nil {
|
||||
return err
|
||||
} else if err = apply(nodes, mapValue, ctx); err != nil {
|
||||
} else if err = apply(recurNodes, mapValue, ctx); err != nil {
|
||||
return err
|
||||
} else if err = exitFirstNode(nodes, k, ctx); err != nil {
|
||||
} else if err = exitFirstNode(enterApplyExitNodes, k, ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if arrValue, ok := v.([]interface{}); ok {
|
||||
for _, val := range arrValue {
|
||||
// First, enter for this key
|
||||
if err := enterFirstNode(nodes, k, ctx); err != nil {
|
||||
if err := enterFirstNode(enterApplyExitNodes, k, ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
// Recur or handle the value as necessary.
|
||||
if mapValue, ok := val.(map[string]interface{}); ok {
|
||||
if err := apply(nodes, mapValue, ctx); err != nil {
|
||||
if err := apply(recurNodes, mapValue, ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err := applyFirstNode(nodes, k, val, ctx); err != nil {
|
||||
} else if err := applyFirstNode(enterApplyExitNodes, k, val, ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
// Finally, exit for this key
|
||||
if err := exitFirstNode(nodes, k, ctx); err != nil {
|
||||
if err := exitFirstNode(enterApplyExitNodes, k, ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if err := applyFirstNode(nodes, k, v, ctx); err != nil {
|
||||
} else if err := applyFirstNode(enterApplyExitNodes, k, v, ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,10 +49,13 @@ type Ontology interface {
|
|||
SpecURI() string
|
||||
// Load loads the entire ontology.
|
||||
Load() ([]RDFNode, error)
|
||||
// Load loads the entire ontology with a specific alias.
|
||||
// LoadAsAlias loads the entire ontology with a specific alias.
|
||||
LoadAsAlias(s string) ([]RDFNode, error)
|
||||
// LoadElement loads a specific element of the ontology by name. The
|
||||
// payload may be nil.
|
||||
// LoadSpecificAsAlias loads a specific element of the ontology by
|
||||
// being able to handle the specific alias as its name instead.
|
||||
LoadSpecificAsAlias(alias, name string) ([]RDFNode, error)
|
||||
// LoadElement loads a specific element of the ontology based on the
|
||||
// object definition.
|
||||
LoadElement(name string, payload map[string]interface{}) ([]RDFNode, error)
|
||||
}
|
||||
|
||||
|
@ -111,21 +114,6 @@ func (r *RDFRegistry) getOntology(alias string) (Ontology, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// loadElement will handle the aliasing of an ontology and retrieve the nodes
|
||||
// required for a specific element within that ontology.
|
||||
func (r *RDFRegistry) loadElement(alias, element string, payload map[string]interface{}) (n []RDFNode, e error) {
|
||||
if ontName, ok := r.aliases[alias]; !ok {
|
||||
e = fmt.Errorf("no alias to ontology for %s", alias)
|
||||
return
|
||||
} else if ontology, ok := r.ontologies[ontName]; !ok {
|
||||
e = fmt.Errorf("no ontology named %s for alias %s", ontName, alias)
|
||||
return
|
||||
} else {
|
||||
n, e = ontology.LoadElement(element, payload)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// AddOntology adds an RDF ontology to the registry.
|
||||
func (r *RDFRegistry) AddOntology(o Ontology) error {
|
||||
if r.ontologies == nil {
|
||||
|
@ -174,7 +162,8 @@ func (r *RDFRegistry) getAliased(alias, s string) (n []RDFNode, e error) {
|
|||
if e != nil {
|
||||
return
|
||||
}
|
||||
n, e = o.LoadElement(strs[1], nil)
|
||||
fmt.Println(strs)
|
||||
n, e = o.LoadSpecificAsAlias(alias, strs[1])
|
||||
return
|
||||
} else {
|
||||
e = fmt.Errorf("too many delimiters in %s", s)
|
||||
|
|
|
@ -18,6 +18,10 @@ func (o *RDFSchemaOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *RDFSchemaOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *RDFSchemaOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -1,23 +1,140 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cjslep/activity/tools/exp/rdf"
|
||||
)
|
||||
|
||||
const (
|
||||
schemaSpec = "http://schema.org/"
|
||||
exampleSpec = "workExample"
|
||||
mainEntitySpec = "mainEntity"
|
||||
urlSpec = "URL"
|
||||
)
|
||||
|
||||
type SchemaOntology struct{}
|
||||
|
||||
func (o *SchemaOntology) SpecURI() string {
|
||||
return "http://schema.org/"
|
||||
return schemaSpec
|
||||
}
|
||||
|
||||
func (o *SchemaOntology) Load() ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
return o.LoadAsAlias("")
|
||||
}
|
||||
|
||||
func (o *SchemaOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: schemaSpec,
|
||||
Alias: s,
|
||||
Name: exampleSpec,
|
||||
Delegate: &example{},
|
||||
},
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: schemaSpec,
|
||||
Alias: s,
|
||||
Name: mainEntitySpec,
|
||||
Delegate: &mainEntity{},
|
||||
},
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: schemaSpec,
|
||||
Alias: s,
|
||||
Name: urlSpec,
|
||||
Delegate: &URL{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (o *SchemaOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, error) {
|
||||
switch name {
|
||||
case exampleSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &example{},
|
||||
},
|
||||
}, nil
|
||||
case mainEntitySpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &mainEntity{},
|
||||
},
|
||||
}, nil
|
||||
case urlSpec:
|
||||
return []rdf.RDFNode{
|
||||
&rdf.AliasedDelegate{
|
||||
Spec: "",
|
||||
Alias: "",
|
||||
Name: alias,
|
||||
Delegate: &URL{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("schema ontology cannot find %q to alias to %q", name, alias)
|
||||
}
|
||||
|
||||
func (o *SchemaOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var _ rdf.RDFNode = &example{}
|
||||
|
||||
type example struct{}
|
||||
|
||||
func (e *example) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (e *example) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (e *example) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var _ rdf.RDFNode = &mainEntity{}
|
||||
|
||||
type mainEntity struct{}
|
||||
|
||||
func (m *mainEntity) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (m *mainEntity) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (m *mainEntity) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var _ rdf.RDFNode = &URL{}
|
||||
|
||||
type URL struct{}
|
||||
|
||||
func (u *URL) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (u *URL) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (u *URL) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
|
||||
// TODO
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ func (o *XMLOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *XMLOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o *XMLOntology) LoadElement(name string, payload map[string]interface{}) ([]rdf.RDFNode, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
読み込み中…
新しいイシューから参照