def conceptsets(self): """ :returns: `dict` mapping ConceptSet IDs to `Conceptset` instances. """ return to_dict( Conceptset(api=self, **lowercase(d)) for d in read_dicts(self.data_path('concepticon.tsv')))
def metadata(self): """ :returns: `dict` mapping metadata provider IDs to `Metadata` instances. """ return to_dict(map( self._metadata, [p.stem for p in self.data_path('concept_set_meta').glob('*.tsv')]))
def conceptlists(self): """ :returns: `dict` mapping ConceptList IDs to `Conceptlist` instances. .. note:: Individual concepts can be accessed via `Conceptlist.concepts`. """ return to_dict( Conceptlist(api=self, **lowercase(d)) for d in read_dicts(self.data_path('conceptlists.tsv')))
def bibliography(self) -> typing.Dict[str, Source]: """ :returns: `dict` mapping BibTeX IDs to `Reference` instances. """ return to_dict( Source.from_entry(key, entry) for key, entry in pybtex.database.parse_string( self.bibfile.read_text( encoding='utf8'), bib_format='bibtex').entries.items())
def _metadata(self, id_): values_path = self.data_path('concept_set_meta', id_ + '.tsv') md_path = self.data_path('concept_set_meta', id_ + '.tsv' + MD_SUFFIX) assert values_path.exists() and md_path.exists() md = jsonlib.load(md_path) return Metadata(id=id_, meta=md, values=to_dict( read_dicts(values_path, schema=md['tableSchema']), key=operator.itemgetter('CONCEPTICON_ID')))
def bibliography(self): """ :returns: `dict` mapping BibTeX IDs to `Reference` instances. """ refs = [] with self.bibfile.open(encoding='utf8') as fp: for key, entry in pybtex.database.parse_string( fp.read(), bib_format='bibtex').entries.items(): refs.append(Source.from_entry(key, entry)) return to_dict(refs)
def concepts(self): res = [] if self.path.exists(): for item in self.metadata: kw, attributes = {}, {} for k, v in item.items(): if k: kl = k.lower() setitem(kw if kl in Concept.public_fields() else attributes, kl, v) res.append(Concept(list=self, attributes=attributes, **kw)) return to_dict(res)
def bibliography(self): """ :returns: `dict` mapping BibTeX IDs to `Reference` instances. """ log = logging.getLogger('bibtexparser') log.setLevel(logging.WARN) with self.bibfile.open(encoding='utf8') as fp: refs = [] for rec in bibtexparser.loads(fp.read()).entries: refs.append( Reference(id=rec.pop('ID'), type=rec.pop('ENTRYTYPE'), record=rec)) return to_dict(refs)
def test_to_dict(self): from pyconcepticon.util import to_dict with self.assertRaises(ValueError): to_dict([None, None], id)