Add filter, add READMES
This commit is contained in:
34
backend_go/graph_queries/default.go
Normal file
34
backend_go/graph_queries/default.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package graph_queries
|
||||
|
||||
import "fmt"
|
||||
|
||||
func defaultEdgeQuery(edgeLimit int, includeBNodes bool) string {
|
||||
bnodeFilter := ""
|
||||
if !includeBNodes {
|
||||
bnodeFilter = "FILTER(!isBlank(?s) && !isBlank(?o))"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`
|
||||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
|
||||
SELECT ?s ?p ?o
|
||||
WHERE {
|
||||
{
|
||||
VALUES ?p { rdf:type }
|
||||
?s ?p ?o .
|
||||
?o rdf:type owl:Class .
|
||||
}
|
||||
UNION
|
||||
{
|
||||
VALUES ?p { rdfs:subClassOf }
|
||||
?s ?p ?o .
|
||||
}
|
||||
FILTER(!isLiteral(?o))
|
||||
%s
|
||||
}
|
||||
LIMIT %d
|
||||
`, bnodeFilter, edgeLimit)
|
||||
}
|
||||
|
||||
24
backend_go/graph_queries/hierarchy.go
Normal file
24
backend_go/graph_queries/hierarchy.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package graph_queries
|
||||
|
||||
import "fmt"
|
||||
|
||||
func hierarchyEdgeQuery(edgeLimit int, includeBNodes bool) string {
|
||||
bnodeFilter := ""
|
||||
if !includeBNodes {
|
||||
bnodeFilter = "FILTER(!isBlank(?s) && !isBlank(?o))"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
|
||||
SELECT ?s ?p ?o
|
||||
WHERE {
|
||||
VALUES ?p { rdfs:subClassOf }
|
||||
?s ?p ?o .
|
||||
FILTER(!isLiteral(?o))
|
||||
%s
|
||||
}
|
||||
LIMIT %d
|
||||
`, bnodeFilter, edgeLimit)
|
||||
}
|
||||
|
||||
27
backend_go/graph_queries/registry.go
Normal file
27
backend_go/graph_queries/registry.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package graph_queries
|
||||
|
||||
const DefaultID = "default"
|
||||
|
||||
var definitions = []Definition{
|
||||
{Meta: Meta{ID: DefaultID, Label: "Default"}, EdgeQuery: defaultEdgeQuery},
|
||||
{Meta: Meta{ID: "hierarchy", Label: "Hierarchy"}, EdgeQuery: hierarchyEdgeQuery},
|
||||
{Meta: Meta{ID: "types", Label: "Types"}, EdgeQuery: typesOnlyEdgeQuery},
|
||||
}
|
||||
|
||||
func List() []Meta {
|
||||
out := make([]Meta, 0, len(definitions))
|
||||
for _, d := range definitions {
|
||||
out = append(out, d.Meta)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func Get(id string) (Definition, bool) {
|
||||
for _, d := range definitions {
|
||||
if d.Meta.ID == id {
|
||||
return d, true
|
||||
}
|
||||
}
|
||||
return Definition{}, false
|
||||
}
|
||||
|
||||
12
backend_go/graph_queries/types.go
Normal file
12
backend_go/graph_queries/types.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package graph_queries
|
||||
|
||||
type Meta struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
type Definition struct {
|
||||
Meta Meta
|
||||
EdgeQuery func(edgeLimit int, includeBNodes bool) string
|
||||
}
|
||||
|
||||
26
backend_go/graph_queries/types_only.go
Normal file
26
backend_go/graph_queries/types_only.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package graph_queries
|
||||
|
||||
import "fmt"
|
||||
|
||||
func typesOnlyEdgeQuery(edgeLimit int, includeBNodes bool) string {
|
||||
bnodeFilter := ""
|
||||
if !includeBNodes {
|
||||
bnodeFilter = "FILTER(!isBlank(?s) && !isBlank(?o))"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`
|
||||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
|
||||
SELECT ?s ?p ?o
|
||||
WHERE {
|
||||
VALUES ?p { rdf:type }
|
||||
?s ?p ?o .
|
||||
?o rdf:type owl:Class .
|
||||
FILTER(!isLiteral(?o))
|
||||
%s
|
||||
}
|
||||
LIMIT %d
|
||||
`, bnodeFilter, edgeLimit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user