[docs]classNamespace:""" Represents a namespace in RDF4J. """_prefix:str_namespace:_Namespacedef__init__(self,prefix:str,namespace:str):""" Initializes a new Namespace. Args: prefix (str): The prefix of the namespace. namespace (str): The namespace URI. """self._prefix=prefixself._namespace=_Namespace(namespace)
[docs]@classmethoddeffrom_sparql_query_solution(cls,query_solution:og.QuerySolution)->"Namespace":""" Creates a Namespace from a binding. Args: binding (Mapping[Variable, Identifier]): The binding. Returns: Namespace: The created Namespace. """prefix:og.Literal=query_solution[og.Variable("prefix")]namespace:og.NamedNode=query_solution[og.Variable("namespace")]returncls(prefix=prefix.value,namespace=namespace.value,)
def__str__(self):""" Returns a string representation of the Namespace. Returns: str: A string representation of the Namespace. """returnf"{self._prefix}: {self._namespace}"def__repr__(self):""" Returns a string representation of the Namespace. Returns: str: A string representation of the Namespace. """returnf"Namespace(prefix={self._prefix}, namespace={self._namespace})"def__contains__(self,item:str)->bool:""" Checks if the Namespace contains a given item. Args: item (str): The item to check. Returns: bool: True if the Namespace contains the item, False otherwise. """returniteminself._namespace
[docs]defterm(self,name:str)->IRI:""" Returns the IRI for a given term. Args: name (str): The term name. Returns: IRI: The IRI for the term. """returnself._namespace.term(name)
def__getitem__(self,item:str)->IRI:""" Returns the IRI for a given term. Args: item (str): The term name. Returns: IRI: The IRI for the term. """returnself.term(item)def__getattr__(self,item:str)->IRI:""" Returns the IRI for a given term. Args: item (str): The term name. Returns: IRI: The IRI for the term. """ifitem.startswith("__"):raiseAttributeErrorreturnself.term(item)@propertydefnamespace(self)->IRI:""" Returns the namespace URI. Returns: IRI: The namespace URI. """returnIRI(self._namespace)@propertydefprefix(self)->str:""" Returns the prefix of the namespace. Returns: str: The prefix of the namespace. """returnself._prefix