From 35ee80c5e3a6403e974fc4bdfd46e35d386fb5e2 Mon Sep 17 00:00:00 2001 From: richardpaulhudson Date: Thu, 26 Jan 2023 20:31:30 +0100 Subject: [PATCH] Documentation --- spacy/visualization.py | 6 +++--- website/docs/api/doc.mdx | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/spacy/visualization.py b/spacy/visualization.py index 33b757076..250a0717e 100644 --- a/spacy/visualization.py +++ b/spacy/visualization.py @@ -437,11 +437,11 @@ def render_document( AttributeFormat("dep_", name="dep_"), AttributeFormat("ent_type_", name="ent_type_"), AttributeFormat("i", name="index", aligns="r"), - AttributeFormat("text", name="text", max_width=20), - AttributeFormat("lemma_", name="lemma_", max_width=20), + AttributeFormat("text", name="text", max_width=30), + AttributeFormat("lemma_", name="lemma_", max_width=30), AttributeFormat("pos_", name="pos_"), AttributeFormat("tag_", name="tag_"), - AttributeFormat("morph", name="morph_", max_width=60), + AttributeFormat("morph", name="morph", max_width=80), ] if search_attr_name is not None and search_attr_value is not None: for col in cols: diff --git a/website/docs/api/doc.mdx b/website/docs/api/doc.mdx index a5f3de6be..47dcc2599 100644 --- a/website/docs/api/doc.mdx +++ b/website/docs/api/doc.mdx @@ -520,6 +520,31 @@ JSON data as generated by [`Doc.to_json()`](/api/doc#to_json). | `validate` | Whether to validate the JSON input against the expected schema for detailed debugging. Defaults to `False`. ~~bool~~ | | **RETURNS** | A `Doc` corresponding to the provided JSON. ~~Doc~~ | +## Doc.inspect {id="inspect",tag="method",version="4"} + +Outputs to the console a human-readable, tabular representation of all or part +of the document. If any of the four optional parameters are specified, those +sentences in the document that correspond to the specification are displayed; if +none of them are specified, the whole document is displayed. + +> #### Example +> +> ```python +> doc = nlp("All we have to decide is what to do with the time that is given us. Nobody knows how much time that is.") +> doc.inspect() +> doc.inspect("lemma_", "give") +> doc.inspect("lemma_", "time", start_i=18) +> doc.inspect("lemma_", "time", length=20) +> ``` + +| Name | Description | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| `search_attr_name` | The name of an attribute for which to search to determine the sentence at which to begin rendering, e.g. `lemma_`. ~~Optional[str]~~ | +| `search_attr_value` | The value of an attribute for which to search to determine the sentence at which to begin rendering, e.g. `give`. ~~Optional[str]~~ | +| _keyword-only_ | | +| `start_i` | The index at which searching should begin or with whose containing sentence rendering should begin. ~~Optional[int]~~ | +| `length` | The number of tokens from the start token to the token with whose containing sentence rendering should end. ~~Optional[int]~~ | + ## Doc.retokenize {id="retokenize",tag="contextmanager",version="2.1"} Context manager to handle retokenization of the `Doc`. Modifications to the