JsonS2PaperDB

class s2.db.json.JsonS2PaperDB(json_dir, enforce_id=True)

Dict-like interface to store S2Papers as jsons and retrieve as S2Papers

Note

Types are enforced, so keys must be valid PaperIds and values must be instances of S2Paper.

Parameters
  • json_dir (str or Path) –

    Directory where papers are saved as jsons. If directory does not exist, it will be created and populated with jsons as values are set in the object. For example:

    pdb = JsonS2PaperDB("db")
    paper = s2.api.get_paper(k)
    pdb[k] = paper
    

    will first create a directory db, then a file db/{k}.json containing the S2Paper that was passed, in a json-serialized format.

    Similarly, removing items from the object (e.g. pdb.pop(k)) will delete the corresponding json file.

  • enforce_id (bool, optional) – Enforce that a key be equal to the paperId field of the S2Paper object (if it exists; for handling unknown references without a paperId value, see Saving Objects without S2 Identifiers).

paperIds

In-memory lookup of existing keys, updated whenever a key is added or removed. Will likely be updated to something less scrappy.

Type

set of str