RDF triples are the interlingua for knowledge graphs on the Semantic Web.
subject relation object.
The nodes become subjects and objects. The edges become relations. Unlike JSON-LD, everything is simple strings. No nested structures.
Read Section 3.1 (only) of the W3C overview of triples.
RDF | Lisp |
---|---|
prefix : <http://example#> :john :knows :karen ; :name "John" . :karen :knows :alex ; :name "Karen" . :alex :name "Alex" . |
(setq *facts* '( (john knows karen) (john name "john") (karen knows alex) (karen name "karen") (alex name "Alex"))) |
RDF very simplified here. More later.
SPARQL is the World Wide Web Consortium (W3C) standard query language for RDF triples. Inspired by SQL.
Read RDF and Querying. Stop when you get to Verbs and variables
SPARQL | Lisp |
---|---|
SELECT ?name WHERE { ?x :knows ?y . ?y :name ?name . } |
(graph-search '( (?x knows ?y) (?y name ?name) )) |
Retrieve all subsets of triples that match all the patterns.
(defun graph-search (queries &optional (blists (list nil))) (do ((blists blists (query-search (car queries) blists)) (queries queries (cdr queries))) ((or (null blists) (null queries)) blists))) (defun query-search (query &optional (blists (list nil))) (if (null blists) nil (mapcan (lambda (triple) (match-p query triple blists)) *triples*)))