spaCy/website/docs/api/lemmatizer.md
Ines Montani e597110d31
💫 Update website (#3285)
<!--- Provide a general summary of your changes in the title. -->

## Description

The new website is implemented using [Gatsby](https://www.gatsbyjs.org) with [Remark](https://github.com/remarkjs/remark) and [MDX](https://mdxjs.com/). This allows authoring content in **straightforward Markdown** without the usual limitations. Standard elements can be overwritten with powerful [React](http://reactjs.org/) components and wherever Markdown syntax isn't enough, JSX components can be used. Hopefully, this update will also make it much easier to contribute to the docs. Once this PR is merged, I'll implement auto-deployment via [Netlify](https://netlify.com) on a specific branch (to avoid building the website on every PR). There's a bunch of other cool stuff that the new setup will allow us to do – including writing front-end tests, service workers, offline support, implementing a search and so on.

This PR also includes various new docs pages and content.
Resolves #3270. Resolves #3222. Resolves #2947. Resolves #2837.


### Types of change
enhancement

## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2019-02-17 19:31:19 +01:00

4.6 KiB

title teaser tag source
Lemmatizer Assign the base forms of words class spacy/lemmatizer.py

The Lemmatizer supports simple part-of-speech-sensitive suffix rules and lookup tables.

Lemmatizer.__init__

Create a Lemmatizer.

Example

from spacy.lemmatizer import Lemmatizer
lemmatizer = Lemmatizer()
Name Type Description
index dict / None Inventory of lemmas in the language.
exceptions dict / None Mapping of string forms to lemmas that bypass the rules.
rules dict / None List of suffix rewrite rules.
lookup dict / None Lookup table mapping string to their lemmas.
RETURNS Lemmatizer The newly created object.

Lemmatizer.__call__

Lemmatize a string.

Example

from spacy.lemmatizer import Lemmatizer
from spacy.lang.en import LEMMA_INDEX, LEMMA_EXC, LEMMA_RULES
lemmatizer = Lemmatizer(LEMMA_INDEX, LEMMA_EXC, LEMMA_RULES)
lemmas = lemmatizer(u"ducks", u"NOUN")
assert lemmas == [u"duck"]
Name Type Description
string unicode The string to lemmatize, e.g. the token text.
univ_pos unicode / int The token's universal part-of-speech tag.
morphology dict / None Morphological features following the Universal Dependencies scheme.
RETURNS list The available lemmas for the string.

Lemmatizer.lookup

Look up a lemma in the lookup table, if available. If no lemma is found, the original string is returned. Languages can provide a lookup table via the lemma_lookup variable, set on the individual Language class.

Example

lookup = {u"going": u"go"}
lemmatizer = Lemmatizer(lookup=lookup)
assert lemmatizer.lookup(u"going") == u"go"
Name Type Description
string unicode The string to look up.
RETURNS unicode The lemma if the string was found, otherwise the original string.

Lemmatizer.is_base_form

Check whether we're dealing with an uninflected paradigm, so we can avoid lemmatization entirely.

Example

pos = "verb"
morph = {"VerbForm": "inf"}
is_base_form = lemmatizer.is_base_form(pos, morph)
assert is_base_form == True
Name Type Description
univ_pos unicode / int The token's universal part-of-speech tag.
morphology dict The token's morphological features.
RETURNS bool Whether the token's part-of-speech tag and morphological features describe a base form.

Attributes

Name Type Description
index dict / None Inventory of lemmas in the language.
exc dict / None Mapping of string forms to lemmas that bypass the rules.
rules dict / None List of suffix rewrite rules.
lookup_table 2 dict / None The lemma lookup table, if available.