From 66088851dcd4fe72056c0d7534d80e28400aad15 Mon Sep 17 00:00:00 2001 From: ines Date: Wed, 24 May 2017 11:58:17 +0200 Subject: [PATCH] Add Doc.to_disk() and Doc.from_disk() methods --- spacy/tokens/doc.pyx | 18 ++++++++++++++++++ website/docs/api/doc.jade | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 0e4faafbe..611a68186 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -598,6 +598,24 @@ cdef class Doc: self.is_tagged = bool(TAG in attrs or POS in attrs) return self + def to_disk(self, path): + """Save the current state to a directory. + + path (unicode or Path): A path to a directory, which will be created if + it doesn't exist. Paths may be either strings or `Path`-like objects. + """ + raise NotImplementedError() + + def from_disk(self, path): + """Loads state from a directory. Modifies the object in place and + returns it. + + path (unicode or Path): A path to a directory. Paths may be either + strings or `Path`-like objects. + RETURNS (Doc): The modified `Doc` object. + """ + raise NotImplementedError() + def to_bytes(self): """Serialize, i.e. export the document contents to a binary string. diff --git a/website/docs/api/doc.jade b/website/docs/api/doc.jade index 6a9faf4b4..62b1a2a76 100644 --- a/website/docs/api/doc.jade +++ b/website/docs/api/doc.jade @@ -253,6 +253,44 @@ p +cell #[code Doc] +cell Itself. ++h(2, "to_disk") Doc.to_disk + +tag method + +p Save the current state to a directory. + ++aside-code("Example"). + doc.to_disk('/path/to/doc') + ++table(["Name", "Type", "Description"]) + +row + +cell #[code path] + +cell unicode or #[code Path] + +cell + | A path to a directory, which will be created if it doesn't exist. + | Paths may be either strings or #[code Path]-like objects. + ++h(2, "from_disk") Doc.from_disk + +tag method + +p Loads state from a directory. Modifies the object in place and returns it. + ++aside-code("Example"). + from spacy.tokens import Doc + doc = Doc().from_disk('/path/to/doc') + ++table(["Name", "Type", "Description"]) + +row + +cell #[code path] + +cell unicode or #[code Path] + +cell + | A path to a directory. Paths may be either strings or + | #[code Path]-like objects. + + +footrow + +cell returns + +cell #[code Doc] + +cell The modified #[code Doc] object. + +h(2, "to_bytes") Doc.to_bytes +tag method