Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
0c52a21
Create package linkedql
iddan Oct 17, 2019
490d8b4
Add test and remove limit from session
iddan Oct 17, 2019
28877a5
Correct structure
iddan Oct 17, 2019
2bd94ea
linkedql: add registration for query steps
dennwc Oct 17, 2019
93a4858
Improve naming of steps
iddan Oct 17, 2019
ce7af58
linkedql: Integrated registry to the interface
iddan Oct 17, 2019
7bf8db4
linkedql: Better description of Vertex, Description of Out
iddan Oct 17, 2019
51a1f45
linkedql: Implement parsing of quad.Value and BuildPath for Out
iddan Oct 17, 2019
ab54d8d
linkedql: actual test cases
iddan Oct 17, 2019
309afe1
linkedql: Step to have BuildIterator method which can return any iter…
iddan Oct 17, 2019
7ee92e5
linkedql: Added failing test case for TagArray
iddan Oct 17, 2019
bef6bd0
linkedql: Implement TagArray iterator
iddan Oct 17, 2019
b391eb5
linkedql: Scanner to be private
iddan Oct 17, 2019
89b17b8
Rename Tag to As
iddan Oct 17, 2019
5896f6b
linkedql: use parseValue in UnmarshalStep
iddan Oct 17, 2019
6d6b9c6
linkedql: Is
iddan Oct 17, 2019
fba7ed0
linkedql: Both
iddan Oct 17, 2019
5f183df
linkedql: More operators
iddan Oct 17, 2019
f850333
linkedql: follow
iddan Oct 17, 2019
244e190
linkedql: boilerplate code for all steps
iddan Oct 17, 2019
88ec741
linkedql: Has and more
iddan Oct 17, 2019
b7d1428
linkedql: HasR -> HasReverse
iddan Oct 17, 2019
2978617
Most of the steps are implemented
iddan Oct 17, 2019
0fecbcf
linkedql: Test Back, Both, Count, Except
iddan Oct 18, 2019
024efe4
linkedql: Test steps themselves instead of session
iddan Oct 18, 2019
1291a9d
linkedql: Test HasReverse & In
iddan Oct 18, 2019
5e0afc6
linkedql: Intersect, Is, InPredicates, In
iddan Oct 18, 2019
a1db39e
linkedql: Test OutPredicates
iddan Oct 18, 2019
ff95bda
linkedql: Test Save and add todo
iddan Oct 18, 2019
4393e00
linkedql: Test SaveInPredicates
iddan Oct 18, 2019
9f7f11d
linkedql: Test SaveOptional
iddan Oct 18, 2019
9f0b054
linkedql: Test SaveOptionalReverse
iddan Oct 18, 2019
4c84d7f
linkedql: Test SaveOutPredicates
iddan Oct 18, 2019
ec948db
linkedql: Test SaveReverse
iddan Oct 18, 2019
6b3e614
linkedql: Fix Limit test name, Test Skip, Fix Skip
iddan Oct 18, 2019
fceecc6
linkedql: Test Union
iddan Oct 18, 2019
2301a38
linkedql: Implement TagValue and Test
iddan Oct 18, 2019
4c2c18b
linkedql: Test Unique
iddan Oct 18, 2019
658d313
linkedql: Test Order
iddan Oct 18, 2019
24a2c15
linkedql: Add todo regarding single values
iddan Oct 18, 2019
4f60034
linkedql: Test Like
iddan Oct 18, 2019
044acb0
linkedql: Test operation filters
iddan Oct 18, 2019
b27ee9f
Refactor code
iddan Oct 22, 2019
a9b0b7c
linkedql: Move final steps to different module
iddan Oct 22, 2019
c067f80
linkedql: Correct todo format
iddan Oct 22, 2019
7286a0c
linkedql: Differenciate operators
iddan Oct 22, 2019
8085fdf
linkedql: Rename RegExp.Expression to Pattern
iddan Oct 22, 2019
6e6a80d
linkedql: Remove LabelContext
iddan Oct 22, 2019
e4e86b4
linkedql: Fix errors with former changes
iddan Oct 22, 2019
dbb8c24
linkedql: Add comments to value_iterator.go
iddan Oct 22, 2019
c353ead
linkedql: Change error in parseValue
iddan Oct 22, 2019
5c6a990
linkedql: Unify constants
iddan Oct 22, 2019
b7dc3a4
linkedql: Fix errors from rebasing
iddan Oct 22, 2019
a960d6d
linkedql: Remove casting of operations
iddan Oct 22, 2019
0486953
linkedql: Limit values in TagValue and Value
iddan Oct 22, 2019
07acf4f
linkedql: Support special strings in parseValue
iddan Oct 25, 2019
23b2ba5
linkedql: Rename field in Intersect and allow slice
iddan Oct 25, 2019
5c5009e
linkedql: Move implementation of operators to them
iddan Oct 25, 2019
a4a17cd
linkedql: select
iddan Oct 26, 2019
d7840a5
linkedql: Add dot in the end of sentences
iddan Oct 26, 2019
7ae0124
linkedql: Make optional a flag in save and saveReverse
iddan Oct 26, 2019
90d8c0e
linkedql: Renamed valueIterator to valueit in TagsIterator
iddan Oct 26, 2019
30d0489
linkedql: Corrected syntax in value_iterator
iddan Oct 26, 2019
cc9d466
linkedql: Accept slice in Union
iddan Oct 26, 2019
8ad23e3
linkedql: Rename steps in intersect and union
iddan Nov 5, 2019
0afadcb
linkedql: Use quad values in parseValue
iddan Nov 6, 2019
30a8999
linkedql: Optional and Morphism steps
iddan Nov 8, 2019
ee3b6c3
linkedql: Improve test for optional
iddan Nov 8, 2019
72ce092
Rename save to properties
iddan Nov 8, 2019
71dbc17
Only allow IRIs in Properties
iddan Nov 9, 2019
79b0034
Update names of SaveInPredicates, SaveOutPredicates, SaveReverse
iddan Nov 9, 2019
ec8e01d
linkedql: Accept PathStep in Follow
iddan Nov 9, 2019
0586fc3
linkedql: Convert to PathStep missing
iddan Nov 9, 2019
dcd1daa
linkedql: rename outPredicates and inPredicates
iddan Nov 9, 2019
fcd911d
Correct name for Properties
iddan Nov 9, 2019
2ac2cfe
linkedql: Basic implementation of .documents()
iddan Nov 10, 2019
d4c9add
linkedql: Refactor out ValueStep for PathStep only
iddan Nov 10, 2019
e6546d7
linkedql Reduce repeating code for creating value iterators
iddan Nov 10, 2019
7c8e3ae
linkedql: Support IRIs in registry
iddan Nov 11, 2019
71a9943
linkedql: correct name of document iterator file
iddan Nov 11, 2019
1c95b37
Rename .in() and .out()
iddan Nov 13, 2019
b7ebe49
Fix usage of structs
iddan Nov 13, 2019
34962cb
Make aliases for .out() and .in() and correct type of view
iddan Nov 13, 2019
afa3e53
Remove tags from View and ViewReverse
iddan Nov 13, 2019
3d2d0ba
Add Description to Steps
iddan Nov 13, 2019
42b8fe2
Add Description where missing
iddan Nov 13, 2019
e7f72ef
Add jsonschema dep
iddan Oct 26, 2019
62d835f
linkedql: remove jsonschema
iddan Oct 26, 2019
75772ba
linkedql: Basic schema output works
iddan Oct 27, 2019
6ce7180
linkedql: clean schema code and correct property names
iddan Oct 27, 2019
b57515b
linkedql: Add todo
iddan Oct 27, 2019
1ad62c4
linkedql: Add cardinality restriction on properties
iddan Oct 27, 2019
b00501a
linkedql: Fix schema not registered
iddan Oct 27, 2019
b77a028
linkedql: Use json tag for property name
iddan Oct 27, 2019
e3bc56e
linkedql: Use strict Go types in schema creation
iddan Oct 27, 2019
bc7a9d5
linkedql: Fix Identified JSON and add comments
iddan Oct 27, 2019
ceb9d54
linkedql: OWL more specific property type
iddan Oct 27, 2019
1d35b2e
linkedql: Correct name to SuperClasses
iddan Oct 27, 2019
a5ec5ab
Correct name of bool
iddan Oct 27, 2019
9165a9c
Create a correct schema
iddan Nov 1, 2019
e5f6f70
Nest restrictions
iddan Nov 1, 2019
51b65b5
Update code to use PathStep
iddan Nov 13, 2019
80fd749
Add checks for all steps
iddan Nov 13, 2019
913cbe6
Not all PathSteps are Steps
iddan Nov 13, 2019
5447d0b
Don't assume step is iterable
iddan Nov 13, 2019
2b43390
Bring back aliases and fix anonymous in schema generation
iddan Nov 13, 2019
13e5a3d
More interface validation
iddan Nov 13, 2019
d08b51e
WIP: get description
iddan Nov 13, 2019
111c2b4
Placehold comment for now
iddan Nov 13, 2019
878b98d
Add description to schema
iddan Nov 13, 2019
7e4d4dc
Add linkedql-schema command to cayley CLI
iddan Nov 13, 2019
2d6ce5d
Add back in and out aliases
iddan Nov 13, 2019
388a058
Fix properties of nested aliases
iddan Nov 13, 2019
69e8772
Recover go mod and sum files
iddan Nov 14, 2019
5cbe761
Improve description of vertex
iddan Nov 14, 2019
315a18f
Rename Morphism to Placeholder, move it and give it better description
iddan Nov 14, 2019
e10d432
Improve the description of View
iddan Nov 14, 2019
756e962
Change as to retreive one name only and improve description
iddan Nov 14, 2019
d5faa0e
Correct field access for as
iddan Nov 14, 2019
cfef7d4
Correct usage of Placeholder
iddan Nov 14, 2019
ced7125
Improve description of Intersect
iddan Nov 14, 2019
fedc80e
Align format for all edited descriptions
iddan Nov 15, 2019
53faba1
Improve naming and description of Back
iddan Nov 15, 2019
6517960
Rename both to viewBoth
iddan Nov 15, 2019
016c91d
Correct tests
iddan Nov 15, 2019
151b60b
Rename except to difference
iddan Nov 15, 2019
58bb902
Alias ViewBoth with Both
iddan Nov 15, 2019
7d57e4c
TestGenerateSchema to just validate no error was thrown
iddan Nov 15, 2019
aa1be1e
Add Where step
iddan Nov 16, 2019
f6ec475
linkedql: Allow passing IRIs and strings as properties
iddan Nov 16, 2019
a72a4f7
linkedql: Add comments for PropertyIRIStrings
iddan Nov 16, 2019
112b66d
Add TODO comments for properties
iddan Nov 16, 2019
8b36250
linkedql: rename iterator files to have a common prefix
dennwc Nov 16, 2019
f2f7ec3
linkedql: refactor DocumentIterator
dennwc Nov 16, 2019
0c3888a
linkedql: make sure iterators implement corresponding interface
dennwc Nov 16, 2019
ded9ba0
linkedql: minimize the accepted interface for DocumentIterator
dennwc Nov 16, 2019
ef2a6ae
linkedql: use the new type for Ref
dennwc Nov 16, 2019
4780abe
linkedql: refactor the schema package and rename the CLI command
dennwc Nov 16, 2019
1f93141
linkedql: fix comments formatting
dennwc Nov 16, 2019
3447b9b
linkedql: refactor value parsing
dennwc Nov 16, 2019
4bb71d1
linkedql: make the schema generator internal and refactor it
dennwc Nov 16, 2019
0e88e78
linkedql: refactor interfaces and fix panic in tests
dennwc Nov 16, 2019
1ee2b2c
linkedql: Implemented Entity and Entities and corrected parsing of IRIs
iddan Nov 29, 2019
2524b47
linkedql: Correct schema single range json output
iddan Nov 30, 2019
1e94a01
linkedql: Add missing descriptions
iddan Nov 30, 2019
bd6fc08
Add missing prefix to Placeholder type
iddan Nov 30, 2019
b8f3d5d
Remove ID from list in schema
iddan Nov 30, 2019
3196804
Streamline description text
iddan Dec 13, 2019
6de7636
WIP
iddan Dec 1, 2019
f52fd7d
Defined better API and loaded json schema to quad store
iddan Dec 1, 2019
6a5bf22
Start implementing OWL module and test it
iddan Dec 2, 2019
4d91af7
Complete OWL module
iddan Dec 6, 2019
f8de284
Make union properties work
iddan Dec 7, 2019
99a16a6
Correct list containing
iddan Dec 7, 2019
07f1d8a
Creating a basic file, types are still not correct
iddan Dec 7, 2019
cabf421
Remove old client files
iddan Dec 7, 2019
66f4059
Rename client2 to generate_client.go
iddan Dec 7, 2019
1b94148
Share identifier vars
iddan Dec 7, 2019
955474b
Correct value types
iddan Dec 7, 2019
4fcdb19
Correct slice types
iddan Dec 7, 2019
bc7a0c2
Don't use Path ptr
iddan Dec 7, 2019
de6e319
Correctly use path arguments
iddan Dec 7, 2019
f587953
Correct path creation
iddan Dec 7, 2019
8dc86b6
Share more string values
iddan Dec 7, 2019
27855cd
Change behaviour if doesn't have from
iddan Dec 7, 2019
0648a6b
Correct hasFrom
iddan Dec 7, 2019
ad41e1f
Add generate_client to gogen, remove gizmo codegen
iddan Dec 7, 2019
e890164
Rename path.go to client.go
iddan Dec 7, 2019
f8bd816
Move code generation script
iddan Dec 11, 2019
ebdc745
Update path in gogen.go
iddan Dec 11, 2019
ea4b9a0
Refactor code to be more navigatable and panic only on main
iddan Dec 13, 2019
6a55190
Generate comments
iddan Dec 13, 2019
b426cb4
linkedql: Add comment to path methods
iddan Dec 13, 2019
ce6c948
linkedql: add type assertion for final steps
iddan Dec 13, 2019
5b9cae0
linkedql: Correct step types in schema
iddan Dec 13, 2019
bf9dba6
linkedql: Correct emitted JSON-LD schema
iddan Dec 13, 2019
4bced0c
Merge branch 'feature/linkedql' into linkedql/client
iddan Dec 13, 2019
36b746a
linkedql: Correct type handling in client
iddan Dec 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/cayley/cayley.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func init() {
command.NewConvertCmd(),
command.NewDedupCommand(),
command.NewHealthCmd(),
command.NewSchemaCommand(),
)
rootCmd.PersistentFlags().StringP("config", "c", "", "path to an explicit configuration file")

