linkml 1.5.6__py3-none-any.whl → 1.5.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. linkml/__init__.py +2 -6
  2. linkml/_version.py +1 -1
  3. linkml/generators/__init__.py +26 -5
  4. linkml/generators/common/type_designators.py +27 -22
  5. linkml/generators/csvgen.py +4 -10
  6. linkml/generators/docgen/class.md.jinja2 +7 -0
  7. linkml/generators/docgen/class_diagram.md.jinja2 +0 -6
  8. linkml/generators/docgen/subset.md.jinja2 +54 -13
  9. linkml/generators/docgen.py +92 -90
  10. linkml/generators/dotgen.py +5 -9
  11. linkml/generators/erdiagramgen.py +56 -51
  12. linkml/generators/excelgen.py +10 -16
  13. linkml/generators/golanggen.py +11 -21
  14. linkml/generators/golrgen.py +4 -13
  15. linkml/generators/graphqlgen.py +3 -11
  16. linkml/generators/javagen.py +8 -15
  17. linkml/generators/jsonldcontextgen.py +7 -36
  18. linkml/generators/jsonldgen.py +14 -12
  19. linkml/generators/jsonschemagen.py +177 -133
  20. linkml/generators/markdowngen.py +40 -89
  21. linkml/generators/namespacegen.py +1 -2
  22. linkml/generators/oocodegen.py +22 -25
  23. linkml/generators/owlgen.py +34 -49
  24. linkml/generators/prefixmapgen.py +5 -13
  25. linkml/generators/projectgen.py +7 -14
  26. linkml/generators/protogen.py +3 -5
  27. linkml/generators/pydanticgen.py +85 -73
  28. linkml/generators/pythongen.py +86 -154
  29. linkml/generators/rdfgen.py +5 -11
  30. linkml/generators/shaclgen.py +32 -18
  31. linkml/generators/shexgen.py +19 -24
  32. linkml/generators/sparqlgen.py +4 -12
  33. linkml/generators/sqlalchemy/__init__.py +3 -2
  34. linkml/generators/sqlalchemy/sqlalchemy_declarative_template.py +7 -7
  35. linkml/generators/sqlalchemy/sqlalchemy_imperative_template.py +3 -3
  36. linkml/generators/sqlalchemygen.py +29 -27
  37. linkml/generators/sqlddlgen.py +34 -26
  38. linkml/generators/sqltablegen.py +21 -21
  39. linkml/generators/sssomgen.py +11 -13
  40. linkml/generators/summarygen.py +2 -4
  41. linkml/generators/terminusdbgen.py +7 -19
  42. linkml/generators/typescriptgen.py +10 -18
  43. linkml/generators/yamlgen.py +0 -2
  44. linkml/generators/yumlgen.py +23 -71
  45. linkml/linter/cli.py +4 -11
  46. linkml/linter/config/datamodel/config.py +17 -47
  47. linkml/linter/linter.py +2 -4
  48. linkml/linter/rules.py +34 -48
  49. linkml/reporting/__init__.py +2 -0
  50. linkml/reporting/model.py +9 -24
  51. linkml/transformers/relmodel_transformer.py +20 -33
  52. linkml/transformers/schema_renamer.py +14 -10
  53. linkml/utils/converter.py +15 -13
  54. linkml/utils/datautils.py +6 -22
  55. linkml/utils/datavalidator.py +2 -2
  56. linkml/utils/execute_tutorial.py +10 -12
  57. linkml/utils/generator.py +73 -91
  58. linkml/utils/helpers.py +4 -2
  59. linkml/utils/ifabsent_functions.py +23 -15
  60. linkml/utils/mergeutils.py +19 -35
  61. linkml/utils/rawloader.py +2 -6
  62. linkml/utils/schema_builder.py +31 -19
  63. linkml/utils/schema_fixer.py +28 -18
  64. linkml/utils/schemaloader.py +44 -89
  65. linkml/utils/schemasynopsis.py +49 -72
  66. linkml/utils/sqlutils.py +40 -30
  67. linkml/utils/typereferences.py +9 -6
  68. linkml/utils/validation.py +4 -5
  69. linkml/validators/__init__.py +2 -0
  70. linkml/validators/jsonschemavalidator.py +28 -18
  71. linkml/validators/sparqlvalidator.py +5 -15
  72. linkml/workspaces/datamodel/workspaces.py +13 -30
  73. linkml/workspaces/example_runner.py +74 -67
  74. {linkml-1.5.6.dist-info → linkml-1.5.7.dist-info}/METADATA +1 -1
  75. linkml-1.5.7.dist-info/RECORD +109 -0
  76. linkml-1.5.6.dist-info/RECORD +0 -109
  77. {linkml-1.5.6.dist-info → linkml-1.5.7.dist-info}/LICENSE +0 -0
  78. {linkml-1.5.6.dist-info → linkml-1.5.7.dist-info}/WHEEL +0 -0
  79. {linkml-1.5.6.dist-info → linkml-1.5.7.dist-info}/entry_points.txt +0 -0
