Finish implementing ontologies.

- ActivityStreams specification can now be entirely parsed.
- Removed print statements
- Added missing ontology items to rdfs
このコミットが含まれているのは:
Cory Slep 2018-12-05 23:36:27 +01:00
コミット e5693c2eb9
4個のファイルの変更107行の追加33行の削除

ファイルの表示

@ -97,7 +97,6 @@ func (t *typeLD) Exit(key string, ctx *ParsingContext) (bool, error) {
}
func (t *typeLD) Apply(key string, value interface{}, ctx *ParsingContext) (bool, error) {
fmt.Printf("@type key=%s, value=%v\n", key, value)
vs, ok := value.(string)
if !ok {
return true, fmt.Errorf("@type is not string")
@ -116,7 +115,6 @@ type ContainerLD struct {
}
func (c *ContainerLD) Enter(key string, ctx *ParsingContext) (bool, error) {
fmt.Println("===container enter")
if ctx.OnlyApplyThisNodeNextLevel != nil {
return true, fmt.Errorf("@container parsing context exit already has non-nil node")
}
@ -125,7 +123,6 @@ func (c *ContainerLD) Enter(key string, ctx *ParsingContext) (bool, error) {
}
func (c *ContainerLD) Exit(key string, ctx *ParsingContext) (bool, error) {
fmt.Println("===container exit")
if ctx.OnlyApplyThisNodeNextLevel == nil {
return true, fmt.Errorf("@container parsing context exit already has nil node")
}
@ -142,12 +139,10 @@ var _ RDFNode = &IndexLD{}
type IndexLD struct{}
func (i *IndexLD) Enter(key string, ctx *ParsingContext) (bool, error) {
fmt.Println(">>> enter index")
return true, nil
}
func (i *IndexLD) Exit(key string, ctx *ParsingContext) (bool, error) {
fmt.Println(">>> exit index")
return true, nil
}

ファイルの表示

@ -313,15 +313,19 @@ func (d *disjointWith) Apply(key string, value interface{}, ctx *rdf.ParsingCont
var _ rdf.RDFNode = &unionOf{}
type unionOf struct{}
type unionOf struct {
entered bool
}
func (u *unionOf) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
u.entered = true
ctx.Push()
ctx.Current = &rdf.VocabularyReference{}
return true, nil
}
func (u *unionOf) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
u.entered = false
if ctx.Current == nil {
return true, fmt.Errorf("owl unionOf exit given nil Current")
}
@ -354,11 +358,20 @@ func (u *unionOf) Apply(key string, value interface{}, ctx *rdf.ParsingContext)
} else {
return true, fmt.Errorf("owl unionOf apply bad SplitAlias")
}
arr, ok := ctx.Current.([]rdf.VocabularyReference)
if !ok {
return true, fmt.Errorf("owl unionOf apply's Current not given []rdf.VocabularyReference")
if u.entered {
in, ok := ctx.Current.(*rdf.VocabularyReference)
if !ok {
return true, fmt.Errorf("owl unionOf apply's Current not given *rdf.VocabularyReference: %T", ctx.Current)
}
in.Name = ref.Name
in.Vocab = ref.Vocab
} else {
arr, ok := ctx.Current.([]rdf.VocabularyReference)
if !ok {
return true, fmt.Errorf("owl unionOf apply's Current not given []rdf.VocabularyReference: %T", ctx.Current)
}
ctx.Current = append(arr, *ref)
}
ctx.Current = append(arr, *ref)
return true, nil
}
@ -414,6 +427,8 @@ func (c *class) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (b
ctx.Current = &rdf.VocabularyType{}
} else if _, ok := ctx.Current.(*rdf.VocabularyReference); ok {
return true, nil
} else if _, ok := ctx.Current.([]rdf.VocabularyReference); ok {
return true, nil
} else {
return true, fmt.Errorf("owl class applied with non-reset ctx and not a vocab reference: %T", ctx.Current)
}

ファイルの表示

@ -49,12 +49,12 @@ func (p *ParsingContext) SetOnlyApplyThisNodeNextLevel(n RDFNode) {
func (p *ParsingContext) GetNextNodes(n []RDFNode) (r []RDFNode, clearFn func()) {
if p.OnlyApplyThisNodeNextLevel == nil {
return n, func () {}
return n, func() {}
} else if p.OnlyApplied {
return n, func () {}
return n, func() {}
} else {
p.OnlyApplied = true
return []RDFNode{p.OnlyApplyThisNodeNextLevel}, func () {
return []RDFNode{p.OnlyApplyThisNodeNextLevel}, func() {
p.OnlyApplied = false
}
}
@ -162,7 +162,6 @@ func apply(nodes []RDFNode, input JSONLD, ctx *ParsingContext) error {
}
// Normal recursive processing
for k, v := range input {
fmt.Println(k)
// Skip things we have already processed: context and type
if k == JSON_LD_CONTEXT {
continue

ファイルの表示

@ -34,6 +34,36 @@ func (o *RDFSchemaOntology) LoadAsAlias(s string) ([]rdf.RDFNode, error) {
Name: commentSpec,
Delegate: &comment{},
},
&rdf.AliasedDelegate{
Spec: rdfsSpecURI,
Alias: s,
Name: domainSpec,
Delegate: &domain{},
},
&rdf.AliasedDelegate{
Spec: rdfsSpecURI,
Alias: s,
Name: isDefinedBySpec,
Delegate: &isDefinedBy{},
},
&rdf.AliasedDelegate{
Spec: rdfsSpecURI,
Alias: s,
Name: rangeSpec,
Delegate: &ranges{},
},
&rdf.AliasedDelegate{
Spec: rdfsSpecURI,
Alias: s,
Name: subClassOfSpec,
Delegate: &subClassOf{},
},
&rdf.AliasedDelegate{
Spec: rdfsSpecURI,
Alias: s,
Name: subPropertyOfSpec,
Delegate: &subPropertyOf{},
},
}, nil
}
@ -90,7 +120,7 @@ func (o *RDFSchemaOntology) LoadSpecificAsAlias(alias, name string) ([]rdf.RDFNo
Spec: "",
Alias: "",
Name: alias,
Delegate: &comment{},
Delegate: &subPropertyOf{},
},
}, nil
}
@ -153,18 +183,28 @@ var _ rdf.RDFNode = &domain{}
type domain struct{}
func (d *domain) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
ctx.Push()
ctx.Current = make([]rdf.VocabularyReference, 0)
return true, nil
}
func (d *domain) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
i := ctx.Current
ctx.Pop()
vr, ok := i.([]rdf.VocabularyReference)
if !ok {
return true, fmt.Errorf("rdfs domain exit did not get []rdf.VocabularyReference")
}
vp, ok := ctx.Current.(*rdf.VocabularyProperty)
if !ok {
return true, fmt.Errorf("rdf domain exit Current is not *rdf.VocabularyProperty")
}
vp.Domain = append(vp.Domain, vr...)
return true, nil
}
func (d *domain) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
// TODO
return true, nil
return true, fmt.Errorf("rdfs domain cannot be applied")
}
var _ rdf.RDFNode = &isDefinedBy{}
@ -172,18 +212,23 @@ var _ rdf.RDFNode = &isDefinedBy{}
type isDefinedBy struct{}
func (i *isDefinedBy) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
return true, nil
return true, fmt.Errorf("rdfs isDefinedBy cannot be entered")
}
func (i *isDefinedBy) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
return true, nil
return true, fmt.Errorf("rdfs isDefinedBy cannot be exited")
}
func (i *isDefinedBy) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
// TODO
return true, nil
s, ok := value.(string)
if !ok {
return true, fmt.Errorf("rdfs isDefinedBy given non-string: %T", value)
}
u, ok := ctx.Current.(rdf.URISetter)
if !ok {
return true, fmt.Errorf("rdfs isDefinedBy Current is not rdf.URISetter: %T", ctx.Current)
}
return true, u.SetURI(s)
}
var _ rdf.RDFNode = &ranges{}
@ -191,18 +236,28 @@ var _ rdf.RDFNode = &ranges{}
type ranges struct{}
func (r *ranges) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
ctx.Push()
ctx.Current = make([]rdf.VocabularyReference, 0)
return true, nil
}
func (r *ranges) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
i := ctx.Current
ctx.Pop()
vr, ok := i.([]rdf.VocabularyReference)
if !ok {
return true, fmt.Errorf("rdfs ranges exit did not get []rdf.VocabularyReference")
}
vp, ok := ctx.Current.(*rdf.VocabularyProperty)
if !ok {
return true, fmt.Errorf("rdf ranges exit Current is not *rdf.VocabularyProperty")
}
vp.Range = append(vp.Range, vr...)
return true, nil
}
func (r *ranges) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
// TODO
return true, nil
return true, fmt.Errorf("rdfs ranges cannot be applied")
}
var _ rdf.RDFNode = &subClassOf{}
@ -239,16 +294,26 @@ var _ rdf.RDFNode = &subPropertyOf{}
type subPropertyOf struct{}
func (s *subPropertyOf) Enter(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
ctx.Push()
ctx.Current = &rdf.VocabularyReference{}
return true, nil
}
func (s *subPropertyOf) Exit(key string, ctx *rdf.ParsingContext) (bool, error) {
// TODO
i := ctx.Current
ctx.Pop()
vr, ok := i.(*rdf.VocabularyReference)
if !ok {
return true, fmt.Errorf("rdfs subpropertyof exit did not get *rdf.VocabularyReference")
}
vp, ok := ctx.Current.(*rdf.VocabularyProperty)
if !ok {
return true, fmt.Errorf("rdf subpropertyof exit Current is not *rdf.VocabularyProperty")
}
vp.SubpropertyOf = *vr
return true, nil
}
func (s *subPropertyOf) Apply(key string, value interface{}, ctx *rdf.ParsingContext) (bool, error) {
// TODO
return true, nil
return true, fmt.Errorf("rdfs subpropertyof cannot be applied")
}