Expand Down
42 changes: 42 additions & 0 deletions cmd/cayley/command/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package command

import (
"bytes"
"encoding/json"
"fmt"

"github.com/spf13/cobra"

"github.com/cayleygraph/cayley/internal/linkedql/schema"
)

func NewSchemaCommand() *cobra.Command {
root := &cobra.Command{
Use: "schema",
Short: "Commands related to RDF schema",
}
root.AddCommand(
NewLinkedQLSchemaCommand(),
)
return root
}

func NewLinkedQLSchemaCommand() *cobra.Command {
return &cobra.Command{
Use: "linkedql",
Short: "Generate LinkedQL Schema to stdout",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("too many arguments provided, expected 0")
}
data := schema.Generate()
buf := bytes.NewBuffer(nil)
err := json.Indent(buf, data, "", "\t")
if err != nil {
return err
}
fmt.Println(buf)
return nil
},
}
}
318 changes: 318 additions & 0 deletions cmd/generate_linkedql_client/generate_linkedql_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
package main

import (
"bufio"
"context"
"encoding/json"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/token"
"io"
"os"

"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/cayley/graph/memstore"
"github.com/cayleygraph/cayley/owl"
"github.com/cayleygraph/quad"
"github.com/cayleygraph/quad/jsonld"
"github.com/cayleygraph/quad/voc/rdfs"
)

