deiu / rdf2go Goto Github PK
View Code? Open in Web Editor NEWNative golang library for RDF (includes parser/serializer for Turtle and JSON-LD)
License: MIT License
Native golang library for RDF (includes parser/serializer for Turtle and JSON-LD)
License: MIT License
For example:
rdf
is the prefix for <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Therefore, in the .ttl file we should write:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
...
ont:TACTIC rdf:type owl:Class ;
neo4voc:name "TACTIC" .
ont:CustomId rdf:type owl:DatatypeProperty ;
neo4voc:name "CustomId" .
I'm a happy user of this library but we get occasional errors from the Go runtime's 'concurrent map misuse detector' which makes the program crash: https://go.dev/doc/go1.6#runtime
I believe IterTriples() needs to be changed to avoid this error, e.g. by adding a lock:
Line 107 in c39eb29
You may also need to use this same lock inside the reader methods.
Alternatively you could avoid creating a goroutine inside IterTriples().
So I am seeing if I can read a VoID doc in turtle. All is going very well till I try to look for triples based on a # IRI.
When I try and do this line (full code ref below)
vds.DownloadURL = getObject(g, triples[triple].Subject, rdf2go.NewResource("http://www.w3.org/ns/dcat#downloadURL"))
It doesn't work since of course everything after # is effectively ignored which is of course correct in many cases. Still, in SPARQL I can set up a query and use a prefix that has a #'s base.
Is there a way to conduct a search in rdf2go with IRIs that have the # structure like in https://github.com/OpenCoreData/ocdGarden/blob/master/GraphUtils/VOIDReader/void.ttl
Code Ref: https://github.com/OpenCoreData/ocdGarden/blob/master/GraphUtils/VOIDReader/main.go
Hello,
There's a problem (bug) in the current library code regarding the escpaction of special characters.
I'm trying to parse a RDF literal (string) which has dobule slash: "aaa\\bbb"
.
As a result of that, an exception is being thrown: panic: strconv.ParseInt: parsing "ser": invalid syntax
Program's code:
package main
import (
"github.com/deiu/rdf2go"
"log"
"os"
)
func main() {
if err := convertTtlToJsonLd(); err != nil {
log.Fatalln(err)
}
}
func convertTtlToJsonLd() error {
r, _ := os.OpenFile("test.ttl", os.O_CREATE|os.O_RDONLY, 0664)
w, _ := os.OpenFile("test.json", os.O_CREATE|os.O_WRONLY, 0644)
g := rdf2go.NewGraph("https://oxfordsemantic.tech/RDFox/getting-started/")
if err := g.Parse(r, "text/turtle"); err != nil {
return err
}
return g.Serialize(w, "application/ld+json")
}
RDF (Turtle) file - test.ttl
:
@prefix : <https://oxfordsemantic.tech/RDFox/getting-started/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfox: <http://oxfordsemantic.tech/RDFox#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix swrl: <http://www.w3.org/2003/11/swrl#> .
@prefix swrlb: <http://www.w3.org/2003/11/swrlb#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
:Username :Asset_account :Account_159 ;
:Str_username "w10apps01\\user" ;
rdf:type :Username .
Exception being thrown:
panic: strconv.ParseInt: parsing "ser": invalid syntax
goroutine 1 [running]:
github.com/deiu/gon3.unescapeUChar({0xc0001c41f0?, 0x12a0120?})
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/rdf.go:208 +0x2be
github.com/deiu/gon3.lexicalForm({0xc0001c41ef, 0x11})
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/rdf.go:155 +0xd2
github.com/deiu/gon3.(*Parser).parseRDFLiteral(0xc000129e68?)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:560 +0x7e
github.com/deiu/gon3.(*Parser).parseLiteral(0xc000129e68?)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:508 +0x5e
github.com/deiu/gon3.(*Parser).parseObject(0xc000129e68)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:469 +0x9c5
github.com/deiu/gon3.(*Parser).parseObjectList(0xc000129e68?)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:381 +0x25
github.com/deiu/gon3.(*Parser).parsePredicateObjectList(0xc000129e68?)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:344 +0xa9
github.com/deiu/gon3.(*Parser).parseTriples(0xc000129e68)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:273 +0xb8
github.com/deiu/gon3.(*Parser).parseStatement(0x1343660?)
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:168 +0x105
github.com/deiu/gon3.(*Parser).Parse(0xc000129e68, {0x1343660?, 0xc000010230?})
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/parser.go:51 +0x11b
github.com/deiu/rdf2go.(*Graph).Parse(0xc00007dc50, {0x1343660, 0xc000010230}, {0x12c8083?, 0x300000002?})
/Users/bora/go/pkg/mod/github.com/deiu/[email protected]/graph.go:201 +0x2f7
main.convertTtlToJsonLd()
/Users/bora/converter/main.go:19 +0x1c7
main.main()
/Users/bora/converter/main.go:10 +0x19
Process finished with the exit code 2
Hello,
I have read this Paper and it mentioned the usage of rdf2go with Semantic Mediawiki (SMW). I came to your repository, hoping for some example or some demo that can show how one can make it work with SMW.
I am looking forward to getting any help from you regarding the rdf2go integration with SMW!
Thanks.
Reference:
https://github.com/OpenCoreData/ocdGarden/blob/master/JSON-goLD/rdf2goTesting/main.go
Taking a JSON-LD document that contains blank nodes results in an error where all blank nodes get the same ID.
Expect something like
_:b0 <http://schema.org/description> "The Empire State Building is a 102-story landmark in New York City." .
_:b0 <http://schema.org/geo> _:b1 .
_:b0 <http://schema.org/image> <http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg> .
_:b0 <http://schema.org/name> "The Empire State Building" .
_:b1 <http://schema.org/latitude> "40.75"^^<http://www.w3.org/2001/XMLSchema#float> .
_:b1 <http://schema.org/longitude> "73.98"^^<http://www.w3.org/2001/XMLSchema#float> .
Get
_:n0 <http://schema.org/description> "The Empire State Building is a 102-story landmark in New York City."^^<http://www.w3.org/2001/XMLSchema#string> .
_:n0 <http://schema.org/geo> _:n0 .
_:n0 <http://schema.org/image> <http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg> .
_:n0 <http://schema.org/name> "The Empire State Building"^^<http://www.w3.org/2001/XMLSchema#string> .
_:n0 <http://schema.org/latitude> "40.75"^^<http://www.w3.org/2001/XMLSchema#float> .
_:n0 <http://schema.org/longitude> "73.98"^^<http://www.w3.org/2001/XMLSchema#float> .
Note the geo line at row 2 in both outputs.
The rightmost blank node can not be _:n0 again.
Also, curious if I load multiple JSON-LD documents into a single graph if the blank nodes will be unique so that subsequent JSON-LD documents don't deserialize with conflicting blank node IDs.
I'm able to convert TTL file to a JSON-LD format. Note, the conversion is not perfect because it lacks of @Context
metadata. I compared the output using this repo vs online converters.
But how can I convert from JSON-LD to an a Golang structs? Or even better, can I convert straight from RDF TTL to Golang struct?
Hi, thanks for your great library. Recently I encountered an error parsing turtle with booleans in it. Here is an example to reproduce:
package main
import (
"fmt"
"strings"
"github.com/deiu/rdf2go"
)
func main() {
g := rdf2go.NewGraph("")
if err := g.Parse(strings.NewReader(`<s> <p> [ <o> true; <other> <triple> ] .`), "text/turtle"); err != nil {
panic(err)
}
fmt.Println(g)
}
This results in:
panic: Expected object, got Expected ':' while lexing pname%!(EXTRA []interface {}=[]) (type %!s(easylex.TokenType=-2))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.