Skip to content

An example of using the Serd RDF parsing library in Swift

Notifications You must be signed in to change notification settings

crspybits/serd-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

serd-parser

This is an example project to show the use of the Serd RDF library to parse N-Triples data in Swift.

From the command line:

% swift build
% ./.build/debug/serd-parse foaf.ttl
<http://kasei.us/about/#greg> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
<http://kasei.us/about/#greg> <http://xmlns.com/foaf/0.1/name> "Gregory Todd Williams" .
<http://kasei.us/about/#greg> <http://xmlns.com/foaf/0.1/nick> "kasei" .
<http://kasei.us/about/#greg> <http://xmlns.com/foaf/0.1/mbox> <mailto://greg@evilfunhouse.com> .
<http://kasei.us/about/#greg> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "f80a0f19d2a0897b89f48647b2fb5ca1f0bc1cb8" .
<http://kasei.us/about/#greg> <http://xmlns.com/foaf/0.1/homepage> <http://kasei.us/> .
<http://kasei.us/about/#greg> <http://xmlns.com/foaf/0.1/img> <http://kasei.us/images/greg.png> .
...

Or, programatically:

import SerdParser

// extract all foaf:name triples
let parser = SerdParser()
let count = try parser.parse(file: filename) { (s, p, o) in
    if case .iri("http://xmlns.com/foaf/0.1/name") = p {
        print("\(s) has name \(o) .")
    }
}
print("\(count) triples processed")

About

An example of using the Serd RDF parsing library in Swift

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%