1+ """Converts a schema sheet into a LinkML schema"""
12import codecs
23import contextlib
3- import os
44import sys
55import csv
66import logging
7- import tempfile
87from urllib .request import urlopen
98from copy import copy
109
1312from dataclasses import dataclass
1413from typing import List , Union , Any , Dict , Tuple , Generator , TextIO
1514
16- from linkml_runtime .dumpers import yaml_dumper
1715from linkml_runtime .linkml_model import Annotation , Example
1816from linkml_runtime .linkml_model .meta import SchemaDefinition , ClassDefinition , Prefix , \
1917 SlotDefinition , EnumDefinition , PermissibleValue , SubsetDefinition , TypeDefinition , Element , Setting
@@ -35,24 +33,40 @@ class SchemaSheetRowException(Exception):
3533@dataclass
3634class SchemaMaker :
3735 """
38- Engine for making LinkML schemas from Schema Sheets
36+ Engine for making LinkML schemas from Schema Sheets.
3937 """
4038 schema : SchemaDefinition = None
39+ """Generated schema."""
40+
4141 element_map : Dict [Tuple [str , str ], Element ] = None
42+
4243 metamodel : SchemaView = None
44+ """Schema describing LinkML elements."""
45+
4346 cardinality_vocabulary : str = None
47+
4448 use_attributes : bool = None
49+ """If True, use attributes instead of slots."""
50+
4551 default_name : str = None
52+ """Default name for the schema."""
53+
4654 unique_slots : bool = None
55+ """If True, slots are unique across classes."""
56+
4757 gsheet_id : str = None
58+ """Google sheet ID."""
59+
4860 table_config_path : str = None
61+ """Path to table configuration file."""
62+
4963 base_schema_path : str = None
5064
5165 def create_schema (self , csv_files : Union [str , List [str ]], ** kwargs ) -> SchemaDefinition :
5266 """
53- Create a LinkML schema from a collection of Schema Sheets
67+ Create a LinkML schema from one or more Schema Sheets.
5468
55- :param csv_files: schema sheets
69+ :param csv_files: schema sheets paths
5670 :param kwargs:
5771 :return: generated schema
5872 """
@@ -68,7 +82,7 @@ def create_schema(self, csv_files: Union[str, List[str]], **kwargs) -> SchemaDef
6882 if not isinstance (csv_files , list ):
6983 csv_files = [csv_files ]
7084 for f in csv_files :
71- self .merge_sheet (f , ** kwargs )
85+ self .load_and_merge_sheet (f , ** kwargs )
7286 self .schema .imports .append ('linkml:types' )
7387 self .schema .prefixes ['linkml' ] = Prefix ('linkml' , 'https://w3id.org/linkml/' )
7488 self ._tidy_slot_usage ()
@@ -83,7 +97,7 @@ def create_schema(self, csv_files: Union[str, List[str]], **kwargs) -> SchemaDef
8397
8498 def _tidy_slot_usage (self ):
8599 """
86- removes all slot usages marked inapplicable
100+ removes all slot usages marked inapplicable.
87101
88102 :return:
89103 """
@@ -93,9 +107,9 @@ def _tidy_slot_usage(self):
93107 c .slots .remove (sn )
94108 del c .slot_usage [sn ]
95109
96- def merge_sheet (self , file_name : str , delimiter = '\t ' ) -> None :
110+ def load_and_merge_sheet (self , file_name : str , delimiter = '\t ' ) -> None :
97111 """
98- Merge information from the given schema sheet into the current schema
112+ Merge information from the given schema sheet into the current schema.
99113
100114 :param file_name: schema sheet
101115 :param delimiter: default is tab
0 commit comments