@@ -45,7 +45,7 @@ def are_ids_unique(self, gdf):
4545
4646 return is_valid , list (duplicates )
4747
48- def validate (self ) -> ValidationResult :
48+ def validate (self , max_errors = 20 ) -> ValidationResult :
4949 try :
5050 # Extract the zipfile
5151 zip_handler = ZipFileHandler (self .zipfile_path )
@@ -62,7 +62,8 @@ def validate(self) -> ValidationResult:
6262 return ValidationResult (False , self .errors )
6363 for file in validator .files :
6464 file_path = os .path .join (file )
65- is_valid = self .validate_osw_errors (file_path )
65+ if not self .validate_osw_errors (file_path , max_errors ):
66+ break
6667
6768 if self .errors :
6869 zip_handler .remove_extracted_files ()
@@ -119,7 +120,7 @@ def validate(self) -> ValidationResult:
119120
120121 # Geometry validation: check geometry type in each file and test if coordinates make a shape that is reasonable geometric shape according to the Simple Feature Access standard
121122 for osw_file in OSW_dataset :
122- invalid_geojson = OSW_dataset [osw_file ][(OSW_dataset [osw_file ].geometry .type != OSW_dataset_files [osw_file ]['geometry' ]) | (OSW_dataset [osw_file ].is_valid == False )]
123+ invalid_geojson = OSW_dataset [osw_file ][(OSW_dataset [osw_file ].geometry .type != OSW_dataset_files [osw_file ]['geometry' ]) | (OSW_dataset [osw_file ].is_valid == False )]
123124 is_valid = len (invalid_geojson ) == 0
124125 if not is_valid :
125126 self .errors .append (f"Invalid { osw_file } geometries found, id's of invalid geometries: { set (invalid_geojson ['_id' ])} " )
@@ -128,7 +129,7 @@ def validate(self) -> ValidationResult:
128129 for file in validator .externalExtensions :
129130 file_path = os .path .join (file )
130131 extensionFile = gpd .read_file (file_path )
131- invalid_geojson = extensionFile [extensionFile .is_valid == False ]
132+ invalid_geojson = extensionFile [extensionFile .is_valid == False ]
132133 is_valid = len (invalid_geojson ) == 0
133134 if not is_valid :
134135 self .errors .append (f"Invalid geometries found in extension file { file } , list of invalid geometries: { invalid_geojson .to_json ()} " )
@@ -147,14 +148,17 @@ def load_osw_file(self, graph_geojson_path: str) -> Dict[str, Any]:
147148 with open (graph_geojson_path , 'r' ) as file :
148149 return json .load (file )
149150
150- def validate_osw_errors (self , file_path : str ) -> bool :
151+ def validate_osw_errors (self , file_path : str , max_errors : int ) -> bool :
151152 '''Validate OSW Data against the schema and process all errors'''
152153 geojson_data = self .load_osw_file (file_path )
153154 validator = jsonschema .Draft7Validator (self .load_osw_schema (self .schema_file_path ))
154155 errors = list (validator .iter_errors (geojson_data ))
155156
156157 if errors :
157- for error in errors :
158- self .errors .append (f'Validation error: { error .message } ' )
158+ for index , error in enumerate (errors ):
159+ if index < max_errors :
160+ self .errors .append (f'Validation error: { error .message } ' )
161+ if len (self .errors ) == max_errors :
162+ break
159163 return False
160164 return True
0 commit comments