const schemaFile = "linkedql.json"
const outputFilePath = "query/linkedql/client/client.go"

var stepIRI = quad.IRI("http://cayley.io/linkedql#Step")
var pathStepIRI = quad.IRI("http://cayley.io/linkedql#PathStep")
var iteratorStepIRI = quad.IRI("http://cayley.io/linkedql#IteratorStep")

func main() {
ctx := context.TODO()
qs, err := loadSchema()

if err != nil {
panic(err)
}

stepClass, err := owl.GetClass(ctx, qs, stepIRI)

if err != nil {
panic(err)
}

stepSubClasses := stepClass.SubClasses()
var decls []ast.Decl

for _, stepSubClass := range stepSubClasses {
if stepSubClass.Identifier == pathStepIRI || stepSubClass.Identifier == iteratorStepIRI {
continue
}
stepSubClassDecls, err := stepSubClassToDecls(stepSubClass)
if err != nil {
panic(err)
}
decls = append(decls, stepSubClassDecls...)
}

// Create a FileSet for node. Since the node does not come
// from a real source file, fset will be empty.
fset := token.NewFileSet()
file, err := getFile(fset)

if err != nil {
panic(err)
}

file.Decls = append(file.Decls, decls...)

err = writeFile(fset, file, outputFilePath)

if err != nil {
panic(err)
}
}

