NlpTools API
Class

NlpTools\FeatureFactories\FunctionFeatures

class FunctionFeatures implements FeatureFactoryInterface

An implementation of FeatureFactoryInterface that takes any number of callables (function names, closures, array($object,'func_name'), etc.) and calls them consecutively using the return value as a feature's unique string.

The class can model both feature frequency and presence

Methods

__construct(array $f = array())

modelFrequency()

Set the feature factory to model frequency instead of presence

modelPresence()

Set the feature factory to model presence instead of frequency

add(callable $feature)

Add a function as a feature

array getFeatureArray(string $class, DocumentInterface $d)

Compute the features that "fire" for a given class,document pair.

Details

at line 24
public __construct(array $f = array())

Parameters

array $f An array of feature functions

at line 32
public modelFrequency()

Set the feature factory to model frequency instead of presence

at line 39
public modelPresence()

Set the feature factory to model presence instead of frequency

at line 48
public add(callable $feature)

Add a function as a feature

Parameters

callable $feature

at line 65
public array getFeatureArray(string $class, DocumentInterface $d)

Compute the features that "fire" for a given class,document pair.

Call each function one by one. Eliminate each return value that
evaluates to false. If the return value is a string add it to
the feature set. If the return value is an array iterate over it
and add each value to the feature set.

Parameters

string $class The class for which we are calculating features
DocumentInterface $d The document for which we are calculating features

Return Value

array