api icon indicating copy to clipboard operation
api copied to clipboard

Reference endpoint

Open mkhorton opened this issue 4 years ago • 2 comments

  • [ ] An endpoint to return either (a) BibTeX strings or (b) formatted references for a given mp-id (see MPRester.get_materials_id_references
  • [ ] Return DOIs for references
  • [ ] Check if article is open access using open access API (lower priority), e.g. see https://openaccessbutton.org/api

Previously, to format references I was using:

ref_markdown = PybtexEngine().format_from_string(
    bibtex_string, style="unsrt", output_backend="markdown"
)

or

               # use Crossref to retrieve pre-formatted text

                # remove leading "1. " from Science CSL style
                refs = {
                    doi: content_negotiation(ids=doi, format="text", style="science")[
                        3:
                    ]
                    for doi in dois_to_item.keys()
                }

And to retrieve I was using habanero:

            cr = Crossref(mailto=CROSSREF_MAILTO)
            individual_references = set()
            for references in all_references:
                individual_references.update(set(references.split("\n\n")))

            # exclude Materials Proect references (these are intended to be
            # references for the structure specifically)
            refs_to_remove = set()
            for ref in individual_references:
                if "Jain2013" in ref:
                    refs_to_remove.add(ref)
            individual_references -= refs_to_remove

            works = [cr.works(query=ref, limit=1) for ref in individual_references]
            self.logger.debug(f"Retrieved {len(works)} works from Crossref.")

            items = [
                work["message"]["items"][0]
                for work in works
                if len(work["message"]["items"]) > 0
            ]

            dois_to_item = {
                item["DOI"]: {
                    "cited-by": item.get("is-referenced-by-count", 0),
                    "score": item["score"],
                    "title": item.get("title", None),
                    "authors": item.get("author", []),
                    "journal": item.get("container-title", [None])[0],
                    "issue": item.get("issue", None),
                    "volume": item.get("volume", None),
                    "pages": item.get("page", None),
                    "date-parts": item.get("issued", {}).get("date-parts", [[None]]),
                }
                for item in items
                if item["score"] > 40
            }

            num_refs = len(dois_to_item)
            sorted_dois = sorted(
                list(dois_to_item.keys()),
                key=lambda doi: -dois_to_item[doi]["cited-by"],
            )

mkhorton avatar Sep 24 '20 22:09 mkhorton

Current endpoint only returns raw bibtex strings and does not provide formatted references.

munrojm avatar Oct 13 '20 22:10 munrojm

Added a builder to populate the cross ref data https://github.com/materialsproject/emmet/pull/133

jmmshn avatar Nov 01 '20 01:11 jmmshn