// loadSchema loads the schema file into an in-memory store
func loadSchema() (graph.QuadStore, error) {
jsonFile, err := os.Open(schemaFile)
if err != nil {
return nil, err
}
var o interface{}
qs := memstore.New()
json.NewDecoder(jsonFile).Decode(&o)
reader := jsonld.NewReaderFromMap(o)
for true {
quad, err := reader.ReadQuad()
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
qs.AddQuad(quad)
}
return qs, nil
}

var xsdString = quad.IRI("http://www.w3.org/2001/XMLSchema#string")
var rdfsResource = quad.IRI(rdfs.Resource).Full()
var stringIdent = ast.NewIdent("string")

var pathTypeIdent = ast.NewIdent("Path")
var pathIdent = ast.NewIdent("p")

func stepSubClassToDecls(stepSubClass *owl.Class) ([]ast.Decl, error) {
var decls []ast.Decl
hasFrom := false
iri, ok := stepSubClass.Identifier.(quad.IRI)
if !ok {
return nil, fmt.Errorf("Unexpected class identifier %v of type %T", stepSubClass.Identifier, stepSubClass.Identifier)
}
properties := stepSubClass.Properties()

var paramsList []*ast.Field
for _, property := range properties {
_type, err := propertyToValueType(stepSubClass, property)
if err != nil {
return nil, err
}
ident := iriToIdent(property.Identifier)
if ident.Name == "from" {
hasFrom = true
continue
}
paramsList = append(paramsList, &ast.Field{
Names: []*ast.Ident{ident},
Type: _type,
})
}
elts := []ast.Expr{
&ast.KeyValueExpr{
Key: &ast.BasicLit{
Kind: token.STRING,
Value: "\"@type\"",
},
Value: &ast.BasicLit{
Kind: token.STRING,
Value: "\"" + string(iri) + "\"",
},
},
}
if hasFrom {
elts = append(elts, &ast.KeyValueExpr{
Key: &ast.BasicLit{
Kind: token.STRING,
Value: "\"from\"",
},
Value: pathIdent,
})
}

for _, property := range properties {
ident := iriToIdent(property.Identifier)
if ident.Name == "from" {
continue
}
var value ast.Expr
value = iriToIdent(property.Identifier)
elts = append(elts, &ast.KeyValueExpr{
Key: &ast.BasicLit{
Kind: token.STRING,
Value: "\"" + string(property.Identifier) + "\"",
},
Value: value,
})
}

var recv *ast.FieldList

if hasFrom {
recv = &ast.FieldList{
List: []*ast.Field{
&ast.Field{
Names: []*ast.Ident{pathIdent},
Type: pathTypeIdent,
},
},
}
}

comment, err := stepSubClass.Comment()

var doc *ast.CommentGroup

if err == nil {
doc = &ast.CommentGroup{
List: []*ast.Comment{
{
Text: "// " + iriToStringIdent(iri) + " " + comment,
},
},
}
}

decls = append(decls, &ast.FuncDecl{
Name: iriToIdent(iri),
Doc: doc,
Type: &ast.FuncType{
Params: &ast.FieldList{List: paramsList},
Results: &ast.FieldList{
List: []*ast.Field{
&ast.Field{
Names: nil,
Type: pathTypeIdent,
},
},
},
},
Recv: recv,
Body: &ast.BlockStmt{
List: []ast.Stmt{
&ast.ReturnStmt{
Results: []ast.Expr{
&ast.CompositeLit{
Type: pathTypeIdent,
Elts: elts,
},
},
},
},
},
})
return decls, nil
}

