def normv(v): if is_list_or_tuple(v): return [normv(_) for _ in v] if isinstance(v, dict): return {k: normv(v) for k, v in v.items()} if isinstance(v, str) and v.startswith('http'): # needed for loading from json that has been serialized # rather than from our internal representation # probably better to centralized the reload ... v = OntTerm(v) return v.asCell() if isinstance( v, rdflib.URIRef): # FIXME why is this getting converted early? ot = OntTerm(v) return ot.asCell() if isinstance(v, ProtcurExpression): return str(v) # FIXME for xml? if isinstance(v, Quantity): return str(v) elif isinstance(v, pathlib.Path): return str(v) elif isinstance(v, idlib.Stream): return v.asCell() #elif isinstance(v, list) or isinstance(v, str): #return v elif isinstance(v, BaseException): return repr(v) else: #loge.debug(repr(v)) return v
def normv(v): if is_list_or_tuple(v): return [normv(_) for _ in v] elif isinstance(v, dict): return {k:normv(v) for k, v in v.items()} elif isinstance(v, str) and v.startswith('http'): # needed for loading from json that has been serialized # rather than from our internal representation # probably better to centralized the reload ... # XXX NOTE these days this will only happen if someone # supplies us with a uri in a field where we aren't # expecting one, in which case we should just return it try: v = OntTerm(v) return v.asCell() except Exception as e: loge.error(f'something went wrong with {v}') loge.exception(e) return v #raise e elif isinstance(v, rdflib.URIRef): # FIXME why is this getting converted early? ot = OntTerm(v) return ot.asCell() elif isinstance(v, ProtcurExpression): return str(v) # FIXME for xml? elif isinstance(v, Quantity): return str(v) elif isinstance(v, AsJson): # XXX returns value not tested, may be extremely strange return str(v) elif isinstance(v, pathlib.Path): return str(v) elif isinstance(v, idlib.Stream): return v.asCell() #elif isinstance(v, list) or isinstance(v, str): #return v elif isinstance(v, BaseException): return repr(v) else: #loge.debug(repr(v)) return v
def normv(v): if isinstance(v, str) and v.startswith('http'): # needed for loading from json that has been serialized # rather than from our internal representation # probably better to centralized the reload ... oid = OntId(v) if oid.prefix in want_prefixes: return OntTerm(v).asCell() else: return oid.iri if isinstance(v, idlib.Stream): if hasattr(v, 'asCell'): return v.asCell() else: loge.debug( f'{type(v)} does not implement an asCell representation') return v.asType(str) if isinstance(v, OntId): if not isinstance(v, OntTerm): v = OntTerm(v) v = v.asCell() if isinstance(v, list) or isinstance(v, tuple): v = ','.join( json.dumps(_, cls=JEncode) if isinstance(_, dict) else normv(_) for _ in v) v = v.replace('\n', ' ').replace('\t', ' ') elif any(isinstance(v, c) for c in (int, float, str)): v = str(v) v = v.replace('\n', ' ').replace('\t', ' ') # FIXME tests to catch this elif isinstance(v, dict): v = json.dumps(v, cls=JEncode) return v