import uuid from typing import Optional, Union # Values for `..#ee-component-type` facts CAPACITOR = "http://purl.org/ee/part-type#capacitor" RESISTOR = "http://purl.org/ee/part-type#resistor" DIODE = "http://purl.org/ee/part-type#diode" INDUCTOR = "http://purl.org/ee/part-type#inductor" CRYSTAL = "http://purl.org/ee/part-type#inductor" TRANSISTOR = "http://purl.org/ee/part-type#transistor" NET_TIE = "http://purl.org/ee/part-type#net-tie" TEST_POINT = "http://purl.org/ee/part-type#test-point" MOUNTING_HOLE = "http://purl.org/ee/part-type#mounting-hole" _DIGIKEY_FACT_KEY_PREFIX = "http://purl.org/ee/digikey-fact-key#" def make_digikey_fact_key(key: int) -> str: return _DIGIKEY_FACT_KEY_PREFIX + str(key) def is_digikey_fact_key(uri: str) -> bool: return uri.startswith(_DIGIKEY_FACT_KEY_PREFIX) def parse_digikey_fact_key(uri: str) -> Optional[int]: if uri.startswith(_DIGIKEY_FACT_KEY_PREFIX): try: return int(uri[len(_DIGIKEY_FACT_KEY_PREFIX):]) except ValueError: pass _FACT_KEY_PREFIX = "http://purl.org/trygvis/ee/fact-key#" def make_fact_key(name: str) -> str: return "{}{}".format(_FACT_KEY_PREFIX, name) def make_schematic_part_uri(project: Union[str, uuid.UUID], schematic_reference: str) -> str: return "http://purl.org/trygvis/ee/project/{}#{}".format(project, schematic_reference)