@@ -1,18 +1,11 @@
1
- import logging
2
1
  import os
3
2
  from dataclasses import dataclass, field
4
3
  from enum import Enum
5
- from typing import List, Union, Optional
4
+ from typing import List, Optional, Union
6
5
 
7
6
  import click
8
7
  import pydantic
9
- from linkml_runtime.linkml_model.meta import (Annotation, ClassDefinition,
10
- ClassDefinitionName, Definition,
11
- DefinitionName, Element,
12
- EnumDefinition, SchemaDefinition,
13
- SlotDefinition,
14
- SlotDefinitionName,
15
- SubsetDefinition, TypeDefinition)
8
+ from linkml_runtime.linkml_model.meta import ClassDefinitionName, SlotDefinition
16
9
  from linkml_runtime.utils.formatutils import camelcase, underscore
17
10
  from linkml_runtime.utils.schemaview import SchemaView
18
11
 
@@ -21,6 +14,7 @@ from linkml.utils.generator import Generator, shared_arguments
21
14
 
22
15
  MERMAID_SERIALIZATION = str
23
16
 
17
+
24
18
  class Attribute(pydantic.BaseModel):
25
19
  datatype: str = "string"
26
20
  name: str = None
@@ -28,14 +22,15 @@ class Attribute(pydantic.BaseModel):
28
22
  comment: str = None
29
23
 
30
24
  def __str__(self):
31
- cmt = f'"{self.comment}"' if self.comment else ''
25
+ cmt = f'"{self.comment}"' if self.comment else ""
32
26
  return f' {self.datatype} {self.name} {self.key if self.key else ""} {cmt}'
33
27
 
34
28
 
35
29
  class IdentifyingType(str, Enum):
36
- """ Identifying types.
30
+ """Identifying types.
37
31
 
38
32
  See: https://mermaid.js.org/syntax/entityRelationshipDiagram.html#identification"""
33
+
39
34
  IDENTIFYING = "--"
40
35
  NON_IDENTIFYING = ".."
41
36
 
@@ -44,9 +39,10 @@ class IdentifyingType(str, Enum):
44
39
 
45
40
 
46
41
  class Cardinality(pydantic.BaseModel):
47
- """ Cardinality of a slot.
42
+ """Cardinality of a slot.
48
43
 
49
44
  See https://mermaid.js.org/syntax/entityRelationshipDiagram.html#relationship-syntax"""
45
+
50
46
  required: bool = True
51
47
  multivalued: bool = False
52
48
  is_left: bool = True
@@ -58,34 +54,37 @@ class Cardinality(pydantic.BaseModel):
58
54
  else:
59
55
  multivalued_char = "|"
60
56
  if self.is_left:
61
- return f'{multivalued_char}{required_char}'
57
+ return f"{multivalued_char}{required_char}"
62
58
  else:
63
- return f'{required_char}{multivalued_char}'
59
+ return f"{required_char}{multivalued_char}"
64
60
 
65
61
 
66
62
  class RelationshipType(pydantic.BaseModel):
67
- """ Relationship type.
63
+ """Relationship type.
68
64
  See https://mermaid.js.org/syntax/entityRelationshipDiagram.html#relationship-syntax"""
65
+
69
66
  left_cardinality: Cardinality
70
67
  identifying: IdentifyingType = IdentifyingType.IDENTIFYING
71
68
  right_cardinality: Cardinality = None
72
69
 
73
70
  def __str__(self):
74
- return f'{self.left_cardinality}{self.identifying}{self.right_cardinality}'
71
+ return f"{self.left_cardinality}{self.identifying}{self.right_cardinality}"
75
72
 
