From 90d6edeb10a96c4fc8d93cf6c18f170fc57ba63d Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Thu, 8 Jun 2023 15:04:57 -0700 Subject: [PATCH] citation style to handle dates, starting on ld fragments --- src/comparison/ld_fragments.md | 7 +++ src/conf.py | 81 +++++++++++++++++++++++++++++++++- src/index.md | 9 ++++ src/p2p_ld_docs.bib | 19 ++++++++ src/references.md | 2 +- src/sketchpad.md | 2 +- 6 files changed, 117 insertions(+), 3 deletions(-) diff --git a/src/comparison/ld_fragments.md b/src/comparison/ld_fragments.md index b7da0b9..caf995c 100644 --- a/src/comparison/ld_fragments.md +++ b/src/comparison/ld_fragments.md @@ -1 +1,8 @@ # Linked Data Fragments + + +## References + +- Homepage: https://linkeddatafragments.org/ +- Papers: + - {cite}`verborghTriplePatternFragments2016` \ No newline at end of file diff --git a/src/conf.py b/src/conf.py index 8d13e37..213c111 100644 --- a/src/conf.py +++ b/src/conf.py @@ -61,4 +61,83 @@ napoleon_attr_annotations = True # bibtex bibtex_bibfiles = ['p2p_ld_docs.bib'] -bibtex_reference_style = 'author_year' \ No newline at end of file +bibtex_reference_style = 'author_year' +bibtex_default_style = 'bbibtex' + +## Formatting to handle dates that are in the `date` field rather than `year` +import re +import pybtex.plugin +from pybtex.richtext import Symbol, Text +from pybtex.style.formatting.unsrt import Style as UnsrtStyle +from pybtex.style.formatting import toplevel +from pybtex.style.template import ( + field, first_of, href, join, names, optional, optional_field, sentence, + tag, together, words +) + +def dashify(text): + dash_re = re.compile(r'-+') + return Text(Symbol('ndash')).join(text.split(dash_re)) + +date = first_of [ + field('date'), + words [optional_field('month'), field('year')] +] +pages = field('pages', apply_func=dashify) + + +class BetterBibTeXStyle(UnsrtStyle): + def get_article_template(self, e): + volume_and_pages = first_of [ + # volume and pages, with optional issue number + optional [ + join [ + field('volume'), + optional['(', field('number'),')'], + ':', pages + ], + ], + # pages only + words ['pages', pages], + ] + template = toplevel [ + self.format_names('author'), + self.format_title(e, 'title'), + sentence [ + tag('em') [first_of [ + field('journaltitle'), + field('journal') + ]], + optional[ volume_and_pages ], + date], + sentence [ optional_field('note') ], + self.format_web_refs(e), + ] + return template + +# ---------------- +# Handle when dates are in `date` and not `year` + +# fuck it just monkey patch it + +from sphinxcontrib.bibtex.style.template import node +from typing import Dict +from sphinxcontrib.bibtex.style.template import first_of as first_of_ +from sphinxcontrib.bibtex.style.template import optional as optional_ +from sphinxcontrib.bibtex.style.template import field as field_ +from sphinxcontrib.bibtex.style import template as template_module + + + +def split_year(date:str) -> str: + return date.split('-')[0] + +@node +def year(children, data: Dict[str, Any]) -> "BaseText": + assert not children + return first_of_[optional_[field_('year')], optional_[field_('date', apply_func=split_year)], 'n.d.'].format_data(data) + +template_module.year = year + + +pybtex.plugin.register_plugin('pybtex.style.formatting', 'bbibtex', BetterBibTeXStyle) \ No newline at end of file diff --git a/src/index.md b/src/index.md index c37b26d..cc476dc 100644 --- a/src/index.md +++ b/src/index.md @@ -3,9 +3,14 @@ All of this is very work in progress :) plz do not rely on any of the descriptions or statements here, as they are all effectively provisional. This site describes the implementation of the p2p linked data protocol in {cite}`saundersDecentralizedInfrastructureNeuro2022` + +## Document Status + +**23-06-08** - Populating the [Comparison](comparison) section first to refresh myself on other projects, and starting to sketch diagrammatically in [Sketchpad](sketchpad). The rest of the pages are just stubs to keep track of ideas before fleshing them out. ```{toctree} :caption: Introduction +:hidden: overview comparison/index @@ -16,6 +21,7 @@ out_of_scope ```{toctree} :caption: Protocol :numbered: +:hidden: definitions protocol @@ -32,6 +38,7 @@ evolvability ```{toctree} :caption: Ecosystem +:hidden: triplets translation @@ -39,12 +46,14 @@ translation ```{toctree} :caption: Drafting +:hidden: sketchpad ``` ```{toctree} :caption: Meta +:hidden: genindex references diff --git a/src/p2p_ld_docs.bib b/src/p2p_ld_docs.bib index 77bff0a..152362e 100644 --- a/src/p2p_ld_docs.bib +++ b/src/p2p_ld_docs.bib @@ -25,3 +25,22 @@ keywords = {archived,Computer Science - General Literature,E.2,H.4.3,H.5.3,K.2,K.4.1,K.4.3,K.6.4}, file = {/Users/jonny/Dropbox/papers/zotero/S/SaundersJ/saunders_2022_decentralized_infrastructure_for_(neuro)science.pdf} } + +@article{verborghTriplePatternFragments2016, + title = {Triple {{Pattern Fragments}}: {{A}} Low-Cost Knowledge Graph Interface for the {{Web}}}, + shorttitle = {Triple {{Pattern Fragments}}}, + author = {Verborgh, Ruben and Vander Sande, Miel and Hartig, Olaf and Van Herwegen, Joachim and De Vocht, Laurens and De Meester, Ben and Haesendonck, Gerald and Colpaert, Pieter}, + date = {2016-03}, + journaltitle = {Journal of Web Semantics}, + shortjournal = {Journal of Web Semantics}, + volume = {37--38}, + pages = {184--206}, + issn = {15708268}, + doi = {10.1016/j.websem.2016.03.003}, + url = {https://linkinghub.elsevier.com/retrieve/pii/S1570826816000214}, + urldate = {2023-06-08}, + archive = {https://web.archive.org/web/20230608191748/https://www.sciencedirect.com/science/article/abs/pii/S1570826816000214?via\%3Dihub}, + langid = {english}, + keywords = {archived}, + file = {/Users/jonny/Dropbox/papers/zotero/V/VerborghR/verborgh_2016_triple_pattern_fragments.pdf} +} diff --git a/src/references.md b/src/references.md index ab49843..d2d61f4 100644 --- a/src/references.md +++ b/src/references.md @@ -2,4 +2,4 @@ ```{bibliography} -``` \ No newline at end of file +``` \ No newline at end of file diff --git a/src/sketchpad.md b/src/sketchpad.md index 536fe82..b80ffac 100644 --- a/src/sketchpad.md +++ b/src/sketchpad.md @@ -6,7 +6,7 @@ Dummy change to check that we don't invalidate the rust cache on CI. Just a stub to check if mermaid works -```mermaid +```{mermaid} erDiagram IDENTITY { string hash