Giter Site home page Giter Site logo

callidon / joseki Goto Github PK

View Code? Open in Web Editor NEW
33.0 5.0 2.0 162 KB

Pure Go library for working with RDF, a powerful framework for representing informations as graphs.

License: MIT License

Go 99.71% Shell 0.29%
rdf rdflib rdf-graphs turtle n-triples graph

joseki's Introduction

joseki license GoDoc Build Status Coverage Status

Joseki is a pure Go library for working with RDF, a powerful framework for representing informations as graphs.

For more informations about RDF itself, please see https://www.w3.org/TR/rdf11-concepts

Features

Joseki provides the following features to work with RDF :

  • Structures to represent and manipulate the RDF model (URIs, Literals, Blank Nodes, Triples, etc)
  • RDF Graphs to store data, with several implentations provided.
  • A Low level API to query data stored in graphs.
  • A High level API to query data using the SPARQL 1.1 query language. (WIP - Unstable)
  • Query processing using modern techniques such as join ordering or optimized query execution plans.
  • Load RDF data stored in files in various formats (N-Triples, Turtle, etc) into any graph.

Getting Started

This package aims to work with RDF graphs, which are composed of RDF Triple {Subject Object Predicate}. Using joseki, you can represent an RDF Triple as followed :

import (
    "github.com/Callidon/joseki/rdf"
    "fmt"
)
subject := rdf.NewURI("http://example.org/book/book1")
predicate := rdf.NewURI("http://purl.org/dc/terms/title")
object := rdf.NewLiteral("Harry Potter and the Order of the Phoenix")
triple := rdf.NewTriple(subject, predicate, object)
fmt.Println(triple)
// Output : {<http://example.org/book/book1> <http://purl.org/dc/terms/title> "Harry Potter and the Order of the Phoenix"}

You can also store your RDF Triples in a RDF Graph, using various type of graphs. Here, we use a Tree Graph to store our triple :

import (
    "github.com/Callidon/joseki/rdf"
    "github.com/Callidon/joseki/graph"
)
subject := rdf.NewURI("http://example.org/book/book1")
predicate := rdf.NewURI("http://purl.org/dc/terms/title")
object := rdf.NewLiteral("Harry Potter and the Order of the Phoenix")
graph := graph.NewTreeGraph()
graph.Add(rdf.NewTriple(subject, predicate, object))

You can also query any triple from a RDF Graph, using a low level API or a SPARQL query.

import (
    "github.com/Callidon/joseki/rdf"
    "github.com/Callidon/joseki/graph"
    "fmt"
)
graph := graph.NewTreeGraph()
// Datas stored in a file can be easily loaded into a graph
graph.LoadFromFile("datas/awesome-books.ttl", "turtle")
// Let's fetch the titles of all the books in our graph !
subject := rdf.NewVariable("title")
predicate := rdf.NewURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
object := rdf.NewURI("https://schema.org/Book")
for bindings := range graph.Filter(subject, predicate, object) {
    fmt.Println(bindings)
}

For more informations about specific features, see the documentation

joseki's People

Contributors

callidon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

samuell afduarte

joseki's Issues

Convert RDF to a Golang struct

Does this project enables to convert a rdf turtle (TTL file format) to a Golang struct?
I.e. marshal & unmarshal to/from TTL/struct.

Nested select queries return 400 error

Posting the following query to the http://data.linkedmdb.org/sparql endpoint returns a 400 error.

select ?label ?n {
  {
    select ?p (count(?o) as ?n) {
      ?s ?p ?o .
    }
    group by ?s
  }
  bind (replace(str(?s), ".*\\/", "") as ?label)
  filter (?n > 1000)
}
order by ?p

A curl request would look like this:

curl http://data.linkedmdb.org/sparql -X POST --data 'query=select+%3Flabel+%3Fn+%7B%0A++%7B%0A++++select+%3Fp+(count(%3Fs)+as+%3Fn)+%7B%0A++++++%3Fs+%3Fp+%3Fo+.%0A++++%7D%0A++++group+by+%3Fp%0A++%7D%0A++bind+(replace(str(%3Fp)%2C+%22.*%5C%5C%2F%22%2C+%22%22)+as+%3Flabel)%0A++filter+(%3Fn+%3E+1000)%0A%7D%0Aorder+by+%3Fp' -H 'Accept: application/sparql-results+json'

Expected outcome:

The endpoint returns a histogram of predicates, filtered to show only predicates that occur more than 1000 times.

Actual outcome:

The endpoint returns a 400 error with the following headers.

> POST /sparql HTTP/1.1
> Host: data.linkedmdb.org
> User-Agent: curl/7.55.1
> Accept: application/sparql-results+json
> Content-Length: 267
> Content-Type: application/x-www-form-urlencoded
>
} [267 bytes data]
* upload completely sent off: 267 out of 267 bytes
100   267    0     0  100   267      0    267  0:00:01 --:--:--  0:00:01  1265< HTTP/1.1 400 Parse_error__select_label_n_________select_p_counts_as_n________s_p_o___________group_by_p______bind_replacestrp___as_label___filter_n__1000__order_by_p__Encountered_select_at_line_3_column_5_Was_expecting_one_of_____IRIref______PNAME_NS______PNAME_LN______BLANK_NODE_LABEL______VAR1______VAR2______graph______optional______service______filter______true______false______INTEGER______DECIMAL______DOUBLE______INTEGER_POSITIVE______DECIMAL_POSITIVE______DOUBLE_POSITIVE______INTEGER_NEGATIVE______DECIMAL_NEGATIVE______DOUBLE_NEGATIVE______STRING_LITERAL1______STRING_LITERAL2______STRING_LITERAL_LONG1______STRING_LITERAL_LONG2____________NIL________________________ANON______
< Date: Tue, 17 Apr 2018 11:55:02 GMT
< Server: Jetty(6.1.4)
< Pragma: no-cache
< X-Joseki-Server: Joseki-3.0-dev
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 2387
< Connection: close

To the best of my knowledge, the query is correct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.