76
73
 
77
74
  class Entity(pydantic.BaseModel):
78
- """ Entity in an ER diagram."""
75
+ """Entity in an ER diagram."""
76
+
79
77
  name: str
80
78
  attributes: List[Attribute] = []
81
79
 
82
80
  def __str__(self):
83
- attrs = '\n'.join([str(a) for a in self.attributes])
84
- return f'{self.name} {{\n{attrs}\n}}'
81
+ attrs = "\n".join([str(a) for a in self.attributes])
82
+ return f"{self.name} {{\n{attrs}\n}}"
85
83
 
86
84
 
87
85
  class Relationship(pydantic.BaseModel):
88
- """ Relationship in an ER diagram."""
86
+ """Relationship in an ER diagram."""
87
+
89
88
  first_entity: str
90
89
  relationship_type: RelationshipType = None
91
90
  second_entity: str = None
@@ -97,13 +96,14 @@ class Relationship(pydantic.BaseModel):
97
96
 
98
97
  class ERDiagram(pydantic.BaseModel):
99
98
  """Represents an Diagram of Entities and Relationships"""
99
+
100
100
  entities: List[Entity] = []
101
101
  relationships: List[Relationship] = []
102
102
 
103
103
  def __str__(self):
104
- ents = '\n'.join([str(e) for e in self.entities])
105
- rels = '\n'.join([str(r) for r in self.relationships])
106
- return f'erDiagram\n{ents}\n\n{rels}\n'
104
+ ents = "\n".join([str(e) for e in self.entities])
105
+ rels = "\n".join([str(r) for r in self.relationships])
106
+ return f"erDiagram\n{ents}\n\n{rels}\n"
107
107
 
108
108
 
109
109
  @dataclass
@@ -135,7 +135,6 @@ class ERDiagramGenerator(Generator):
135
135
  no_types_dir: bool = field(default_factory=lambda: False)
136
136
  use_slot_uris: bool = field(default_factory=lambda: False)
137
137
 
138
-
139
138
  def __post_init__(self):
140
139
  self.schemaview = SchemaView(self.schema)
141
140
  super().__post_init__()
@@ -159,10 +158,12 @@ class ERDiagramGenerator(Generator):
159
158
  self.add_class(cn, diagram)
160
159
  return self.serialize_diagram(diagram)
161
160
 
162
- def serialize_classes(self,
163
- class_names: List[Union[str, ClassDefinitionName]],
164
- follow_references=False,
165
- max_hops: int = None) -> MERMAID_SERIALIZATION:
161
+ def serialize_classes(
162
+ self,
163
+ class_names: List[Union[str, ClassDefinitionName]],
164
+ follow_references=False,
165
+ max_hops: int = None,
166
+ ) -> MERMAID_SERIALIZATION:
166
167
  """
167
168
  Serialize a list of classes as an ER Diagram.
168
169
 
@@ -193,7 +194,7 @@ class ERDiagramGenerator(Generator):
193
194
  if rng in sv.all_classes():
194
195
  if follow_references or sv.is_inlined(slot):
195
196
  if rng not in visited:
196
- stack.append((rng, depth+1))
197
+ stack.append((rng, depth + 1))
197
198
  return self.serialize_diagram(diagram)
198
199
 
199
200
  def serialize_diagram(self, diagram: ERDiagram) -> str:
@@ -204,8 +205,8 @@ class ERDiagramGenerator(Generator):
204
205
  :return:
205
206
  """
206
207
  er = str(diagram)
207
- if self.format == 'markdown':
208
- return f'```mermaid\n{er}\n```\n'
208
+ if self.format == "markdown":
209
+ return f"```mermaid\n{er}\n```\n"
209
210
  else:
210
211
  return er
211
212
 
@@ -242,17 +243,15 @@ class ERDiagramGenerator(Generator):
242
243
  sv = self.schemaview
243
244
  rel_type = RelationshipType(
244
245
  right_cardinality=Cardinality(
245
- required=slot.required is True,
246
- multivalued=slot.multivalued is True,
247
- is_left=True
246
+ required=slot.required is True, multivalued=slot.multivalued is True, is_left=True
248
247
  ),
249
- left_cardinality=Cardinality(is_left=False)
248
+ left_cardinality=Cardinality(is_left=False),
250
249
  )
