An open API service indexing awesome lists of open source software.

https://github.com/edwardanderson/krml

Create knowledge graphs with Markdown
https://github.com/edwardanderson/krml

json-ld knowledge-graph linked-data markdown rdf

Last synced: 4 months ago
JSON representation

Create knowledge graphs with Markdown

Awesome Lists containing this project

README

          

# Knowledge Representation Markup Language

- [Knowledge Representation Markup Language](#knowledge-representation-markup-language)
- [Overview](#overview)
- [Example](#example)
- [Input](#input)
- [Output](#output)
- [Model](#model)
- [Logical](#logical)
- [Physical](#physical)
- [Quickstart](#quickstart)
- [Test](#test)

## Overview

Knowledge Representation Markup Language (KRML) is a simple language for creating RDF knowledge graphs using [Markdown](https://en.wikipedia.org/wiki/Markdown) elements: lists of hyperlinks, images, tables and styled or plain text.

As a readable, content-first, low-syntax document format, KRML is optimised for humans. It's intended to facilitate the exchange of structured data between researchers, writers and developers to support the construction of databases of networked information.

The language is defined in this [Specification](docs/specification.md).

> [!NOTE]
> KRML is an on-going research project and is not yet ready for use in production.

## Example

The following description of the [Mona Lisa](https://en.wikipedia.org/wiki/Mona_Lisa) demonstrates many of the features of the language.

```bash
krml examples/mona_lisa.md
```

### Input

[`mona_lisa.md`](examples/mona_lisa.md)

```markdown
---
id: http://example.org/mona-lisa
title: Mona Lisa
language: en
---

- Mona Lisa
- title
- > Mona Lisa
- > La joconde `fr`
- > la Gioconda `it`
- > モナ・リザ `jp`
- a
- Painting
- description
- > Considered an archetypal [masterpiece](https://en.wikipedia.org/wiki/Masterpiece) of the [Italian Renaissance](https://en.wikipedia.org/wiki/Italian_Renaissance), it has been described as "the best known, the most visited, the most written about, the most sung about, [and] the most parodied work of art in the world."
- source
-
- image
- ![Mona Lisa, by Leonardo da Vinci](https://w.wiki/C4dN)
- creator
- [Leonardo da Vinci](http://www.wikidata.org/entity/Q762)
- description
- > Italian Renaissance polymath (1452−1519)
- [date of birth](https://schema.org/birthDate)
- > 1452-04-15 `date`

---

Mona Lisa
:
:

title
:

date
:
```

### Output

```json
{
"@context": [
{
"@version": 1.1,
"dcmitype": "http://purl.org/dc/dcmitype/",
"dcterms": "http://purl.org/dc/terms/",
"owl": "http://www.w3.org/2002/07/owl#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"schema": "https://schema.org/",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"_Dataset": {
"@id": "dcmitype:Dataset"
},
"_HTML": {
"@id": "rdf:HTML"
},
"_Image": {
"@id": "dcmitype:Image"
},
"_Table": {
"@id": "schema:Table"
},
"_Text": {
"@id": "dcmitype:Text"
},
"_boolean": {
"@id": "xsd:boolean"
},
"_content": {
"@id": "rdf:value"
},
"_format": {
"@id": "dcterms:format"
},
"_label": {
"@id": "rdfs:label"
},
"_sameAs": {
"@id": "owl:sameAs",
"@container": "@set"
},
"_seeAlso": {
"@id": "rdfs:seeAlso",
"@container": "@set"
}
},
{
"@base": "http://example.org/",
"@language": "en",
"@vocab": "http://example.org/terms/",
"title": {
"@id": "https://schema.org/name",
"@container": "@set"
},
"date": {
"@id": "http://www.w3.org/2001/XMLSchema#date",
"@type": "@id"
}
}
],
"@id": "http://example.org/mona-lisa",
"@graph": [
{
"@id": "http://example.org/mona-lisa",
"_label": "Mona Lisa"
},
{
"@id": "http://www.wikidata.org/entity/Q12418",
"_label": "Mona Lisa",
"@type": [
"Painting"
],
"title": [
{
"@language": "en",
"@value": "Mona Lisa"
},
{
"@language": "fr",
"@value": "La joconde"
},
{
"@language": "it",
"@value": "la Gioconda"
},
{
"@language": "jp",
"@value": "モナ・リザ"
}
],
"description": [
{
"@type": [
"_Text"
],
"_content": {
"@type": "_HTML",
"@value": "

Considered an archetypal masterpiece of the Italian Renaissance, it has been described as \"the best known, the most visited, the most written about, the most sung about, [and] the most parodied work of art in the world.\"

"
},
"_seeAlso": [
{
"@id": "https://en.wikipedia.org/wiki/Masterpiece",
"_label": "masterpiece"
},
{
"@id": "https://en.wikipedia.org/wiki/Italian_Renaissance",
"_label": "Italian Renaissance"
}
],
"source": [
{
"@id": "https://en.wikipedia.org/wiki/Mona_Lisa",
"_label": "Mona_Lisa"
}
]
}
],
"image": [
{
"@id": "https://w.wiki/C4dN",
"@type": [
"_Image"
],
"_label": "Mona Lisa, by Leonardo da Vinci"
}
],
"creator": [
{
"@id": "http://www.wikidata.org/entity/Q762",
"_label": "Leonardo da Vinci",
"description": [
{
"@language": "en",
"@value": "Italian Renaissance polymath (1452−1519)"
}
],
"https://schema.org/birthDate": [
{
"@type": "date",
"@value": "1452-04-15"
}
]
}
]
},
{
"@id": "http://www.wikidata.org/entity/Q12418",
"_sameAs": [
{
"@id": "https://collections.louvre.fr/ark:/53355/cl010062370",
"_label": "Mona Lisa"
}
]
}
]
}
```

text/turtle

```turtle
PREFIX dcmitype:
PREFIX ex:
PREFIX exterms:
PREFIX owl:
PREFIX rdf:
PREFIX rdfs:
PREFIX schema:
PREFIX xsd:

ex:mona-lisa
rdfs:label "Mona Lisa"@en ;
.

a exterms:Painting ;
rdfs:label "Mona Lisa"@en ;
exterms:creator ;
exterms:description [
a dcmitype:Text ;
exterms:source ;
rdf:value "

Considered an archetypal masterpiece of the Italian Renaissance, it has been described as \"the best known, the most visited, the most written about, the most sung about, [and]
the most parodied work of art in the world.\"

"^^rdf:HTML ;
rdfs:seeAlso
,

] ;
exterms:image ;
owl:sameAs ;
schema:name
"Mona Lisa"@en ,
"La joconde"@fr ,
"la Gioconda"@it ,
"モナ・リザ"@jp ;
.

rdfs:label "Leonardo da Vinci"@en ;
exterms:description "Italian Renaissance polymath (1452−1519)"@en ;
schema:birthDate "1452-04-15"^^xsd:date ;
.

rdfs:label "Mona Lisa"@en ;
.

rdfs:label "Italian Renaissance"@en ;
.

rdfs:label "masterpiece"@en ;
.

rdfs:label "Mona_Lisa"@en ;
.

a dcmitype:Image ;
rdfs:label "Mona Lisa, by Leonardo da Vinci"@en ;
.
```

application/trig

```turtle
@prefix dcmitype: .
@prefix ex: .
@prefix exterms: .
@prefix owl: .
@prefix rdf: .
@prefix rdfs: .
@prefix schema: .
@prefix xsd: .

ex:mona-lisa {
ex:mona-lisa rdfs:label "Mona Lisa"@en .

a exterms:Painting ;
rdfs:label "Mona Lisa"@en ;
exterms:creator ;
exterms:description [ a dcmitype:Text ;
exterms:source ;
rdf:value "

Considered an archetypal masterpiece of the Italian Renaissance, it has been described as \"the best known, the most visited, the most written about, the most sung about, [and]
the most parodied work of art in the world.\"

"^^rdf:HTML ;
rdfs:seeAlso ,
] ;
exterms:image ;
owl:sameAs ;
schema:name "Mona Lisa"@en,
"La joconde"@fr,
"la Gioconda"@it,
"モナ・リザ"@jp .

rdfs:label "Leonardo da Vinci"@en ;
exterms:description "Italian Renaissance polymath (1452−1519)"@en ;
schema:birthDate "1452-04-15"^^xsd:date .

rdfs:label "Mona Lisa"@en .

rdfs:label "Italian Renaissance"@en .

rdfs:label "masterpiece"@en .

rdfs:label "Mona_Lisa"@en .

a dcmitype:Image ;
rdfs:label "Mona Lisa, by Leonardo da Vinci"@en .
}
```

## Model

### Logical

A KRML document is a list of **Resources** connected to each other via **Relationships**.

### Physical

Documents are composed of nests of ordered or unordered lists of resources, relationships and types.

- Resources are identified by [hyperlinks](https://www.markdownguide.org/basic-syntax/#links), [image links](https://www.markdownguide.org/basic-syntax/#images-1) or plain-text
- Relationships are identified by hyperlinks or plain-text
- Texts are [blockquotes](https://www.markdownguide.org/basic-syntax/#blockquotes-1), with or without styling
- Types are optional qualifiers for human languages or [datatypes](https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#section-Datatypes) of Texts as [code-fenced text](https://www.markdownguide.org/basic-syntax/#code)

```text
- Resource
- relationship
- Resource
- relationship
- > Text `Type`
- relationship
- ...
```

```text
- John
- knows
- Paul
- name
- > John Winston Lennon `en`
```

Definition lists can identify any plain text resources, relationships or types.

```text
- John
- date of birth
- > 1940-10-09 `date`
- born in
- Liverpool
- Paul
- born in
- Liverpool

date
:

born in
:

Liverpool
:
```

Document configuration parameters can be set in the [frontmatter](docs/specification.md#2-frontmatter).

```markdown
---
base: http://www.example.org/
id: http://www/example.org/doc/1
import: file:///path/to/file.md
language: en
title: Lorem Ipsum
vocab: https://schema.org/
---
```

## Quickstart

```bash
git clone git@github.com:edwardanderson/krml.git
cd krml
python3 -m venv .venv
source .venv/bin/activate
pip install --editable .
```

```bash
krml /path/to/file.md --help
```

## Test

This project uses `pytest` with `go-testmark` fixtures to validate the [Specification](docs/specification.md).