generated from MinBZK/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6175ac
commit 8de085a
Showing
19 changed files
with
22,611 additions
and
2,146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,86 @@ | ||
import logging | ||
|
||
from amt.schema.measure import MeasureTask | ||
from amt.schema.requirement import RequirementTask | ||
from amt.schema.requirement import Requirement, RequirementTask | ||
from amt.schema.system_card import AiActProfile | ||
from amt.services.measures import create_measures_service | ||
from amt.services.requirements import create_requirements_service | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_requirements(ai_act_profile: AiActProfile) -> list[RequirementTask]: | ||
requirements: list[RequirementTask] = [] | ||
def is_requirement_applicable(requirement: Requirement, ai_act_profile: AiActProfile) -> bool: | ||
""" | ||
Determine if a specific requirement is applicable to a given AI Act profile. | ||
return requirements | ||
Evaluation Criteria: | ||
- Always applicable requirements automatically return True. | ||
- For the 'role' attribute, handles compound values like | ||
"gebruiksverantwoordelijke + aanbieder". | ||
- For the 'systemic_risk' attribute, handles the old name 'publication_category'. | ||
- A requirement is applicable if all specified attributes match or have no | ||
specific restrictions. | ||
""" | ||
if requirement.always_applicable == 1: | ||
return True | ||
|
||
# We can assume the ai_act_profile field always contains exactly 1 element. | ||
requirement_profile = requirement.ai_act_profile[0] | ||
comparison_attrs = ( | ||
"type", | ||
"risk_category", | ||
"type", | ||
"open_source", | ||
"systemic_risk", | ||
"transparency_obligations", | ||
) | ||
|
||
def get_requirements_and_measures( | ||
for attr in comparison_attrs: | ||
requirement_attr_values = getattr(requirement_profile, attr, []) | ||
|
||
if not requirement_attr_values: | ||
continue | ||
|
||
input_value = _parse_attribute_values(attr, ai_act_profile) | ||
|
||
if not input_value & {attr_value.value for attr_value in requirement_attr_values}: | ||
return False | ||
|
||
return True | ||
|
||
|
||
async def get_requirements_and_measures( | ||
ai_act_profile: AiActProfile, | ||
) -> tuple[ | ||
list[RequirementTask], | ||
list[MeasureTask], | ||
]: | ||
# TODO (Robbert): the body of this method will be added later (another ticket) | ||
measure_card: list[MeasureTask] = [] | ||
requirements_card: list[RequirementTask] = [] | ||
|
||
return requirements_card, measure_card | ||
) -> tuple[list[RequirementTask], list[MeasureTask]]: | ||
requirements_service = create_requirements_service() | ||
measure_service = create_measures_service() | ||
all_requirements = await requirements_service.fetch_requirements() | ||
|
||
applicable_requirements: list[RequirementTask] = [] | ||
applicable_measures: list[MeasureTask] = [] | ||
measure_urns: set[str] = set() | ||
|
||
for requirement in all_requirements: | ||
if is_requirement_applicable(requirement, ai_act_profile): | ||
applicable_requirements.append(RequirementTask(urn=requirement.urn, version=requirement.schema_version)) | ||
|
||
for measure_urn in requirement.links: | ||
if measure_urn not in measure_urns: | ||
measure = await measure_service.fetch_measures(measure_urn) | ||
applicable_measures.append(MeasureTask(urn=measure_urn, version=measure[0].schema_version)) | ||
measure_urns.add(measure_urn) | ||
|
||
return applicable_requirements, applicable_measures | ||
|
||
|
||
def _parse_attribute_values(attr: str, ai_act_profile: AiActProfile) -> set[str]: | ||
""" | ||
Helper function needed in `is_requirement_applicable`, handling special case for 'role' | ||
and 'publication_category'. | ||
""" | ||
if attr == "role": | ||
return {s.strip() for s in getattr(ai_act_profile, attr, "").split("+")} | ||
if attr == "risk_category": | ||
return {getattr(ai_act_profile, "publication_category", "")} | ||
|
||
return {getattr(ai_act_profile, attr, "")} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.