diff --git a/docs-scripts/build.py b/docs-scripts/build.py index 9dc7fb911..dd9fab22b 100755 --- a/docs-scripts/build.py +++ b/docs-scripts/build.py @@ -1,19 +1,16 @@ #!/usr/bin/env python3 import os -import re -from jinja2 import Environment, FileSystemLoader -from rdflib import DC, RDF, RDFS, Graph +from rdflib import Graph import logging import shutil import hashlib +from pylode.profiles.vocpub import VocPub # Configure root logger logger = logging.getLogger() logger.setLevel(logging.INFO) logging.basicConfig(format='%(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', level=logging.DEBUG) -prefixes = {} - def hash_file(filename): """Returns the SHA-256 hash of the file passed into it""" @@ -58,94 +55,16 @@ def create_documentation(name, version): versioned_target = f"docs/vocab/{name}/{version}/index.html" latest_target = f"docs/vocab/{name}/latest/index.html" - # Load RDF data into a graph - g = Graph(bind_namespaces="none") - g.parse(file=open(f"hefquin-vocabs/{name}.ttl"), format="turtle") - - # Set up Jinja2 environment and load the template - env = Environment(loader=FileSystemLoader('./docs-scripts/')) - env.filters['prefix'] = prefix - env.filters['prefix_list'] = prefix_list - env.filters['fragment'] = fragment - html_template = env.get_template('template.j2') - - # Collect prefixes - prefixes = {} - for p, namespace in g.namespaces(): - prefixes[p] = namespace - - # Get the identifier of the vocabulary - for s, p, _ in g.triples((None, DC.identifier, None)): - vocab_uri = s - - # Extract general information about the vocabulary - data = { - "creator": g.value(vocab_uri, DC.creator), - "date": g.value(vocab_uri, DC.date), - "format": g.value(vocab_uri, DC.format), - "identifier": g.value(vocab_uri, DC.identifier), - "title": g.value(vocab_uri, DC.title), - "label": g.value(vocab_uri, RDFS.label), - "description": g.value(vocab_uri, DC.description), - "comment": g.value(vocab_uri, RDFS.comment), - "prefixes": prefixes, - "classes": [], - "properties": [], - "instances": [] - } - - # Extract classes - for s in g.subjects(RDF.type, RDFS.Class): - data["classes"].append({ - "uri": s, - "label": g.value(s, RDFS.label, default="N/A"), - "comment": g.value(s, RDFS.comment, default="N/A"), - "subclasses": [o for o in g.objects(s, RDFS.subClassOf)] - }) - - # Extract properties - for s in g.subjects(RDF.type, RDF.Property): - data["properties"].append({ - "uri": s, - "label": g.value(s, RDFS.label, default="N/A"), - "comment": g.value(s, RDFS.comment, default="N/A"), - "domain": g.value(s, RDFS.domain, default="N/A"), - "range": g.value(s, RDFS.range, default="N/A") - }) - - # Extract instances - for s in g.subjects(RDF.type, None): - if s not in [cls['uri'] for cls in data['classes']] and s not in [prop['uri'] for prop in data['properties']]: - data["instances"].append({ - "uri": s, - "type": [o for o in g.objects(s, RDF.type)] - }) - - ## Save the HTML to a file - with open(versioned_target, "w") as file: - data["location"] = f"{vocab_uri}/{version}/{name}" - html_content = html_template.render(data) - file.write(html_content) - - with open(latest_target, "w") as file: - data["location"] = f"{vocab_uri}/latest/{name}" - html_content = html_template.render(data) - file.write(html_content) - - -def prefix_list(l): - return [prefix(i) for i in l] - - -def prefix(resource): - for prefix, uri in prefixes.items(): - if resource.startswith(uri): - return f"{prefix}:{resource.replace(uri, '')}" - return resource - - -def fragment(resource): - return re.split(r"[/#]", resource)[-1] + source = f"hefquin-vocabs/{name}.ttl" + + od = VocPub(ontology=source) + html = od.make_html() + + with open(versioned_target, "w") as f: + f.write(html) + + with open(latest_target, "w") as f: + f.write(html) def main(): diff --git a/docs-scripts/requirements.txt b/docs-scripts/requirements.txt index 3c14f48f7..e93b2fc1d 100644 --- a/docs-scripts/requirements.txt +++ b/docs-scripts/requirements.txt @@ -1,2 +1,2 @@ rdflib -jinja2 \ No newline at end of file +git+https://github.com/LiUSemWeb/pyLODE.git \ No newline at end of file diff --git a/docs-scripts/template.j2 b/docs-scripts/template.j2 deleted file mode 100644 index 4a6aaa066..000000000 --- a/docs-scripts/template.j2 +++ /dev/null @@ -1,101 +0,0 @@ - - -
- - -Creator: {{ creator }}
-Date: {{ date }}
-Format: {{ format }}
-Identifier: {{ identifier }}
-Label: {{ label }}
-Description: {{ description }}
-Comment: {{ comment }}
- -{{ prefix }}: {{ uri }}
- {% endfor %} -Label: {{ cls.label }}
-Comment: {{ cls.comment }}
-- Subclasses: - {% if cls.subclasses %} - {{ cls.subclasses | prefix_list | join(", ") }} - {% else %} - None - {% endif %} -
-Label: {{ prop.label }}
-Comment: {{ prop.comment }}
-Domain: {{ prop.domain | prefix }}
-Range: {{ prop.range | prefix }}
-{{ inst.uri | prefix }}
- {% endfor %} -