var quadValueType = &ast.SelectorExpr{
Sel: ast.NewIdent("Value"),
X: ast.NewIdent("quad"),
}

func propertyToValueType(class *owl.Class, property *owl.Property) (ast.Expr, error) {
_range, err := property.Range()
if err != nil {
return nil, err
}
isSlice := true
isPTR := false
cardinality, err := class.CardinalityOf(property)
if cardinality == int64(1) {
isSlice = false
isPTR = false
}
maxCardinality, err := class.MaxCardinalityOf(property)
if maxCardinality == int64(1) {
isSlice = false
isPTR = true
}
var t ast.Expr
if _range == xsdString {
t = stringIdent
} else if _range == pathStepIRI {
t = pathTypeIdent
} else if _range == rdfsResource {
t = quadValueType
} else {
return nil, fmt.Errorf("Unexpected range %v", _range)
}
if isPTR {
t = &ast.StarExpr{
X: t,
}
}
if isSlice {
t = &ast.ArrayType{
Elt: t,
}
}
return t, nil
}

func getFile(fset *token.FileSet) (*ast.File, error) {
src := `
package client

import (
"github.com/cayleygraph/quad"
)

type Path map[string]interface{}
`
file, err := parser.ParseFile(fset, "", src, 0)

if err != nil {
return nil, err
}

return file, nil
}

// writeFile writes given file of given fset to given path
func writeFile(fset *token.FileSet, file *ast.File, path string) error {
f, err := os.Create(path)

if err != nil {
return err
}

w := bufio.NewWriter(f)

err = format.Node(w, fset, file)

if err != nil {
return err
}

w.Flush()
f.Close()

return nil
}

func iriToStringIdent(iri quad.IRI) string {
return string(iri)[26:]
}

func iriToIdent(iri quad.IRI) *ast.Ident {
return ast.NewIdent(iriToStringIdent(iri))
}
2 changes: 1 addition & 1 deletion gogen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cayley

//go:generate go run ./cmd/docgen/docgen.go -i ./docs/GizmoAPI.md.in -o ./docs/GizmoAPI.md
//go:generate go run ./cmd/generate_linkedql_client/generate_linkedql_client.go
Loading