Models Dana Angluin’s Language Learner.

Example

Imports

import axle._
import axle.lx._
import Angluin._

Setup

val mHi = Symbol("hi")
val mIm = Symbol("I'm")
val mYour = Symbol("your")
val mMother = Symbol("Mother")
val mShut = Symbol("shut")
val mUp = Symbol("up")

val Σ = Alphabet(Set(mHi, mIm, mYour, mMother, mShut, mUp))

val s1 = Expression(mHi :: mIm :: mYour :: mMother :: Nil)
val s2 = Expression(mShut :: mUp :: Nil)
val  = Language(Set(s1, s2))

val T = Text(s1 ::  ::  :: s2 ::  :: s2 :: s2 :: Nil)

val ɸ = memorizingLearner

Usage

import axle.algebra.lastOption

val outcome = lastOption(ɸ.guesses(T))
// outcome: Option[Grammar] = Some(
//   value = HardCodedGrammar(
//     ℒ = Language(
//       sequences = Set(
//         Expression(
//           symbols = List(Symbol(hi), Symbol(I'm), Symbol(your), Symbol(Mother))
//         ),
//         Expression(symbols = List(Symbol(shut), Symbol(up)))
//       )
//     )
//   )
// )

outcome.get.
// res0: Language = Language(
//   sequences = Set(
//     Expression(
//       symbols = List(Symbol(hi), Symbol(I'm), Symbol(your), Symbol(Mother))
//     ),
//     Expression(symbols = List(Symbol(shut), Symbol(up)))
//   )
// )


// res1: Language = Language(
//   sequences = Set(
//     Expression(
//       symbols = List(Symbol(hi), Symbol(I'm), Symbol(your), Symbol(Mother))
//     ),
//     Expression(symbols = List(Symbol(shut), Symbol(up)))
//   )
// )

T
// res2: Text = Iterable(
//   Expression(
//     symbols = List(Symbol(hi), Symbol(I'm), Symbol(your), Symbol(Mother))
//   ),
//   Expression(symbols = List()),
//   Expression(symbols = List()),
//   Expression(symbols = List(Symbol(shut), Symbol(up))),
//   Expression(symbols = List()),
//   Expression(symbols = List(Symbol(shut), Symbol(up))),
//   Expression(symbols = List(Symbol(shut), Symbol(up)))
// )

T.isFor()
// res3: Boolean = true