251
250
  rel = Relationship(
252
251
  first_entity=entity.name,
253
252
  relationship_type=rel_type,
254
253
  second_entity=camelcase(sv.get_class(slot.range).name),
255
- relationship_label=slot.name
254
+ relationship_label=slot.name,
256
255
  )
257
256
  diagram.relationships.append(rel)
258
257
 
@@ -266,28 +265,32 @@ class ERDiagramGenerator(Generator):
266
265
  """
267
266
  if self.exclude_attributes:
268
267
  return
269
- sv = self.schemaview
270
268
  dt = slot.range
271
269
  if slot.multivalued:
272
270
  # NOTE: mermaid does not support []s or *s in attribute types
273
- dt = f'{dt}List'
271
+ dt = f"{dt}List"
274
272
  attr = Attribute(name=underscore(slot.name), datatype=dt)
275
273
  entity.attributes.append(attr)
276
274
 
277
275
 
278
276
  @shared_arguments(ERDiagramGenerator)
279
- @click.option('--structural/--no-structural', default=True,
280
- help='If True, then only the tree_root and entities reachable from the root are drawn')
281
- @click.option('--exclude-attributes/--no-exclude-attributes', default=False,
282
- help='If True, do not include attributes in entities')
283
- @click.option('--follow-references/--no-follow-references', default=False,
284
- help='If True, follow references even if not inlined')
285
- @click.option('--max-hops', default=None, type=click.INT,
286
- help="Maximum number of hops")
287
- @click.option('--classes',
288
- '-c',
289
- multiple=True,
290
- help="List of classes to serialize")
277
+ @click.option(
278
+ "--structural/--no-structural",
279
+ default=True,
280
+ help="If True, then only the tree_root and entities reachable from the root are drawn",
281
+ )
282
+ @click.option(
283
+ "--exclude-attributes/--no-exclude-attributes",
284
+ default=False,
285
+ help="If True, do not include attributes in entities",
286
+ )
287
+ @click.option(
288
+ "--follow-references/--no-follow-references",
289
+ default=False,
290
+ help="If True, follow references even if not inlined",
291
+ )
292
+ @click.option("--max-hops", default=None, type=click.INT, help="Maximum number of hops")
293
+ @click.option("--classes", "-c", multiple=True, help="List of classes to serialize")
291
294
  @click.version_option(__version__, "-V", "--version")
292
295
  @click.command()
293
296
  def cli(yamlfile, classes: List[str], max_hops: Optional[int], follow_references: bool, **args):
@@ -303,7 +306,9 @@ def cli(yamlfile, classes: List[str], max_hops: Optional[int], follow_references
303
306
  **args,
304
307
  )
305
308
  if classes:
306
- print(gen.serialize_classes(classes, follow_references=follow_references, max_hops=max_hops))
309
+ print(
310
+ gen.serialize_classes(classes, follow_references=follow_references, max_hops=max_hops)
311
+ )
307
312
  else:
308
313
  print(gen.serialize())
309
314
 
@@ -1,19 +1,18 @@
1
- import os
2
1
  import logging
3
-
2
+ import os
4
3
  from dataclasses import dataclass
5
4
  from typing import List
6
5
 
7
6
  import click
8
-
9
7
  from linkml_runtime.utils.schemaview import SchemaView
10
- from linkml.utils.generator import Generator, shared_arguments
11
- from linkml._version import __version__
12
- from linkml.utils.helpers import convert_to_snake_case
13
8
  from openpyxl import Workbook
14
- from openpyxl.worksheet.worksheet import Worksheet
15
- from openpyxl.worksheet.datavalidation import DataValidation
16
9
  from openpyxl.utils import get_column_letter
10
+ from openpyxl.worksheet.datavalidation import DataValidation
11
+ from openpyxl.worksheet.worksheet import Worksheet
12
+
13
+ from linkml._version import __version__
14
+ from linkml.utils.generator import Generator, shared_arguments
15
+ from linkml.utils.helpers import convert_to_snake_case
17
16
 
18
17
 
19
18
  @dataclass
@@ -152,22 +151,17 @@ class ExcelGenerator(Generator):
152
151
  for cls_name, cls in sv.all_classes(imports=self.mergeimports).items():
153
152
  if not cls.mixin and not cls.abstract:
154
153
  slots = [
155
- s.name
156
- for s in sv.class_induced_slots(cls_name, imports=self.mergeimports)
154
+ s.name for s in sv.class_induced_slots(cls_name, imports=self.mergeimports)
157
155
  ]
158
156
  self.add_columns_to_worksheet(workbook, cls_name, slots)
159
157
 
160
- enum_list = [
161
- e_name for e_name, _ in sv.all_enums(imports=self.mergeimports).items()
162
- ]
158
+ enum_list = [e_name for e_name, _ in sv.all_enums(imports=self.mergeimports).items()]
163
159
  for cls_name, cls in sv.all_classes(imports=self.mergeimports).items():
164
160
  if not cls.mixin and not cls.abstract:
165
161
  for s in sv.class_induced_slots(cls_name, imports=self.mergeimports):
166
162
  if s.range in enum_list:
167
163
  pv_list = []
168
- for pv_name, _ in sv.get_enum(
169
- s.range
170
- ).permissible_values.items():
164
+ for pv_name, _ in sv.get_enum(s.range).permissible_values.items():
171
165
  pv_list.append(pv_name)
172
166
  self.column_enum_validation(workbook, cls_name, s.name, pv_list)
173
167
  self.logger.info(f"The Excel workbook has been written to {self.output}")
@@ -1,23 +1,17 @@
1
1
  import logging
2
2
  import os
3
- from copy import deepcopy
4
3
  from dataclasses import dataclass
5
- from pathlib import Path
6
- from typing import (Callable, Dict, Iterator, List, Optional, Set, TextIO,
7
- Tuple, Union)
4
+ from typing import List, Optional
8
5
 
9
6
  import click
10
- from jinja2 import Environment, FileSystemLoader, Template
11
- from linkml_runtime.dumpers import yaml_dumper
12
- from linkml_runtime.linkml_model.meta import (Annotation, ClassDefinition,
13
- ClassDefinitionName, Definition,
14
- DefinitionName, Element,
15
- EnumDefinition, SchemaDefinition,
16
- SlotDefinition,
17
- SlotDefinitionName,
18
- TypeDefinition)
7
+ from jinja2 import Template
8
+ from linkml_runtime.linkml_model.meta import (
9
+ ClassDefinition,
10
+ ClassDefinitionName,
11
+ Element,
12
+ SlotDefinition,
13
+ )
19
14
  from linkml_runtime.utils.formatutils import camelcase, underscore
20
- from linkml_runtime.utils.schemaview import SchemaView
21
15
 
22
16
  from linkml._version import __version__
23
17
  from linkml.utils.generator import Generator, shared_arguments
@@ -82,7 +76,7 @@ type {{gen.name(c)}} struct {
82
76
  }
83
77
 
84
78
  {% endfor %}
85
- """
79
+ """ # noqa: E101, W191
86
80
 
87
81
 
88
82
  @dataclass
@@ -103,9 +97,7 @@ class GolangGenerator(Generator):
103
97
  :return:
104
98
  """
