Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/)

## [2.0.1] 2025-02-19

### Changed

- Also count node shapes for the execution report
- New icon

## [2.0.0] 2025-02-10

Expand Down
12 changes: 5 additions & 7 deletions cmem_plugin_shapes/plugin_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def str2bool(value: str) -> bool:

@Plugin(
label="Generate SHACL shapes from data",
icon=Icon(file_name="shacl.jpg", package=__package__),
icon=Icon(file_name="shapes.svg", package=__package__),
description="Generate SHACL node and property shapes from a data graph",
documentation=SHAPES_DOC,
parameters=[
Expand Down Expand Up @@ -160,6 +160,7 @@ def format_prefixes(prefixes: dict, formatted_prefixes: dict | None = None) -> d
formatted_prefixes = {}
for prefix, namespace in prefixes.items():
formatted_prefixes.setdefault(namespace, []).append(prefix + ":")

return formatted_prefixes

def get_prefixes(self) -> dict:
Expand All @@ -180,7 +181,6 @@ def get_prefixes(self) -> dict:
if not prefixes_cc or not self.prefix_cc:
with (Path(__path__[0]) / "prefix_cc.json").open("r", encoding="utf-8") as json_file:
prefixes_cc = json.load(json_file)

if prefixes_cc:
prefixes = self.format_prefixes(prefixes_cc, prefixes)

Expand Down Expand Up @@ -214,13 +214,11 @@ def get_name(self, iri: str) -> str:
except IndexError as exc:
raise IndexError(f"{title_json['title']} {prefixes}") from exc
title += f" ({prefix})"

return title

def init_shapes_graph(self) -> Graph:
"""Initialize SHACL shapes graph"""
shapes_graph = Graph()
shapes_graph.add((URIRef(self.shapes_graph_iri), RDF.type, SHUI.ShapeCatalog))
shapes_graph = Graph().add((URIRef(self.shapes_graph_iri), RDF.type, SHUI.ShapeCatalog))
shapes_graph.add(
(
URIRef(self.shapes_graph_iri),
Expand All @@ -240,6 +238,7 @@ def iri_list_to_filter(iris: list[str], name: str = "property", filter_: str = "
if not iris:
return ""
iris_quoted = [f"<{_}>" for _ in iris]

return f"FILTER (?{name} {filter_} ({', '.join(iris_quoted)}))"

def get_class_dict(self) -> dict:
Expand Down Expand Up @@ -292,6 +291,7 @@ def create_shapes(self, shapes_graph: Graph) -> tuple[Graph, int]:
node_shape_uri = URIRef(f"{format_namespace(self.shapes_graph_iri)}{class_uuid}")

if class_uuid not in class_uuids:
shapes_count += 1
shapes_graph.add((node_shape_uri, RDF.type, SH.NodeShape))
shapes_graph.add((node_shape_uri, SH.targetClass, URIRef(cls)))
name = self.get_name(cls)
Expand All @@ -304,7 +304,6 @@ def create_shapes(self, shapes_graph: Graph) -> tuple[Graph, int]:
NAMESPACE_URL, f"{prop['property']}{'inverse' if prop['inverse'] else ''}"
)
property_shape_uri = URIRef(f"{format_namespace(self.shapes_graph_iri)}{prop_uuid}")

if prop_uuid not in prop_uuids:
shapes_count += 1
name = self.get_name(prop["property"])
Expand Down Expand Up @@ -332,7 +331,6 @@ def create_shapes(self, shapes_graph: Graph) -> tuple[Graph, int]:
shapes_graph.add((property_shape_uri, SH.name, Literal(name, lang="en")))
shapes_graph.add((property_shape_uri, RDFS.label, Literal(name, lang="en")))
prop_uuids.add(prop_uuid)

shapes_graph.add((node_shape_uri, SH.property, property_shape_uri))

return shapes_graph, shapes_count
Expand Down
9 changes: 6 additions & 3 deletions cmem_plugin_shapes/prefix_cc.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@
"ddl": "http://purl.org/vocab/riro/ddl#",
"ddpheno": "http://purl.obolibrary.org/obo/DDPHENO_",
"dead": "http://utpl.edu.ec/sbc/data/",
"debias": "http://data.europa.eu/c4p/data/",
"decision": "https://decision-ontology.googlecode.com/svn/trunk/decision.owl#",
"decl": "http://www.linkedmodel.org/1.0/schema/decl#",
"decprov": "http://promsns.org/def/decprov#",
Expand Down Expand Up @@ -1558,7 +1559,7 @@
"mammal": "http://lod.taxonconcept.org/ontology/p01/Mammalia/index.owl#",
"mandaat": "http://data.vlaanderen.be/ns/mandaat#",
"manto": "http://com.vortic3.MANTO/",
"mao": "http://purl.obolibrary.org/obo/MAO_",
"mao": "https://domestic-beethoven.eu/ontology/1.0/music-annotation-ontology.ttl#",
"marc": "http://www.loc.gov/MARC21/slim/",
"marcgt": "https://id.loc.gov/vocabulary/marcgt/",
"marcrel": "http://id.loc.gov/vocabulary/relators/",
Expand Down Expand Up @@ -1784,6 +1785,7 @@
"nsg": "https://neuroshapes.org/",
"nsl": "http://purl.org/ontology/storyline/",
"nsogi": "http://prefix.cc/nsogi:",
"nsprov": "http://www.w3.org/ns/prov#",
"nt": "http://ns.inria.fr/nicetag/2010/09/09/voc#",
"ntag": "http://ns.inria.fr/nicetag/2010/09/09/voc#",
"ntp": "https://schema.finto.fi/ntp#",
Expand Down Expand Up @@ -2560,7 +2562,7 @@
"sct": "http://snomed.info/id/",
"scufl2": "http://ns.taverna.org.uk/2010/scufl2#",
"scv": "http://purl.org/NET/scovo#",
"sd": "https://w3id.org/okn/o/sd#",
"sd": "http://www.w3.org/ns/sparql-service-description#",
"sdgp": "http://stats.data-gov.ie/property/",
"sdl": "http://purl.org/vocab/riro/sdl#",
"sdm": "https://w3id.org/okn/o/sdm#",
Expand Down Expand Up @@ -3068,7 +3070,7 @@
"trackback": "http://madskills.com/public/xml/rss/module/trackback/",
"traffic": "http://www.sensormeasurement.appspot.com/ont/transport/traffic#",
"trait": "http://contextus.net/ontology/ontomedia/ext/common/trait#",
"trak": "https://trakmetamodel.sourceforge.io/vocab/rdf-schema.rdf#",
"trak": "https://purl.org/trak/elements/",
"trans": "http://purl.obolibrary.org/obo/TRANS_",
"transit": "http://vocab.org/transit/terms/",
"transmed": "http://www.w3.org/2001/sw/hcls/ns/transmed/",
Expand Down Expand Up @@ -3215,6 +3217,7 @@
"vr": "https://www.w3.org/2018/credentials/v1/",
"vra": "http://purl.org/vra/",
"vrank": "http://purl.org/voc/vrank#",
"vrti": "https://www.w3id.org/virtual-treasury/ontology#",
"vs": "http://www.w3.org/2003/06/sw-vocab-status/ns#",
"vsao": "http://purl.obolibrary.org/obo/VSAO_",
"vsearch": "http://vocab.sti2.at/vsearch#",
Expand Down
Binary file removed cmem_plugin_shapes/shacl.jpg
Binary file not shown.
15 changes: 15 additions & 0 deletions cmem_plugin_shapes/shapes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading