def tune_token(a_token, allow_untyped_numbers=False, raise_error_if_no_corners=True, base_namespace=None): if a_token.startswith("<"): return IRI(remove_corners(a_uri=a_token, raise_error_if_no_corners=raise_error_if_no_corners)) elif a_token.startswith('"'): content, elem_type = parse_literal(an_elem=a_token, base_namespace=base_namespace) return Literal(content=content, elem_type=elem_type) elif a_token.startswith("_:"): return BNode(identifier=a_token[2:]) elif a_token.strip() == "[]": return BNode(identifier=a_token) if allow_untyped_numbers: try: candidate_float = float(a_token) if _is_integer(candidate_float): return Literal(content=a_token.strip(), elem_type=INTEGER_TYPE) return Literal(content=a_token.strip(), elem_type=FLOAT_TYPE) except: pass content, elem_type = parse_unquoted_literal(a_token) return Literal(content=content, elem_type=elem_type)
def tune_subj(a_token, raise_error_if_no_corners=True): if a_token.startswith("<"): return IRI(remove_corners(a_uri=a_token, raise_error_if_no_corners=raise_error_if_no_corners)) elif a_token.startswith("_:"): return BNode(identifier=a_token[2:]) elif a_token.strip() == "[]": return BNode(identifier=a_token) else: # ??? raise ValueError("Unrecognized token in subject position: " + a_token)
def tune_subj(a_token): if a_token.startswith("<"): return IRI(remove_corners(a_token)) elif a_token.startswith('"'): content, elem_type = parse_literal(a_token) return Literal(content=content, elem_type=elem_type) elif a_token.startswith("_:"): return BNode(identifier=a_token[2:]) elif a_token.strip() == "[]": return BNode(identifier=a_token) else: # ??? content, elem_type = parse_unquoted_literal(a_token) return Literal(content=content, elem_type=elem_type)
def create_IRI_from_string(an_str): return IRI(content=an_str)