105
99
  template_obj = Template(default_template)
106
- out_str = template_obj.render(
107
- gen=self, schema=self.schemaview.schema, view=self.schemaview
108
- )
100
+ out_str = template_obj.render(gen=self, schema=self.schemaview.schema, view=self.schemaview)
109
101
  return out_str
110
102
 
111
103
  def name(self, element: Element) -> str:
@@ -148,9 +140,7 @@ class GolangGenerator(Generator):
148
140
  else:
149
141
  return None
150
142
 
151
- def get_identifier_or_key_slot(
152
- self, cn: ClassDefinitionName
153
- ) -> Optional[SlotDefinition]:
143
+ def get_identifier_or_key_slot(self, cn: ClassDefinitionName) -> Optional[SlotDefinition]:
154
144
  sv = self.schemaview
155
145
  id_slot = sv.get_identifier_slot(cn)
156
146
  if id_slot:
@@ -8,11 +8,10 @@ See the golr-views directory in this repo for examples
8
8
  """
9
9
  import os
10
10
  from dataclasses import dataclass
11
- from typing import List, Optional, TextIO, Union
11
+ from typing import List, Optional
12
12
 
13
13
  import click
14
- from linkml_runtime.linkml_model.meta import (ClassDefinition,
15
- SchemaDefinition, SlotDefinition)
14
+ from linkml_runtime.linkml_model.meta import ClassDefinition, SlotDefinition
16
15
  from linkml_runtime.utils.formatutils import underscore
17
16
  from linkml_runtime.utils.metamodelcore import empty_list
18
17
  from linkml_runtime.utils.yamlutils import YAMLRoot, as_yaml
@@ -43,7 +42,6 @@ class GOLRClass(YAMLRoot):
43
42
 
44
43
  @dataclass
45
44
  class GolrSchemaGenerator(Generator):
46
-
47
45
  # ClassVars
48
46
  generatorname = os.path.basename(__file__)
49
47
  generatorversion = "0.1.1"
@@ -57,7 +55,6 @@ class GolrSchemaGenerator(Generator):
57
55
  directory: str = None
58
56
  class_obj: Optional[GOLRClass] = None
59
57
 
60
-
61
58
  def generate_header(self):
62
59
  headers = [f"# metamodel_version: {self.schema.metamodel_version}"]
63
60
  if self.schema.version:
@@ -106,17 +103,11 @@ class GolrSchemaGenerator(Generator):
106
103
 
107
104
  @shared_arguments(GolrSchemaGenerator)
108
105
  @click.command()
109
- @click.option(
110
- "--dir", "-d", default="golr-views", show_default=True, help="Output directory"
111
- )
106
+ @click.option("--dir", "-d", default="golr-views", show_default=True, help="Output directory")
112
107
  @click.version_option(__version__, "-V", "--version")
113
108
  def cli(yamlfile, dir=None, **args):
114
109
  """Generate GOLR representation of a LinkML model"""
115
- print(
116
- GolrSchemaGenerator(yamlfile, directory=dir, **args).serialize(
117
- directory=dir, **args
118
- )
119
- )
110
+ print(GolrSchemaGenerator(yamlfile, directory=dir, **args).serialize(directory=dir, **args))
120
111
 
121
112
 
122
113
  if __name__ == "__main__":
@@ -1,10 +1,8 @@
1
1
  import os
2
2
  from dataclasses import dataclass
3
- from typing import TextIO, Union
4
3
 
5
4
  import click
6
- from linkml_runtime.linkml_model.meta import (ClassDefinition,
7
- SchemaDefinition, SlotDefinition)
5
+ from linkml_runtime.linkml_model.meta import ClassDefinition, SlotDefinition
8
6
  from linkml_runtime.utils.formatutils import camelcase, lcamelcase
9
7
 
10
8
  from linkml._version import __version__
@@ -13,7 +11,6 @@ from linkml.utils.generator import Generator, shared_arguments
13
11
 
14
12
  @dataclass
15
13
  class GraphqlGenerator(Generator):
16
-
17
14
  # ClassVars
18
15
  generatorname = os.path.basename(__file__)
19
16
  generatorversion = "0.1.1"
@@ -33,14 +30,9 @@ class GraphqlGenerator(Generator):
33
30
  print(f"# version: {self.schema.version}")
34
31
 
35
32
  def visit_class(self, cls: ClassDefinition) -> bool:
36
- etype = (
37
- "interface" if (cls.abstract or cls.mixin) and not cls.mixins else "type"
38
- )
33
+ etype = "interface" if (cls.abstract or cls.mixin) and not cls.mixins else "type"
39
34
  mixins = ", ".join([camelcase(mixin) for mixin in cls.mixins])
40
- print(
41
- f"{etype} {camelcase(cls.name)}"
42
- + (f" implements {mixins}" if mixins else "")
43
- )
35
+ print(f"{etype} {camelcase(cls.name)}" + (f" implements {mixins}" if mixins else ""))
44
36
  print(" {")
45
37
  return True
46
38
 
@@ -1,13 +1,13 @@
1
+ import importlib.util
1
2
  import os
2
- from dataclasses import field, dataclass
3
+ from dataclasses import dataclass, field
3
4
  from typing import Optional
5
+
4
6
  import click
5
- import importlib.util
6
7
  from jinja2 import Environment, FileSystemLoader, Template
7
8
  from linkml_runtime.linkml_model.meta import TypeDefinition
8
9
 
9
10
  from linkml._version import __version__
10
- from linkml.generators import JAVA_GEN_VERSION
11
11
  from linkml.generators.oocodegen import OOCodeGenerator
12
12
  from linkml.utils.generator import shared_arguments
13
13
 
@@ -37,7 +37,7 @@ public{% if cls.abstract %} abstract{% endif %} class {{ cls.name }} {% if cls.i
37
37
  private {{f.range}} {{ f.name }};
38
38
  {%- endfor %}
39
39
 
40
- }"""
40
+ }""" # noqa: E501
41
41
 
42
42
  TYPEMAP = {
43
43
  "xsd:string": "String",
@@ -52,13 +52,8 @@ TYPEMAP = {
52
52
  "xsd:decimal": "BigDecimal",
53
53
  }
54
54
 
55
- TYPE_DEFAULTS = {
56
- "boolean": "false",
57
- "int": "0",
58
- "float": "0f",
59
- "double": "0d",
60
- "String": '""'
61
- }
55
+ TYPE_DEFAULTS = {"boolean": "false", "int": "0", "float": "0f", "double": "0d", "String": '""'}
56
+
62
57
 
63
58
  @dataclass
64
59
  class JavaGenerator(OOCodeGenerator):
@@ -73,7 +68,7 @@ class JavaGenerator(OOCodeGenerator):
73
68
 
74
69
  # ClassVars
75
70
  generatorname = os.path.basename(__file__)
76
- generatorversion = JAVA_GEN_VERSION
71
+ generatorversion = "0.0.1"
77
72
  valid_formats = ["java"]
78
73
 
79
74
  # ObjectVars
@@ -143,9 +138,7 @@ class JavaGenerator(OOCodeGenerator):
143
138
  help="Output directory for individually generated class files",
144
139
  )
145
140
  @click.option("--package", help="Package name where relevant for generated class files")
146
- @click.option(
147
- "--template-file", help="Optional jinja2 template to use for class generation"
148
- )
141
+ @click.option("--template-file", help="Optional jinja2 template to use for class generation")
149
142
  @click.option(
150
143
  "--generate-records/--no-generate-records",
151
144
  default=False,
@@ -5,15 +5,13 @@ Generate JSON-LD contexts
5
5
  import os
6
6
  import re
7
7
  from dataclasses import dataclass, field
8
- from typing import Optional, Set, TextIO, Union, Dict
8
+ from typing import Dict, Optional, Set
9
9
 
10
10
  import click
11
11
  from jsonasobj2 import JsonObj, as_json
12
- from linkml_runtime.linkml_model.meta import (ClassDefinition, Definition,
13
- Element, SchemaDefinition,
14
- SlotDefinition)
12
+ from linkml_runtime.linkml_model.meta import ClassDefinition, SlotDefinition
15
13
  from linkml_runtime.linkml_model.types import SHEX
16
- from linkml_runtime.utils.formatutils import be, camelcase, underscore
14
+ from linkml_runtime.utils.formatutils import camelcase, underscore
17
15
  from rdflib import SKOS, XSD
18
16
 
19
17
  from linkml._version import __version__
@@ -32,7 +30,6 @@ ENUM_CONTEXT = {
32
30
 
33
31
  @dataclass
34
32
  class ContextGenerator(Generator):
35
-
36
33
  # ClassVars
37
34
  generatorname = os.path.basename(__file__)
38
35
  generatorversion = "0.1.1"
@@ -60,9 +57,7 @@ class ContextGenerator(Generator):
60
57
  "Schema text must be supplied to context generator. Preparsed schema will not work"
61
58
  )
62
59
 
63
- def visit_schema(
64
- self, base: Optional[str] = None, output: Optional[str] = None, **_
65
- ):
60
+ def visit_schema(self, base: Optional[str] = None, output: Optional[str] = None, **_):
66
61
  # Add any explicitly declared prefixes
67
62
  for prefix in self.schema.prefixes.values():
68
63
  self.emit_prefixes.add(prefix.prefix_prefix)
@@ -104,20 +99,6 @@ class ContextGenerator(Generator):
104
99
  comments.description = "Auto generated by LinkML jsonld context generator"
105
100
  comments.generation_date = self.schema.generation_date
106
101
  comments.source = self.schema.source_file
107
- #
108
- # comments = f"""Auto generated from {self.schema.source_file} by {self.generatorname} version: {self.generatorversion}"""
109
- # if self.schema.generation_date:
110
- # comments += f"""
111
- #
112
- # Schema: {self.schema.name}
113
- # metamodel version: {self.schema.metamodel_version}
114
- # model version: {self.schema.version if self.schema.version else None}
115
- # """
116
- # comments += f"""
117
- # id: {self.schema.id}
118
- # description: {be(self.schema.description)}
119
- # license: {be(self.schema.license)}
120
- # """
121
102
  context.comments = comments
