From 6d432681934a532f4429f57c0c92eb96ed3388c7 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 12 May 2025 11:13:07 +0200 Subject: cover CURIE type prefix; improve examples in comments --- .../semantic-markdown/semantic-markdown.lua | 116 ++++++++++++++++----- 1 file changed, 89 insertions(+), 27 deletions(-) (limited to '_extensions') diff --git a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua index 9213a1a..fb96abe 100644 --- a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua +++ b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua @@ -5,39 +5,93 @@ --- --- ## Examples --- ---- Ideally, this text: +--- The following Markdown text includes semantic annotations +--- within braced enclosures: --- ---- ```Markdown+RDF ---- Simple ontological annotation: ---- [This]{foaf:depiction} is not a pipe. +--- ```markdown +--- # {=<#artwork> .:Image} Semantics +--- +--- Simple ontological annotation: +--- [This][painting] is not a [pipe]. +--- +--- Nested, mixed-use and custom-namespaced annotations: +--- [[Ceci][painting] n'est pas une [pipe].]{lang=fr bibo:shortDescription} +--- +--- [painting]: {wd:Q1061035} +--- "A painting of a smoking pipe {:depiction}" --- ---- Nested, mixed-use and custom-namespaced annotations: ---- [[Ceci]{foaf:depiction} n'est pas une pipe.]{lang=fr bibo:Quote} +--- [pipe]: {wd:Q104526} +--- "A smoking pipe {:depicts}" +--- +--- {@default}: foaf --- --- {bibo}: http://purl.org/ontology/bibo/ +--- +--- {wd}: http://www.wikidata.org/entity/ --- ``` --- ---- ...should with this filter be transformed to this text: +--- This filter should transform the above text, with the command +--- `pandoc -L semantic-markdown.lua -t commonmark --wrap=preserve`, +--- into the below markdown text with semantic annotations as metadata: --- ---- ```Markdown +--- ```markdown --- --- --- turtle: | --- @prefix bibo: http://purl.org/ontology/bibo/ +--- @prefix foaf: http://xmlns.com/foaf/0.1/ +--- @prefix wd: https://www.wikidata.org/entity/ --- ---- _:001 a foaf:depiction . ---- _:002 a foaf:depiction . ---- _:003 a bibo:Quote . +--- <#artwork> a foaf:Image ; +--- foaf:depiction ; +--- foaf:depicts ; +--- bibo:shortDescription "Ceci n'est pas une pipe."@fr . --- --- ---- Simple ontological annotation: ---- This is not a pipe. +--- # Semantics --- ---- Nested, mixed-use and custom-namespaced annotations: ---- [Ceci n'est pas une pipe.]{lang=fr} +--- Simple ontological annotation: +--- [This][painting] is not a [pipe]. +--- +--- Nested, mixed-use and custom-namespaced annotations: +--- [[Ceci][painting] n'est pas une [pipe].]{lang=fr} +--- +--- [painting]: https://www.wikidata.org/entity/Q1061035 +--- "A painting of a smoking pipe" +--- +--- [pipe]: https://www.wikidata.org/entity/Q104526 +--- "A smoking pipe" --- ``` --- ---- When target document format is html, ---- this filter should ideally produce RDFa 1.1 Lite or Core data. ---- (Lite is *not* a subset of Core as it deviates slightly). +--- This filter should also transform the above text, with the command +--- `pandoc -L semantic-markdown.lua -t html --wrap=preserve`, +--- into the below HTML text with embedded RDFa Lite 1.1 anotations, +--- modulo wrapping of long lines: +--- +--- ```html +---
+---

Semantics

+---

Simple ontological annotation:
+--- This +--- is not +--- a pipe.

+--- +---

Nested, mixed-use and custom-namespaced annotations:
+--- +--- Ceci +--- n'est pas +--- une pipe. +---

+---
+--- ``` --- --- * v0.0.1 --- * initial release @@ -74,6 +128,9 @@ local ElementTypeIsEnclosure = { Strong = true, } +--- curie_type_prefix - `typeof` or `resource` attribute CURIE hint +local curie_type_prefix = "[.=]?" + -- TODO: cover non-ASCII Unicode characters -- @see --- curie_prefix - CURIE prefix component as set of chars @@ -118,6 +175,7 @@ local curie_default = ":" --- # Annotated paragraph using a custom namespace --- --- My favorite animal is the [Liger]{ov:preferredAnimal}. +--- {=<#me> .:Person} --- --- {ov}: http://open.vocab.org/terms/ --- ``` @@ -129,7 +187,7 @@ local curie_default = ":" local function Namespaces(blocks) -- paragraph with only a braced prefix-only CURIE, colon and one word - local curie_pattern = "^{"..curie_prefix.."}:$" + local curie_pattern = "^{"..curie_type_prefix..curie_prefix.."}:$" if #blocks.content == 3 and blocks.content[1].t == "Str" and blocks.content[2].t == "Space" @@ -182,10 +240,10 @@ end --- a bc CURIEa d --- --- Nested and mixed-use annotations: ---- ["[Ceci]{foaf:depiction} n'est pas une pipe"]{lang=fr dc:Text} ---- | | ||\~~~~~~~~~~~~/| || \~~~~~/| ---- a a1 |c1 CURIEa d1 bc CURIEb d ---- b1 +--- ["Ceci n'est pas une [pipe]{foaf:depicts lang=fr}"]{dc:description} +--- | | ||\~~~~~~~~~~/ | ||\~~~~~~~~~~~~/| +--- a a1 |c1 CURIEa d1bc CURIEb d +--- b1 --- --- Chained hypermedia and ontological annotations: --- "A [map](https://osm.org/){foaf:depiction} is not the territory" @@ -339,10 +397,14 @@ local function Statements (block) -- in braced enclosure, leaving it -- TODO: support mixed-use enclosure if encl == Enclosure.BRACED then - local _, nextpos1 = el.text:find("^"..curie_long.."}", pos) - local _, nextpos2 = el.text:find("^"..curie_no_ref.."}", pos) - local _, nextpos3 = el.text:find("^"..curie_local.."}", pos) - local _, nextpos4 = el.text:find("^"..curie_default.."}", pos) + local curie_pattern1 = "^"..curie_type_prefix..curie_long.."}" + local curie_pattern2 = "^"..curie_type_prefix..curie_no_ref.."}" + local curie_pattern3 = "^"..curie_type_prefix..curie_local.."}" + local curie_pattern4 = "^"..curie_type_prefix..curie_default.."}" + local _, nextpos1 = el.text:find(curie_pattern1, pos) + local _, nextpos2 = el.text:find(curie_pattern2, pos) + local _, nextpos3 = el.text:find(curie_pattern3, pos) + local _, nextpos4 = el.text:find(curie_pattern4, pos) local nextpos = nextpos1 or nextpos2 or nextpos3 or nextpos4 if nextpos then statement_count = statement_count + 1 -- cgit v1.2.3