4141PLUGIN_LABEL = "Generate SHACL shapes from data"
4242TRUE_SET = {"yes" , "true" , "t" , "y" , "1" }
4343FALSE_SET = {"no" , "false" , "f" , "n" , "0" }
44+ EXISTING_GRAPH_ADD = "add"
45+ EXISTING_GRAPH_REPLACE = "replace"
46+ EXISTING_GRAPH_STOP = "stop"
47+ EXISTING_GRAPH_PARAMETER_CHOICES = OrderedDict (
48+ {
49+ EXISTING_GRAPH_ADD : "add result to graph" ,
50+ EXISTING_GRAPH_REPLACE : "replace existing graph with result" ,
51+ EXISTING_GRAPH_STOP : "stop workflow if output graph exists" ,
52+ }
53+ )
4454
4555
4656def format_namespace (iri : str ) -> str :
@@ -82,15 +92,7 @@ def str2bool(value: str) -> bool:
8292 description = "The knowledge graph the generated shapes will be added to." ,
8393 ),
8494 PluginParameter (
85- param_type = ChoiceParameterType (
86- OrderedDict (
87- {
88- "add" : "add result to graph" ,
89- "replace" : "replace existing graph with result" ,
90- "stop" : "stop workflow if output graph exists" ,
91- }
92- ),
93- ),
95+ param_type = ChoiceParameterType (EXISTING_GRAPH_PARAMETER_CHOICES ),
9496 name = "existing_graph" ,
9597 label = "Handle existing output graph" ,
9698 description = "Add result to the existing graph (add result to graph), overwrite the "
@@ -119,10 +121,11 @@ def str2bool(value: str) -> bool:
119121 param_type = BoolParameterType (),
120122 name = "prefix_cc" ,
121123 label = "Fetch namespace prefixes from prefix.cc" ,
122- description = "Attempt to fetch namespace prefixes from prefix.cc instead of from the "
123- "local database. If this fails, fall back on local database. Prefixes defined in the "
124- "Corporate Memory project will override prefixes defined in the external database." ,
125- default_value = False ,
124+ description = "Fetch the list of namespace prefixes from https://prefix.cc instead of "
125+ "using the local prefix database. If unavailable, fall back to the local database. "
126+ "Prefixes defined in the Corporate Memory project override database prefixes. Enabling "
127+ "this option exposes your IP address to prefix.cc but no other data is shared. If "
128+ "unsure, keep this option disabled. See https://prefix.cc/about." ,
126129 advanced = True ,
127130 ),
128131 PluginParameter (
@@ -149,9 +152,9 @@ def __init__( # noqa: PLR0913
149152 data_graph_iri : str ,
150153 shapes_graph_iri : str ,
151154 label : str = "" ,
152- existing_graph : str = "stop" ,
155+ existing_graph : str = EXISTING_GRAPH_STOP ,
153156 import_shapes : bool = False ,
154- prefix_cc : bool = True ,
157+ prefix_cc : bool = False ,
155158 ignore_properties : str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" ,
156159 plugin_provenance : bool = False ,
157160 ) -> None :
@@ -169,18 +172,21 @@ def __init__( # noqa: PLR0913
169172 self .label = label
170173
171174 existing_graph = existing_graph .lower ()
172- if existing_graph not in ("stop" , "replace" , "add" ):
173- raise ValueError ("Invalid value for parameter 'Handle existing output graph'" )
175+ if existing_graph not in EXISTING_GRAPH_PARAMETER_CHOICES :
176+ raise ValueError (
177+ "Invalid value for parameter 'Handle existing output graph'. "
178+ f"Valid options: { ', ' .join (EXISTING_GRAPH_PARAMETER_CHOICES .keys ())} ."
179+ )
174180 self .replace = False
175- if existing_graph == "replace" :
181+ if existing_graph == EXISTING_GRAPH_REPLACE :
176182 self .replace = True
177183 self .existing_graph = existing_graph
178184
179185 self .import_shapes = import_shapes
180186 self .prefix_cc = prefix_cc
181187
182188 self .ignore_properties = []
183- for _ in ignore_properties .split ("\n " ):
189+ for _ in filter ( None , ignore_properties .split ("\n " ) ):
184190 if not validators .url (_ ):
185191 raise ValueError (f"Invalid property IRI ({ _ } ) in parameter 'Properties to ignore'" )
186192 self .ignore_properties .append (_ )
@@ -598,7 +604,7 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> None
598604 self .update_execution_report ()
599605 setup_cmempy_user_access (context .user )
600606 graph_exists = self .shapes_graph_iri in [_ ["iri" ] for _ in get_graphs_list ()]
601- if self .existing_graph == "stop" and graph_exists :
607+ if self .existing_graph == EXISTING_GRAPH_STOP and graph_exists :
602608 raise ValueError (f"Graph <{ self .shapes_graph_iri } > already exists." )
603609
604610 self .prefixes = self .get_prefixes ()
0 commit comments