summaryrefslogtreecommitdiff
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
initial commit
-rw-r--r--.gitignore65
-rw-r--r--COPYING3
-rw-r--r--HACKING47
l---------README1
-rw-r--r--README.org22
-rw-r--r--doc/schemantic.texi61
-rw-r--r--guix.scm32
-rw-r--r--hall.scm30
-rw-r--r--schemantic.scm0
-rw-r--r--schemantic/ns.scm12
-rw-r--r--schemantic/rdf.scm95
-rw-r--r--tests/schemantic/rdf.scm42
12 files changed, 410 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0a123e7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,65 @@
+*.eps
+*.go
+*.log
+*.pdf
+*.png
+*.tar.xz
+*.tar.gz
+*.tmp
+*~
+.#*
+\#*\#
+,*
+/ABOUT-NLS
+/INSTALL
+/aclocal.m4
+/autom4te.cache
+/build-aux/ar-lib
+/build-aux/compile
+/build-aux/config.guess
+/build-aux/config.rpath
+/build-aux/config.sub
+/build-aux/depcomp
+/build-aux/install-sh
+/build-aux/mdate-sh
+/build-aux/missing
+/build-aux/test-driver
+/build-aux/texinfo.tex
+/config.status
+/configure
+/doc/*.1
+/doc/.dirstamp
+/doc/contributing.*.texi
+/doc/*.aux
+/doc/*.cp
+/doc/*.cps
+/doc/*.fn
+/doc/*.fns
+/doc/*.html
+/doc/*.info
+/doc/*.info-[0-9]
+/doc/*.ky
+/doc/*.pg
+/doc/*.toc
+/doc/*.t2p
+/doc/*.tp
+/doc/*.vr
+/doc/*.vrs
+/doc/stamp-vti
+/doc/version.texi
+/doc/version-*.texi
+/m4/*
+/pre-inst-env
+/test-env
+/test-tmp
+/tests/*.trs
+GPATH
+GRTAGS
+GTAGS
+Makefile
+Makefile.in
+config.cache
+stamp-h[0-9]
+tmp
+/.version
+/doc/stamp-[0-9]
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..f658e91
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,3 @@
+This project's license is GPL 3+.
+
+You can read the full license at https://www.gnu.org/licenses/gpl.html.
diff --git a/HACKING b/HACKING
new file mode 100644
index 0000000..471719e
--- /dev/null
+++ b/HACKING
@@ -0,0 +1,47 @@
+-*- mode: org; coding: utf-8; -*-
+
+#+TITLE: Hacking schemantic
+
+* Contributing
+
+By far the easiest way to hack on schemantic is to develop using Guix:
+
+#+BEGIN_SRC bash
+ # Obtain the source code
+ cd /path/to/source-code
+ guix environment -l guix.scm
+ # In the new shell, run:
+ hall dist --execute && autoreconf -vif && ./configure && make check
+#+END_SRC
+
+You can now hack this project's files to your heart's content, whilst
+testing them from your `guix environment' shell.
+
+To try out any scripts in the project you can now use
+
+#+BEGIN_SRC bash
+ ./pre-inst-env scripts/${script-name}
+#+END_SRC
+
+If you'd like to tidy the project again, but retain the ability to test the
+project from the commandline, simply run:
+
+#+BEGIN_SRC bash
+ ./hall clean --skip "scripts/${script-name},pre-inst-env" --execute
+#+END_SRC
+
+** Manual Installation
+
+If you do not yet use Guix, you will have to install this project's
+dependencies manually:
+ - autoconf
+ - automake
+ - pkg-config
+ - texinfo
+ - guile-hall
+
+Once those dependencies are installed you can run:
+
+#+BEGIN_SRC bash
+ hall dist -x && autoreconf -vif && ./configure && make check
+#+END_SRC
diff --git a/README b/README
new file mode 120000
index 0000000..314e17d
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+README.org \ No newline at end of file
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..10d687b
--- /dev/null
+++ b/README.org
@@ -0,0 +1,22 @@
+-*- mode: org; coding: utf-8; -*-
+
+#+TITLE: Guile Schemantic
+
+A [[https://www.gnu.org/software/guile/][Guile]] library for the Semantic Web. Implements the Resource Description Framework (RDF).
+
+Guile Schemantic uses GOOPS, the object oriented extension to Guile. This is an
+experiment to improve developer ergonomics. For a Guile RDF library that does
+not use GOOPS see the excellent [[https://framagit.org/tyreunom/guile-rdf][guile-rdf]].
+
+* Inspiration
+** [[https://rdf-elixir.dev/][RDF.ex]]
+
+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).
+
+** [[https://framagit.org/tyreunom/guile-rdf][Guile RDF]]
+
+Guile library for RDF.
diff --git a/doc/schemantic.texi b/doc/schemantic.texi
new file mode 100644
index 0000000..a54a710
--- /dev/null
+++ b/doc/schemantic.texi
@@ -0,0 +1,61 @@
+
+\input texinfo
+@c -*-texinfo-*-
+
+@c %**start of header
+@setfilename guile-schemantic.info
+@documentencoding UTF-8
+@settitle Guile Schemantic Reference Manual
+@c %**end of header
+
+@include version.texi
+
+@copying
+Copyright @copyright{} 2020 pukkamustard
+
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.3 or
+any later version published by the Free Software Foundation; with no
+Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
+copy of the license is included in the section entitled ``GNU Free
+Documentation License''.
+@end copying
+
+@dircategory The Algorithmic Language Scheme
+@direntry
+* Guile Schemantic: (guile-schemantic).
+@end direntry
+
+@titlepage
+@title The Guile Schemantic Manual
+@author pukkamustard
+
+@page
+@vskip 0pt plus 1filll
+Edition @value{EDITION} @*
+@value{UPDATED} @*
+
+@insertcopying
+@end titlepage
+
+@contents
+
+@c *********************************************************************
+@node Top
+@top Guile Schemantic
+
+This document describes Guile Schemantic version @value{VERSION}.
+
+@menu
+* Introduction:: Why Guile Schemantic?
+@end menu
+
+@c *********************************************************************
+@node Introduction
+@chapter Introduction
+
+INTRODUCTION HERE
+
+This documentation is a stub.
+
+@bye
diff --git a/guix.scm b/guix.scm
new file mode 100644
index 0000000..e69b68c
--- /dev/null
+++ b/guix.scm
@@ -0,0 +1,32 @@
+(use-modules
+ (guix packages)
+ ((guix licenses) #:prefix license:)
+ (guix download)
+ (guix build-system gnu)
+ (gnu packages)
+ (gnu packages autotools)
+ (gnu packages guile)
+ (gnu packages guile-xyz)
+ (gnu packages pkg-config)
+ (gnu packages texinfo))
+
+(package
+ (name "guile-schemantic")
+ (version "0.1")
+ (source "./guile-schemantic-0.1.tar.gz")
+ (build-system gnu-build-system)
+ (arguments `())
+ (native-inputs
+ `(("autoconf" ,autoconf)
+ ("automake" ,automake)
+ ("pkg-config" ,pkg-config)
+ ("texinfo" ,texinfo)))
+ (inputs `(("guile" ,guile-3.0)))
+ (propagated-inputs `())
+ (synopsis "Guile library for the Semantic Web")
+ (description
+ "Guile Schemantic is a Guile library for the Semantic Web and implements the Resource Description Framework (RDF).")
+ (home-page
+ "https://gitlab.com/openengiadina/guile-schemantic")
+ (license license:gpl3+))
+
diff --git a/hall.scm b/hall.scm
new file mode 100644
index 0000000..9a4bf48
--- /dev/null
+++ b/hall.scm
@@ -0,0 +1,30 @@
+(hall-description
+ (name "schemantic")
+ (prefix "guile")
+ (version "0.1")
+ (author "pukkamustard")
+ (copyright (2020))
+ (synopsis "Guile library for the Semantic Web")
+ (description
+ "Guile Schemantic is a Guile library for the Semantic Web and implements the Resource Description Framework (RDF).")
+ (home-page
+ "https://gitlab.com/openengiadina/guile-schemantic")
+ (license gpl3+)
+ (dependencies `())
+ (files (libraries
+ ((scheme-file "schemantic")
+ (directory
+ "schemantic"
+ ((scheme-file "rdf") (scheme-file "ns")))))
+ (tests ((directory
+ "tests"
+ ((directory "schemantic" ((scheme-file "rdf")))))))
+ (programs ((directory "scripts" ())))
+ (documentation
+ ((org-file "README")
+ (symlink "README" "README.org")
+ (text-file "HACKING")
+ (text-file "COPYING")
+ (directory "doc" ((texi-file "schemantic")))))
+ (infrastructure
+ ((scheme-file "guix") (scheme-file "hall")))))
diff --git a/schemantic.scm b/schemantic.scm
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/schemantic.scm
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))))
diff --git a/tests/schemantic/rdf.scm b/tests/schemantic/rdf.scm
new file mode 100644
index 0000000..bc13c1b
--- /dev/null
+++ b/tests/schemantic/rdf.scm
@@ -0,0 +1,42 @@
+; SPDX-FileCopyrightText: 2020 pukkamustard <pukkamustard@posteo.net>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+(define-module (tests schemantic rdf)
+ #:use-module (schemantic rdf)
+ #:use-module (web uri)
+ #:use-module (srfi srfi-64))
+
+(define-namespace ex "http://example.com/#")
+(define-namespace ex2 "http://another-example.com/#")
+
+(test-begin "iri")
+
+(test-assert "make-iri from string"
+ (iri? (make-iri "http://example.com/")))
+
+(test-assert "value of iri is string"
+ (equal? "http://example.com/#"
+ (iri-value (make-iri "http://example.com/#"))))
+
+(test-assert "make-iri from uri"
+ (iri? (make-iri (string->uri "http://example.com/#"))))
+
+(test-assert "value of iri is string of uri"
+ (equal? "http://example.com/#"
+ (iri-value (make-iri (string->uri "http://example.com/#")))))
+
+(test-assert "make-iri of iri is an iri"
+ (iri? (make-iri (make-iri "http://example.com/"))))
+
+(test-equal "equal? compares values"
+ (ex "hi") (make-iri "http://example.com/#hi"))
+
+(test-error "make-iri on integer raises an exception"
+ (make-iri 4))
+
+(test-end "iri")
+
+(equal?
+ (make-iri "http://example.com/#")
+ (make-iri "http://example.com/#"))