Package

com.eharmony.aloha

semantics

Permalink

package semantics

Visibility
  1. Public
  2. All

Type Members

  1. trait ErrorEnrichingSemantics[A] extends Semantics[A]

    Permalink

    User-defined functions used in feature specifications can cause models to throw undesirable exceptions.

    User-defined functions used in feature specifications can cause models to throw undesirable exceptions. This semantics mixin can allow the the exception to be caught, reformulated as a com.eharmony.aloha.semantics.SemanticsUdfException and rethrown. This has the distinct advantage of providing the caller with the exact feature specification that failed along with the features that were present and missing and the input data that caused the problem.

    Example usage: Assume a we have an implementation UnsafeSemantics, implementing com.eharmony.aloha.semantics.Semantics\[Xyz\]. We can recast the errors by doing

    // An object (note that because provideSemanticsUdfException = true by default, we don't need to specify it if
    // we want this semantics to always enrich exceptions.
    object SemanticsObjWithEnrichedErrors
        extends UnsafeSemantics
        with RethrowingSemantics[Xyz]
    
    // Here's a way to create a class to allow the caller to specify whether he wants
    // [[com.eharmony.aloha.semantics.SemanticsUdfException]]s to be provided.
    case class SemanticsClsWithEnrichedErrors(override val provideSemanticsUdfException: Boolean = true)
        extends UnsafeSemantics
        with RethrowingSemantics[Xyz]
    val featureSpecification = "[Some feature spec here ...]"
    val xyz: Xyz = getXyz()
    // Don't just call right.get in prod.
    val f = SemanticsObjWithEnrichedErrors.createFunction[SomeOutputType](featureSpecification).right.get
    
    // If the following line throws an exception, it'll throw a SemanticsUdfException which provides additional
    // information.
    val r = f(xyz)
    A

    the input type.

  2. trait MorphableSemantics[M[_] <: Semantics[_], A] extends Semantics[A]

    Permalink

    A version of Semantics that can morph into other instances of the same structure but with a different type parameter.

    A version of Semantics that can morph into other instances of the same structure but with a different type parameter.

    An example:

    case class X[A]() extends MorphableSemantics[X, A] {
      // ...
      def morph[B: RefInfo]: Option[X[B]] = Some(X[B]())
    }

    Notice for class X, that the M type constructor is X and the A is the same for the second type parameter of MorphableSemantics as for the type parameter in Semantics.

    This can be use like the following:

    import com.eharmony.aloha.reflect.RefInfo
    
    val xF = X[Float]
    val riD = implicitly[RefInfo[Double]]
    val xDo: Option[X[Double]] = xF.morph[Double]
    val xDo1: Option[X[Double]] = xF.morph(riD)

    or use it generically:

    def morph[M[_] <: Semantics[_], A, B: RefInfo](m: MorphableSemantics[M, A]): Option[Semantics[B]] = {
      m.morph[B]
    }
    
    val sDO: Option[Semantics[Double]] = morph(xF)
    M

    a type constructor providing the structure of the Semantics. This will most likely always be the concrete subclass of Semantics that implements MorphableSemantics.

    A

    the type parameter to which M is applied for this instance of Semantics, also the type parameter for the Semantics.

  3. trait Semantics[A] extends Closeable

    Permalink
    Annotations
    @implicitNotFound( ... )
  4. trait SemanticsProvider[A] extends AnyRef

    Permalink

    This is passed to the factory.

  5. case class SemanticsUdfException[+A](specification: String, accessorOutput: Map[String, Try[Any]], accessorsMissingOutput: List[String], accessorsInErr: List[String], cause: Throwable, input: A) extends AlohaException with Product with Serializable

    Permalink

    An exception used to denote that an error occurred while applying a user-defined function on the input data.

    An exception used to denote that an error occurred while applying a user-defined function on the input data. This was not a problem with the model but rather the code that the model called. This is differentiated because the code may have been defined outside of the Aloha libraries.

    The instantiation of this class should not throw exceptions.

    specification

    a specification for the feature that produced an error.

    accessorOutput

    output of the accessor functions for the feature that produced an error.

    accessorsMissingOutput

    names of accessor functions with missing data in the feature that produced an error.

    accessorsInErr

    names of accessor functions that produced errors in the feature that produced an error.

    cause

    the actual exception denoting the cause of the problem in the feature.

    input

    input to the feature that caused a problem. (Note: this parameter was intentionally chosen to go last because of a possible verbose toString output)

Value Members

  1. object EmptySemantics

    Permalink
  2. object SemanticsUdfException extends Serializable

    Permalink
  3. package compiled

    Permalink
  4. package func

    Permalink

Ungrouped