Skip to content

Commit

Permalink
linkedql: use voc package more
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Dec 30, 2019
1 parent eae4452 commit ce8b18b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/badgerodon/peg v0.0.0-20130729175151-9e5f7f4d07ca
github.com/cayleygraph/quad v1.1.0
github.com/cayleygraph/quad v1.2.1
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
github.com/coreos/bbolt v1.3.3 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/cayleygraph/quad v1.1.0 h1:w1nXAmn+nz07+qlw89dke9LwWkYpeX+OcvfTvGQRBpM=
github.com/cayleygraph/quad v1.1.0/go.mod h1:maWODEekEhrO0mdc9h5n/oP7cH1h/OTgqQ2qWbuI9M4=
github.com/cayleygraph/quad v1.2.0/go.mod h1:maWODEekEhrO0mdc9h5n/oP7cH1h/OTgqQ2qWbuI9M4=
github.com/cayleygraph/quad v1.2.1 h1:PqqP+F8BLICaAWoGvSlrx1U11pXEc2BBodmTv30uSLM=
github.com/cayleygraph/quad v1.2.1/go.mod h1:maWODEekEhrO0mdc9h5n/oP7cH1h/OTgqQ2qWbuI9M4=
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down
46 changes: 24 additions & 22 deletions internal/linkedql/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (

"github.com/cayleygraph/cayley/query/linkedql"
"github.com/cayleygraph/quad"
"github.com/cayleygraph/quad/voc/owl"
"github.com/cayleygraph/quad/voc/rdf"
"github.com/cayleygraph/quad/voc/rdfs"
"github.com/cayleygraph/quad/voc/xsd"
)

var (
Expand All @@ -22,15 +25,14 @@ func typeToRange(t reflect.Type) string {
if t.Kind() == reflect.Slice {
return typeToRange(t.Elem())
}
// TODO: add XSD types to voc package
if t.Kind() == reflect.String {
return "xsd:string"
return xsd.String
}
if t.Kind() == reflect.Bool {
return "xsd:boolean"
return xsd.Boolean
}
if kind := t.Kind(); kind == reflect.Int64 || kind == reflect.Int {
return "xsd:int"
return xsd.Int
}
if t.Implements(pathStep) {
return linkedql.Prefix + "PathStep"
Expand All @@ -42,7 +44,7 @@ func typeToRange(t reflect.Type) string {
return rdfs.Resource
}
if t.Implements(entityIdentifier) {
return "owl:Thing"
return owl.Thing
}
if t == propertyPath {
return linkedql.Prefix + "PropertyPath"
Expand Down Expand Up @@ -76,7 +78,7 @@ func newBlankNodeID() string {
func newSingleCardinalityRestriction(prop string) cardinalityRestriction {
return cardinalityRestriction{
ID: newBlankNodeID(),
Type: "owl:Restriction",
Type: owl.Restriction,
Cardinality: 1,
Property: identified{ID: prop},
}
Expand All @@ -85,9 +87,9 @@ func newSingleCardinalityRestriction(prop string) cardinalityRestriction {
// getOWLPropertyType for given kind of value type returns property OWL type
func getOWLPropertyType(kind reflect.Kind) string {
if kind == reflect.String || kind == reflect.Bool || kind == reflect.Int64 || kind == reflect.Int {
return "owl:DatatypeProperty"
return owl.DatatypeProperty
}
return "owl:ObjectProperty"
return owl.ObjectProperty
}

// property is used to declare a property
Expand Down Expand Up @@ -151,7 +153,7 @@ func newUnionOf(classes []string) unionOf {
}
return unionOf{
ID: newBlankNodeID(),
Type: "owl:Class",
Type: owl.Class,
List: newList(members),
}
}
Expand Down Expand Up @@ -260,28 +262,28 @@ func (g *generator) Generate() []byte {
}
graph := []interface{}{
map[string]string{
"@id": "linkedql:Step",
"@type": "owl:Class",
"@id": linkedql.Prefix + "Step",
"@type": owl.Class,
},
map[string]interface{}{
"@id": "linkedql:PathStep",
"@type": "owl:Class",
"rdfs:subClassOf": identified{ID: "linkedql:Step"},
"@id": linkedql.Prefix + "PathStep",
"@type": owl.Class,
rdfs.SubClassOf: identified{ID: linkedql.Prefix + "Step"},
},
map[string]interface{}{
"@id": "linkedql:IteratorStep",
"@type": "owl:Class",
"rdfs:subClassOf": identified{ID: "linkedql:Step"},
"@id": linkedql.Prefix + "IteratorStep",
"@type": owl.Class,
rdfs.SubClassOf: identified{ID: linkedql.Prefix + "Step"},
},
}
graph = append(graph, g.out...)
data, err := json.Marshal(map[string]interface{}{
"@context": map[string]interface{}{
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"owl": "http://www.w3.org/2002/07/owl#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"linkedql": "http://cayley.io/linkedql#",
"rdf": rdf.NS,
"rdfs": rdfs.NS,
"owl": owl.NS,
"xsd": xsd.NS,
"linkedql": linkedql.Namespace,
},
"@graph": graph,
})
Expand Down

0 comments on commit ce8b18b

Please sign in to comment.