122
103
  context_content = {}
123
104
  if base:
@@ -155,15 +136,9 @@ class ContextGenerator(Generator):
155
136
  cn = camelcase(cls.name)
156
137
  self.add_mappings(cls)
157
138
  cls_uri_prefix, cls_uri_suffix = self.namespaces.prefix_suffix(cls.class_uri)
158
- if (
159
- not self.default_ns
160
- or not cls_uri_prefix
161
- or cls_uri_prefix != self.default_ns
162
- ):
139
+ if not self.default_ns or not cls_uri_prefix or cls_uri_prefix != self.default_ns:
163
140
  class_def["@id"] = (
164
- (cls_uri_prefix + ":" + cls_uri_suffix)
165
- if cls_uri_prefix
166
- else cls.class_uri
141
+ (cls_uri_prefix + ":" + cls_uri_suffix) if cls_uri_prefix else cls.class_uri
167
142
  )
168
143
  if cls_uri_prefix:
169
144
  self.add_prefix(cls_uri_prefix)
@@ -198,11 +173,7 @@ class ContextGenerator(Generator):
198
173
  else:
199
174
  slot_def["@type"] = range_type.uri
200
175
  slot_prefix = self.namespaces.prefix_for(slot.slot_uri)
201
- if (
202
- not self.default_ns
203
- or not slot_prefix
204
- or slot_prefix != self.default_ns
205
- ):
176
+ if not self.default_ns or not slot_prefix or slot_prefix != self.default_ns:
206
177
  slot_def["@id"] = slot.slot_uri
