Class LyreExpression
- java.lang.Object
-
- com.gengoai.apollo.ml.feature.Featurizer<HString>
-
- com.gengoai.hermes.extraction.FeaturizingExtractor
-
- com.gengoai.hermes.extraction.lyre.LyreExpression
-
- All Implemented Interfaces:
FeatureExtractor<HString>
,ObservationExtractor<HString>
,SerializableFunction<HString,String>
,SerializablePredicate<HString>
,Extractor
,Expression
,Serializable
,Function<HString,String>
,Predicate<HString>
public final class LyreExpression extends FeaturizingExtractor implements Expression, SerializableFunction<HString,String>, SerializablePredicate<HString>
A LyreExpression represents a series of steps to perform over an input
HString
which can be used for querying (i.e. acting as a Java Predicate) and extracting and transforming (i.e. like a Java Function). Lyre expressions extend fromFeaturizingExtractor
allowing them to be used as a feature extractor for machine learning.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
apply(HString hString)
double
applyAsDouble(HString hString)
Applies this expression to the given object converting it to a doubledouble
applyAsDouble(Object object)
Applies this expression to the given object converting it to a doubleList<Variable>
applyAsFeatures(HString hString)
HString
applyAsHString(HString string)
Applies this expression to the given HString converting the result into an HStringList<Object>
applyAsList(Object object)
Applies the given lambda against the given HString returning a list<T> List<T>
applyAsList(Object object, Class<T> elementType)
Applies the given lambda against the given HString returning a list of of the given element type.Object
applyAsObject(Object object)
Applies this expression to given object.String
applyAsString(Object object)
Applies this expression to given object return a String value.Counter<String>
count(@NonNull HString hString)
Applies the expression returning a count over the string results.Extraction
extract(@NonNull HString hString)
Generate anExtraction
from the givenHString
.String
getPattern()
Gets the Lyre Pattern that can generate this expressionLyreExpressionType
getType()
static LyreExpression
parse(String pattern)
Parse the given pattern into aLyreExpression
.boolean
test(HString hString)
boolean
testObject(Object object)
Tests the given object against this LyreExpressionString
toString()
-
Methods inherited from class com.gengoai.apollo.ml.feature.Featurizer
booleanFeaturizer, chain, chain, countFeaturizer, extractObservation, multiValueFeaturizer, predicateFeaturizer, realFeaturizer, valueFeaturizer, valueFeaturizer, withContext, withContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.gengoai.parsing.Expression
apply, as, isInstance, isInstance, isInstance, when, when
-
Methods inherited from interface com.gengoai.apollo.ml.feature.FeatureExtractor
contextualize, extractSequence
-
Methods inherited from interface com.gengoai.function.SerializableFunction
andThen, asConsumer, compose
-
-
-
-
Method Detail
-
parse
public static LyreExpression parse(String pattern)
Parse the given pattern into aLyreExpression
.- Parameters:
pattern
- the pattern- Returns:
- the LyreExpression Expression
-
applyAsDouble
public double applyAsDouble(HString hString)
Applies this expression to the given object converting it to a double- Parameters:
hString
- the object to apply the expression on- Returns:
- the double value
-
applyAsDouble
public double applyAsDouble(Object object)
Applies this expression to the given object converting it to a double- Parameters:
object
- the object to apply the expression on- Returns:
- the double value
-
applyAsFeatures
public List<Variable> applyAsFeatures(HString hString)
- Specified by:
applyAsFeatures
in classFeaturizer<HString>
-
applyAsHString
public HString applyAsHString(HString string)
Applies this expression to the given HString converting the result into an HString- Parameters:
string
- the HString to apply the expression against- Returns:
- the resulting HString
-
applyAsList
public <T> List<T> applyAsList(Object object, Class<T> elementType)
Applies the given lambda against the given HString returning a list of of the given element type.- Type Parameters:
T
- the list element parameter- Parameters:
object
- the object to apply the lambda againstelementType
- the type information for the list elements- Returns:
- the list of elements of the given type or null if the generated value is not convertible to a list of the given type
-
applyAsList
public List<Object> applyAsList(Object object)
Applies the given lambda against the given HString returning a list- Parameters:
object
- the object to apply the lambda against- Returns:
- the list of objects or null if not convertible
-
applyAsObject
public Object applyAsObject(Object object)
Applies this expression to given object.- Parameters:
object
- the object to apply the expression on- Returns:
- the result of the expression evaluation
-
applyAsString
public String applyAsString(Object object)
Applies this expression to given object return a String value.- Parameters:
object
- the object to apply the expression on- Returns:
- the result of the expression evaluation as a String
-
count
public Counter<String> count(@NonNull @NonNull HString hString)
Applies the expression returning a count over the string results.- Parameters:
hString
- the HString to apply the expression against- Returns:
- the counter
-
extract
public Extraction extract(@NonNull @NonNull HString hString)
Description copied from interface:Extractor
Generate anExtraction
from the givenHString
.
-
getPattern
public String getPattern()
Gets the Lyre Pattern that can generate this expression- Returns:
- the Lyre pattern
-
getType
public LyreExpressionType getType()
- Specified by:
getType
in interfaceExpression
-
testObject
public boolean testObject(Object object)
Tests the given object against this LyreExpression- Parameters:
object
- the object- Returns:
- boolean based on expression evaluation
-
-