Skip to content

Commit

Permalink
validate many is None for run_many usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ssssarah committed Aug 16, 2024
1 parent ff9284b commit 44b419b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions kgforge/specializations/models/demo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Dict, List, Optional, Tuple, Union, Any, Type

from kgforge.core.archetypes.store import Store
from kgforge.core.commons.execution import not_supported
from kgforge.core.commons.execution import not_supported, _run_many
from kgforge.core.resource import Resource
from kgforge.core.archetypes.mapping import Mapping
from kgforge.core.archetypes.model import Model
Expand Down Expand Up @@ -87,17 +87,21 @@ def mapping(self, entity: str, source: str, type: Type[Mapping]) -> Mapping:

# Validation.

def _validate(self, resource: Resource, type_: str, inference: str, raise_: bool):
type_expanded = self.service.expand(type_)

schema = self.service.schema(type_expanded)
result, reason = self.service.check(resource, schema)
if reason is not None and raise_:
raise ValidationError(reason)

def _validate_one(self, resource: Resource, type_: str, inference: str) -> None:
"""
Validates the model against a given type provided by type_ parameter.
If type_ is None then it looks for type attribute in resource.
If the resource is not typed, AttributeError is raised
"""
type_expanded = self.service.expand(type_)
schema = self.service.schema(type_expanded)
result, reason = self.service.check(resource, schema)
if reason is not None:
raise ValidationError(reason)
return self._validate(resource, type_, inference, True)

# Utils.

Expand All @@ -124,12 +128,7 @@ def _generate_context(self) -> Dict:
def schema_id(self, type: str) -> str:
raise not_supported()

def _validate_many(
self, resources: List[Resource], type_: str, inference: str
) -> None:

for resource in resources:
self._validate_one(resource, type_, inference)
_validate_many = None


class ModelLibrary:
Expand Down

0 comments on commit 44b419b

Please sign in to comment.