Advanced Usage

Visualization

Create a graph of the feature system lattice.

>>> import features

>>> fs = features.FeatureSystem('plural')

>>> dot = fs.graphviz()

>>> print(dot.source)  
// <FeatureSystem('plural') of 6 atoms 22 featuresets>
digraph plural {
    graph [margin=0]
    edge [arrowtail=none dir=back penwidth=.5]
            f0 [label="+1 &minus;1 +2 &minus;2 +3 &minus;3 +sg +pl &minus;sg &minus;pl"]
            f1 [label="+1 +sg"]
                    f1 -> f0
            f2 [label="+1 +pl"]
                    f2 -> f0
...
_images/fs-plural.svg

Check the documentation of the Python graphviz interface used for details on the resulting object.

Customization

To customize the behavior of the feature sets, override the FeatureSet class-attribute of FeatureSystem with a subclass that implements your wanted features:

>>> class MyFeatures(features.FeatureSystem.FeatureSet):
...     @property
...     def features(self):
...         return list(self.concept.intent)

>>> class MyFeatureSystem(features.FeatureSystem):
...     FeatureSet = MyFeatures

>>> myfs = MyFeatureSystem('small')

>>> myfs('1 -pl')
MyFeatures('+1 -pl')

>>> myfs('1 -pl').features
['+1', '-2', '-pl']