from typing import Optional 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" DIGIKEY_URI = "https://digikey.com" _DIGIKEY_FACT_KEY_PREFIX = "http://purl.org/trygvis/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)