camel_tools.morphology.reinflector¶
The reinflector component of CAMeL Tools.
Classes¶
-
class
camel_tools.morphology.reinflector.Reinflector(db)¶ Morphological reinflector component.
Parameters: db ( MorphologyDB) – Database to use for generation. Must be opened in reinflection mode or both analysis and generation modes.Raises: ReinflectorError– If db is not an instance ofMorphologyDBor if db does not support reinflection.-
all_feats()¶ Return a set of all features provided by the database used in this reinflector instance.
Returns: The set all features provided by the database used in this reinflector instance. Return type: frozensetofstr
-
reinflect(word, feats)¶ Generate surface forms and their associated analyses for a given word and a given set of (possibly underspecified) features. The surface form is accessed through the diac feature.
Parameters: - word (
str) – Word to reinflect. - feats (
dict) – Dictionary of features. See CAMeL Morphology Features for more information on features and their values.
Returns: List of generated analyses. See CAMeL Morphology Features for more information on features and their values.
Return type: Raises: InvalidReinflectorFeature– If a feature is given that is not defined in database.InvalidReinflectorFeatureValue– If an invalid value is given to a feature or if ‘pos’ feature is not defined.
- word (
-
Examples¶
from camel_tools.morphology.database import MorphologyDB
from camel_tools.morphology.reinflector import Reinflector
# Initialize database in reinflection mode
db = MorphologyDB.builtin_db(flags='r')
# Create reinflector instance
reinflector = Reinflector(db)
# Specify word and features to generate for
word = 'شوارع'
features = {
'gen': 'm',
'num': 'd',
'prc1': 'bi_prep'
}
# Generate analyses for lemma and features
analyses = reinflector.reinflect(word, features)