def test_asType(self): import rdflib from idlib.formats import rdf as _bind_rdf o = idlib.Orcid(self.ids[0]) nt = o.asType(rdflib.URIRef) # still haven't decided if this is a good idea or not assert str(o) != str(nt), 'string representation of streams should not match id ???'
def contributor_orcid(self, value): # FIXME use schema self._error_on_na(value) value, _j = self._deatag(value) v = value.replace(' ', '').strip().rstrip() # ah the rando tabs in a csv if not v: return if v.startswith('http:'): v = v.replace('http:', 'https:', 1) if not (v.startswith('ORCID:') or v.startswith('https:')): v = v.strip() if not len(v): return elif v == '0': # FIXME ? someone using strange conventions ... return elif len(v) != 19: msg = f'orcid wrong length {value!r} {self._path.as_posix()!r}' if self.addError(idlib.Orcid._id_class.OrcidLengthError(msg)): logd.error(msg) return v = 'ORCID:' + v else: if v.startswith('https:'): _, numeric = v.rsplit('/', 1) elif v.startswith('ORCID:'): _, numeric = v.rsplit(':', 1) if not len(numeric): return elif len(numeric) != 19: msg = f'orcid wrong length {value!r} {self._path.as_posix()!r}' if self.addError(idlib.Orcid._id_class.OrcidLengthError(msg)): logd.error(msg) return try: #log.debug(f"{v} '{self.path}'") orcid = idlib.Orcid(v) # XXX possible encapsulation issue if not orcid.identifier.checksumValid: # FIXME should not handle this with ifs ... # FIXME json schema can't do this ... msg = f'orcid failed checksum {value!r} {self._path.as_posix()!r}' if self.addError( idlib.Orcid._id_class.OrcidChecksumError(msg)): logd.error(msg) return yield orcid except (OntId.BadCurieError, idlib.Orcid._id_class.OrcidMalformedError) as e: msg = f'orcid malformed {value!r} {self._path.as_posix()!r}' if self.addError(idlib.Orcid._id_class.OrcidMalformedError(msg)): logd.error(msg) yield value
def __new__(cls, something): if '10.' in something: if 'http' in something and 'doi.org' not in something: pass # probably a publisher uri that uses the handle else: return idlib.Doi(something) if 'orcid' in something: return idlib.Orcid(something) if '/ror.org/' in something or something.startswith('ror:'): return idlib.Ror(something) if 'protocols.io' in something: return idlib.Pio(something) return oq.OntId(something) return OntTerm(something) # use the better local version of OntTerm
def _process(self, contributor): # get member if we can find them he = dat.HasErrors(pipeline_stage=self.__class__.__name__ + '.data') if 'contributor_name' in contributor and 'first_name' in contributor: name = contributor['contributor_name'] if ';' in name: msg = f'Bad symbol in name {name!r}' he.addError(msg) logd.error(msg) fn = contributor['first_name'] ln = contributor['last_name'] if ' ' in fn: fn, mn = fn.split(' ', 1) mn, _mn = mn.rstrip('.'), mn if mn != _mn: he.addError(f'Middle initials don\'t need periods :) {name!r}', logfunc=logd.error) contributor['middle_name'] = mn contributor['first_name'] = fn if ' ' in ln: msg = f'Malformed last_name {ln!r}' he.addError(msg) logd.error(msg) ln = ln.replace(' ', '-') failover = f'{fn}-{ln}' member = self.member(fn, ln) if member is not None: userid = OntId('https://api.blackfynn.io/users/' + member.id) contributor['blackfynn_user_id'] = userid else: member = None failover = 'no-orcid-no-name' log.warning(f'No name!' + lj(contributor)) orcid = None if 'contributor_orcid_id' in contributor: orcid = contributor['contributor_orcid_id'] if type(orcid) == str and 'orcid.org' in orcid: orcid = idlib.Orcid(orcid) # FIXME reloading from json if isinstance(orcid, idlib.Orcid): s = orcid else: # it's not an orcid or its a bad orcid orcid = None if orcid is None: if member is not None: s = userid else: log.debug(lj(contributor)) s = OntId(self.dsid + '/contributors/' + failover) contributor['id'] = s he.embedErrors(contributor) # lifting + adding if 'contributor_affiliation' in contributor: ca = contributor['contributor_affiliation'] maybe_ror = self.lifters.affiliations(ca) if maybe_ror is not None: contributor['affiliation'] = maybe_ror