summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2020-09-03 13:41:11 +0200
committerpukkamustard <pukkamustard@posteo.net>2020-09-03 13:46:44 +0200
commit9fa92884d020ece6030056c9ecd46b65da4833fb (patch)
tree8fba77306b559ed6515d2751dce7b7d0b2ee6530
parent6c603605aad1bab3f6bb274f56fdba023c724639 (diff)
(schemantic rdf lang-string): add datatype for rdf:langString
-rw-r--r--README.org2
-rw-r--r--schemantic/iri.scm3
-rw-r--r--schemantic/literal.scm9
-rw-r--r--schemantic/rdf.scm5
-rw-r--r--schemantic/rdf/lang-string.scm25
-rw-r--r--schemantic/xsd.scm2
-rw-r--r--tests/schemantic/literal.scm22
7 files changed, 63 insertions, 5 deletions
diff --git a/README.org b/README.org
index 10d687b..7b991db 100644
--- a/README.org
+++ b/README.org
@@ -15,7 +15,7 @@ An Elixir RDF library from which we take much inspiration.
** [[https://github.com/cordawyn/schemantic-web][Schemantic Web]]
-A collection of tools related to the Semantic Web for Scheme48 (mostly portable).
+A collection of tools related to the Semantic Web for Scheme48 (mostly portable). We stole the cool name from them...
** [[https://framagit.org/tyreunom/guile-rdf][Guile RDF]]
diff --git a/schemantic/iri.scm b/schemantic/iri.scm
index 54cb5e5..c8580dd 100644
--- a/schemantic/iri.scm
+++ b/schemantic/iri.scm
@@ -23,6 +23,9 @@
(define-method (equal? (x <iri>) (y <iri>))
(equal? (iri-value x) (iri-value y)))
+(define-method (write (self <iri>) port)
+ (format port "<iri ~a>" (iri-value self)))
+
(define-generic make-iri)
(define-method (make-iri (s <string>)) (make <iri> #:value s))
(define-method (make-iri (iri <iri>)) iri)
diff --git a/schemantic/literal.scm b/schemantic/literal.scm
index 617f732..cbac7fc 100644
--- a/schemantic/literal.scm
+++ b/schemantic/literal.scm
@@ -14,11 +14,15 @@
literal-value
literal-lexical
literal-canonical
- literal-datatype))
+ literal-datatype
+ literal-language))
(define-class <literal> ()
(value #:init-keyword #:value #:getter literal-value))
+(define-method (write (self <literal>) port)
+ (format port "<literal ~a ~a>" (literal-value self) (literal-datatype self)))
+
(define (literal? x)
(is-a? x <literal>))
@@ -28,6 +32,9 @@
(define-generic literal-lexical)
(define-generic literal-canonical)
(define-generic literal-datatype)
+(define-generic literal-language)
+
+(define-method (literal-language (l <literal>)) #f)
;; Generic literal
diff --git a/schemantic/rdf.scm b/schemantic/rdf.scm
index ededcd5..cee9fb6 100644
--- a/schemantic/rdf.scm
+++ b/schemantic/rdf.scm
@@ -4,11 +4,11 @@
(define-module (schemantic rdf)
#:use-module (oop goops)
- #:use-module (oop goops describe) ; only for dev/debug
#:use-module (schemantic iri)
#:use-module (schemantic literal)
#:use-module (schemantic xsd)
+ #:use-module (schemantic rdf lang-string)
#:export (<triple>
make-triple
@@ -30,7 +30,8 @@
literal-value
literal-lexical
literal-canonical
- literal-datatype))
+ literal-datatype
+ literal-language))
;; Triple
diff --git a/schemantic/rdf/lang-string.scm b/schemantic/rdf/lang-string.scm
new file mode 100644
index 0000000..7468a40
--- /dev/null
+++ b/schemantic/rdf/lang-string.scm
@@ -0,0 +1,25 @@
+; SPDX-FileCopyrightText: 2020 pukkamustard <pukkamustard@posteo.net>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+(define-module (schemantic rdf lang-string)
+ #:use-module (oop goops)
+
+ #:use-module (schemantic literal)
+ #:use-module ((schemantic ns) #:select (rdf))
+
+ #:export (<rdf:langString>
+ make-lang-string))
+
+(define-class <rdf:langString> (<literal>)
+ (language #:init-keyword #:language #:getter literal-language))
+
+(define-method (literal-datatype (l <rdf:langString>)) (rdf "langString"))
+
+(define* (make-lang-string value #:key language)
+ (make <rdf:langString> #:value value #:language language))
+
+(define-method (write (self <literal>) port)
+ (format port "<rdf:langString \"~a\"@~a>" (literal-value self) (literal-language self)))
+
+(make-lang-string "hello" #:language "en")
diff --git a/schemantic/xsd.scm b/schemantic/xsd.scm
index ecc3bf2..bbef832 100644
--- a/schemantic/xsd.scm
+++ b/schemantic/xsd.scm
@@ -16,12 +16,14 @@
(define-method (literal-lexical (x <xsd:string>)) (literal-value x))
(define-method (literal-canonical (x <xsd:string>)) (literal-value x))
(define-method (literal-datatype (x <xsd:string>)) (xsd "string"))
+(define-method (write (self <xsd:string>) port) (format port "<xsd:string ~a>" (literal-value self)))
(define-method (make-literal (s <string>)) (make <xsd:string> #:value s))
(define-class <xsd:integer> (<literal>))
(define-method (literal-lexical (x <xsd:integer>)) (number->string (literal-value x)))
(define-method (literal-canonical (x <xsd:integer>)) (number->string (literal-value x)))
(define-method (literal-datatype (x <xsd:integer>)) (xsd "integer"))
+(define-method (write (self <xsd:integer>) port) (format port "<xsd:integer ~a>" (literal-value self)))
(define-method (make-literal (s <integer>)) (make <xsd:integer> #:value s))
;; TODO add the other XSD datatypes
diff --git a/tests/schemantic/literal.scm b/tests/schemantic/literal.scm
index 486ca08..36219b1 100644
--- a/tests/schemantic/literal.scm
+++ b/tests/schemantic/literal.scm
@@ -5,8 +5,9 @@
(define-module (tests schemantic literal)
#:use-module (oop goops)
#:use-module (schemantic rdf)
+ #:use-module (schemantic rdf lang-string)
#:use-module (schemantic xsd)
- #:use-module ((schemantic ns) #:select (xsd))
+ #:use-module ((schemantic ns) #:select (rdf xsd))
#:use-module (srfi srfi-64))
@@ -25,6 +26,25 @@
(test-end "generic literal")
+(test-begin "rdf:langString")
+
+(test-assert "rdf:langString is a literal"
+ (literal? (make-lang-string "hello" #:language "en")))
+
+(test-equal "datatype is rdf:langString"
+ (rdf "langString")
+ (literal-datatype (make-lang-string "hello" #:language "en")))
+
+(test-equal "value is string"
+ "hello"
+ (literal-value (make-lang-string "hello" #:language "en")))
+
+(test-equal "language can be refed"
+ "en"
+ (literal-language (make-lang-string "hello" #:language "en")))
+
+(test-end "rdf:langString")
+
(test-begin "xsd:string")
(test-assert "string is cast to a literal"