Comments (3)
An RDF Term is an interface, it can be either URI, Literal or Blank node.
If you know it's an Literal, you can type cast it to rdf.Literal and access it's datatype and value (as a string).
package main
import (
"bytes"
"fmt"
"io"
"log"
"github.com/knakk/rdf"
)
const nt = `
<http://localhost/person/me> <http://localhost/birthYear> "1981"^^<http://www.w3.org/2001/XMLSchema#gYear> .
<http://localhost/pi> <http://localhost/size> "3.14"^^<http://www.w3.org/2001/XMLSchema#float> .
<http://localhost/house> <http://localhost/hasNumber> "123"^^<http://www.w3.org/2001/XMLSchema#integer> .
`
func main() {
dec := rdf.NewTripleDecoder(bytes.NewBufferString(nt), rdf.NTriples)
for tr, err := dec.Decode(); err != io.EOF; tr, err = dec.Decode() {
if err != nil {
log.Fatal(err)
}
if tr.Obj.Type() == rdf.TermLiteral {
obj := tr.Obj.(rdf.Literal)
fmt.Printf("Object value: %q\tObject datatype: %s\n", obj.String(), obj.DataType)
}
}
}
from rdf.
Awesome, thanks for the quick reply and code example!
// Cheers
from rdf.
Welcome:)
from rdf.
Related Issues (18)
- Decoders: better error handling on malformed input
- No license information
- Doesn't serialize to N-Quads HOT 5
- '_' may appear in turtle local names HOT 1
- Don't strip xsd type for xsd:integer in turtle serialization HOT 3
- Any plans for RDF/XML support in TripleEncoder? HOT 1
- allowing naming the prefixes/namespaces for turtle export HOT 6
- fails decoding a turtle rdf with just namespace and no id HOT 3
- Add support for more literal type formats
- Add a real license? HOT 3
- Custom namespace functionality not working HOT 2
- JSON-LD support HOT 7
- Request to standardize license
- License
- Lack of documentation + full example HOT 1
- Question: how to convert a TTL file to Golang structs? HOT 1
- How to customize prefixes? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rdf.