diff options
Diffstat (limited to 'grobid_tei_xml')
-rw-r--r-- | grobid_tei_xml/types.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/grobid_tei_xml/types.py b/grobid_tei_xml/types.py index b78b236..199e746 100644 --- a/grobid_tei_xml/types.py +++ b/grobid_tei_xml/types.py @@ -99,7 +99,8 @@ class GrobidCitation: def to_csl_dict(self, default_type: str = "article-journal") -> dict: """ - Transforms in to Citation Style Language (CSL) JSON schema + Transforms in to Citation Style Language (CSL) JSON schema, as a dict + (not an actual JSON string) """ csl = dict( type=default_type, @@ -148,6 +149,27 @@ class GrobidHeader: doi: Optional[str] = None journal: Optional[GrobidJournal] = None + def to_csl_dict(self, default_type: str = "article-journal") -> dict: + + csl = dict( + type=default_type, + author=[a.to_csl_dict() for a in self.authors or []], + issued=_csl_date(self.date), + title=self.title, + DOI=self.doi, + ) + + if self.journal: + csl['publisher'] = self.journal.publisher + if self.journal.name: + csl['container-title'] = self.journal.name + if self.journal.issue and self.journal.issue.isdigit(): + csl['issue'] = int(self.issue) + if self.journal.volume and self.journal.volume.isdigit(): + csl['volume'] = int(self.volume) + + return _simplify_dict(csl) + @dataclass class GrobidDocument: @@ -209,6 +231,16 @@ class GrobidDocument: self.acknowledgement = None self.annex = None + def to_csl_dict(self, default_type: str = "article-journal") -> dict: + """ + Transforms in to Citation Style Language (CSL) JSON schema, as a dict + (not an actual JSON string) + """ + if not self.header: + return {} + else: + return self.header.to_csl_dict(default_type=default_type) + def _simplify_dict(d: dict) -> dict: """ |