diff --git a/.flake8 b/.flake8 index bb93c8a93..b7de0e021 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,2 @@ [flake8] max-line-length=79 -exclude = - scripts/editProperties.py diff --git a/.github/workflows/validate_and_release.yml b/.github/workflows/validate_and_release.yml index 8d7632e3d..f3b713eaa 100644 --- a/.github/workflows/validate_and_release.yml +++ b/.github/workflows/validate_and_release.yml @@ -72,7 +72,6 @@ jobs: mv reproschema.jsonld releases/${{ inputs.version }}/reproschema.jsonld mv reproschema.nt releases/${{ inputs.version }}/reproschema.nt mv reproschema.ttl releases/${{ inputs.version }}/reproschema.ttl - # python scripts/makeRelease.py ${{ inputs.version }} - name: Open pull requests to add files uses: peter-evans/create-pull-request@v6 diff --git a/scripts/editProperties.py b/scripts/editProperties.py deleted file mode 100644 index b6f1ce921..000000000 --- a/scripts/editProperties.py +++ /dev/null @@ -1,104 +0,0 @@ -import sys - -import rdflib as rl -from pytablewriter import MarkdownTableWriter - -AUTO_LINE = "" - - -def edit_properties(version): - targetClasses = [ - "Protocol", - "Activity", - "Field", - "AdditionalProperty", - "OverrideProperty", - "UnitOption", - "ResponseOption", - "Choice", - "ComputeSpecification", - "MessageSpecification", - "AdditionalNoteObj", - "ResponseActivity", - "Response", - "Participant", - "SoftwareAgent", - ] - - with open("docs/schema.md") as fp: - doc = fp.readlines() - for idx, line in enumerate(doc): - if line.startswith(AUTO_LINE): - break - doc = doc[:idx] - doc.append(AUTO_LINE) - doc.append( - """\n -""" - ) - - # read all the terms - g = rl.Graph() - g.parse( - "https://raw.githubusercontent.com/schemaorg/schemaorg/main/data/releases/9.0/schema.ttl", - format="turtle", - ) - g.parse(f"releases/{version}/reproschema.ttl", format="turtle") - g.parse(f"releases/{version}/reproschema-shacl.ttl", format="turtle") - - query = """PREFIX sh: -SELECT ?obj ?prop ?desc ?objdesc -WHERE { - ?obj1 a sh:NodeShape; - sh:property [ sh:path ?prop ]; - sh:targetClass ?obj . - OPTIONAL { ?prop rdfs:comment ?desc .} - OPTIONAL { ?obj rdfs:comment ?objdesc . } -} -""" - results = list(g.query(query)) - - objects = {k: {} for k in targetClasses} - for res in results: - s = g.compute_qname(res[0]) - p = g.compute_qname(res[1]) - if s[2] not in objects: - raise ValueError(f"Unknown class: {s[2]}. Source: {res}") - objects[s[2]][p] = str(res[2]) - objects[s[2]]["klass_desc"] = str(res[3]) - for klass, props in objects.items(): - writer = MarkdownTableWriter() - writer.table_name = ( - f"{klass}\n" - f"{props['klass_desc']}\n\n" - f"**URI:** [http://schema.repronim.org/{klass}](http://schema.repronim.org/{klass})\n" - ) - writer.headers = ["Name", "Description", "URI"] - writer.value_matrix = [] - del props["klass_desc"] - for val, comment in sorted(props.items()): - property = [ - val[2], - comment, - f"[{val[1]}{val[2]}]({val[1]}{val[2]})", - ] - writer.value_matrix.append(property) - writer.margin = 1 # add a whitespace for both sides of each cell - doc.append("\n") - doc.append("##" + writer.dumps()) - with open("docs/30_schema.md", "wt") as fp: - fp.writelines(doc) - - -if __name__ == "__main__": - if len(sys.argv) < 2: - version = "master" - else: - version = sys.argv[1] - print(f"Generating classes and properties for version: {version}") - edit_properties(version) diff --git a/scripts/makeRelease.py b/scripts/makeRelease.py deleted file mode 100644 index f933d973a..000000000 --- a/scripts/makeRelease.py +++ /dev/null @@ -1,59 +0,0 @@ -import json -import os -import sys -from shutil import copyfile - -import rdflib as rl -from pyld import jsonld - -from reproschema.jsonldutils import to_newformat - - -def create_release(version): - # read all the terms - terms = [] - for root, _, files in os.walk("terms"): - for name in files: - terms.extend( - json.loads(to_newformat(os.path.join(root, name), "jsonld")) - ) - - kwargs = {"algorithm": "URDNA2015", "format": "application/n-quads"} - data = jsonld.normalize(terms, kwargs) - - os.makedirs(f"releases/{version}", exist_ok=True) - copyfile("contexts/base", f"releases/{version}/base") - copyfile("contexts/generic", f"releases/{version}/generic") - with open(f"releases/{version}/base") as fp: - base_context = json.load(fp) - compacted = jsonld.compact(terms, ctx=base_context) - - g = rl.Graph() - for key, val in base_context["@context"].items(): - if not key.startswith("@"): - g.namespace_manager.bind(key, val) - g.parse(data=data, format="nt") - - # write n-triples and turtle files - with open(f"releases/{version}/reproschema.jsonld", "w") as fp: - json.dump(compacted, fp, indent=2) - with open(f"releases/{version}/reproschema.nt", "w") as fp: - fp.write(data) - with open(f"releases/{version}/reproschema.ttl", "w") as fp: - fp.write(g.serialize(format="turtle")) - - g1 = rl.Graph() - g1.parse("validation/reproschema-shacl.ttl", format="turtle") - with open(f"releases/{version}/reproschema-shacl.ttl", "w") as fp: - fp.write(g1.serialize(format="turtle")) - - return g - - -if __name__ == "__main__": - if len(sys.argv) < 2: - version = "master" - else: - version = sys.argv[1] - print(f"Generating release for version: {version}") - create_release(version)