summaryrefslogtreecommitdiff
path: root/schemantic
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2020-09-03 11:43:54 +0200
committerpukkamustard <pukkamustard@posteo.net>2020-09-03 11:43:54 +0200
commit4c2f6d772967c70109ac64031e26fb6d716ec133 (patch)
tree26be83145729f5adefbff3778bdc00f255f01add /schemantic
initial commit
Diffstat (limited to 'schemantic')
-rw-r--r--schemantic/ns.scm12
-rw-r--r--schemantic/rdf.scm95
2 files changed, 107 insertions, 0 deletions
diff --git a/schemantic/ns.scm b/schemantic/ns.scm
new file mode 100644
index 0000000..e84636a
--- /dev/null
+++ b/schemantic/ns.scm
@@ -0,0 +1,12 @@
+; SPDX-FileCopyrightText: 2020 pukkamustard <pukkamustard@posteo.net>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+(define-module (schemantic ns)
+ #:use-module (schemantic rdf)
+ #:export (rdf rdfs owl xsd))
+
+(define-namespace rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+(define-namespace rdfs "http://www.w3.org/2000/01/rdf-schema#")
+(define-namespace owl "http://www.w3.org/2002/07/owl#")
+(define-namespace xsd "http://www.w3.org/2001/XMLSchema#")
diff --git a/schemantic/rdf.scm b/schemantic/rdf.scm
new file mode 100644
index 0000000..68329a7
--- /dev/null
+++ b/schemantic/rdf.scm
@@ -0,0 +1,95 @@
+; SPDX-FileCopyrightText: 2020 pukkamustard <pukkamustard@posteo.net>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+(define-module (schemantic rdf)
+ #:use-module (oop goops)
+
+ #:use-module (oop goops describe) ; only for dev/debug
+
+ #:use-module (web uri)
+ #:use-module (ice-9 optargs)
+ #:use-module (ice-9 exceptions)
+
+ #:export (<iri>
+ make-iri
+ iri?
+ iri-value
+
+ <literal>
+ literal?
+ literal-value
+ literal-lexical
+ literal-canonical
+ literal-datatype
+
+ <triple>
+ make-triple
+ triple?
+ triple-subject
+ triple-predicate
+ triple-object
+
+ define-namespace))
+
+;; IRI
+
+(define-class <iri> ()
+ (value #:init-keyword #:value #:getter iri-value))
+
+(define-method (initialize (self <iri>) initargs)
+ (let-keywords initargs #f (value)
+ (cond
+ ((string? value) (next-method self (list #:value value)))
+ ((uri? value) (next-method self (list #:value (uri->string value))))
+ ((iri? value) (next-method self (list #:value (iri-value value))))
+ (else (raise-exception
+ (make-exception
+ (make-programming-error)
+ (make-exception-with-message "can not cast to iri")))))))
+
+(define-method (equal? (x <iri>) (y <iri>))
+ (equal? (iri-value x) (iri-value y)))
+
+(define (make-iri value)
+ "Returns a new iri with value"
+ (make <iri> #:value value))
+
+(define (iri? x)
+ "Returns true if x is an iri"
+ (is-a? x <iri>))
+
+;; Literal
+
+(define-class <literal> ())
+
+(define (literal? x)
+ (is-a? x <literal>))
+
+(define-generic literal-value)
+(define-generic literal-lexical)
+(define-generic literal-canonical)
+(define-generic literal-datatype)
+
+
+;; Triple
+
+(define-class <triple> ()
+ (subject #:init-keyword #:s #:getter triple-subject)
+ (predicate #:init-keyword #:p #:getter triple-predicate)
+ (object #:init-keyword '#:o #:getter triple-object))
+
+(define-method (initialize (t <triple>) initargs)
+ (next-method))
+
+(define (make-triple s p o)
+ (make <triple> #:s s #:p p #:o o))
+
+(define (triple? x)
+ (is-a? x <triple>))
+
+;; Syntax for defining new namespace
+
+(define-syntax-rule (define-namespace name uri)
+ (define (name id)
+ (make-iri (string-append uri id))))