207
178
  if slot_prefix:
208
179
  self.add_prefix(slot_prefix)
@@ -1,7 +1,6 @@
1
1
  """ Generate JSONld
2
2
 
3
3
  """
4
- import logging
5
4
  import os
6
5
  from copy import deepcopy
7
6
  from dataclasses import dataclass
@@ -9,14 +8,18 @@ from typing import Any, Optional
9
8
 
10
9
  import click
11
10
  from jsonasobj2 import as_json, items, loads
12
- from linkml_runtime.linkml_model.meta import (ClassDefinition,
13
- ClassDefinitionName, ElementName,
14
- SchemaDefinition, SlotDefinition,
15
- SlotDefinitionName,
16
- SubsetDefinition,
17
- SubsetDefinitionName,
18
- TypeDefinition,
19
- TypeDefinitionName)
11
+ from linkml_runtime.linkml_model.meta import (
12
+ ClassDefinition,
13
+ ClassDefinitionName,
14
+ ElementName,
15
+ SchemaDefinition,
16
+ SlotDefinition,
17
+ SlotDefinitionName,
18
+ SubsetDefinition,
19
+ SubsetDefinitionName,
20
+ TypeDefinition,
21
+ TypeDefinitionName,
22
+ )
20
23
  from linkml_runtime.utils.formatutils import camelcase, underscore
21
24
  from linkml_runtime.utils.yamlutils import YAMLRoot
22
25
 
@@ -35,6 +38,7 @@ class JSONLDGenerator(Generator):
35
38
 
36
39
  Note: this is distinct from :ref:`ContextGenerator`, which generates a JSON-LD context
37
40
  """
41
+
38
42
  # ClassVars
39
43
  generatorname = os.path.basename(__file__)
40
44
  generatorversion = "0.0.2"
@@ -160,9 +164,7 @@ class JSONLDGenerator(Generator):
160
164
  ).serialize()
161
165
  add_prefixes_json = loads(add_prefixes)
162
166
  context = [METAMODEL_CONTEXT_URI, add_prefixes_json["@context"]]
163
- elif isinstance(
164
- context, str
165
- ): # Some of the older code doesn't do multiple contexts
167
+ elif isinstance(context, str): # Some of the older code doesn't do multiple contexts
166
168
  context = [context]
167
169
  elif isinstance(context, tuple):
168
170
  context = list(context)