package translation
Translation primarily using a functorial framework - see Translator$, for natural language processing as well as serialization, formatted output, parsing, interface with formal languages etc.
Besides the Translator framework and helper typeclasses is Functors, several structures for concrete languages including our implementation of HoTT are in this package.
- Alphabetic
- By Inheritance
- translation
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- case class CodeGen(inducNames: (Term) => Option[Term] = (_) => None, defns: Map[String, Term] = Map()) extends Product with Serializable
- trait CompositeFunctors extends AnyRef
lower priority Functor and Traverese type classes to be extended in Functors
- trait ConeRestriction[X[_], Y[_], G[_]] extends AnyRef
restriction of cone on functors
- trait ContextTranslator[I, O, X[_], Ctx[_, _]] extends (Ctx[I, O]) => (X[I]) => Option[X[O]]
context dependent version of Translator
- trait Domain[E] extends AnyRef
- trait Equiv[X[_], Y[_]] extends AnyRef
Equivalence of Functors (without laws)
- class ExprApplnOps[E] extends AnyRef
- trait ExprLang[E] extends AnyRef
Abstraction (as a type class) of a language for mathematical expressions, i.e., of
Abstraction (as a type class) of a language for mathematical expressions, i.e., of
* methods for forming expressions, * some basic expressions such as true, false, numbers etc.
Expression include functions and propositions. However, expressions here need not include sophisticated, and foundation specific, constructions such as inductive types; these should be abstracted separately.
While the design is based on homotopy type theory, implementations can be with a range of logics or functional languages, for instance HOL or the Wolfram language. All methods are optional, so anything outside a language is just not built.
This is integrated with and used by many components.
* As a target for natural language and latex translation. * Bidirectional integration with HoTT implementations: * * terms have such a structure, * * terms can be translated to a language with this structure. * Allows pickling of terms by implementing a formal expression language. * _Goal:_ Bidirectional integration with lean expressions.
- trait ExprPatterns[E] extends AnyRef
- trait FansiShow[-U] extends AnyRef
- trait FoldedTerm[U <: Term with Subs[U]] extends Term
- trait FormulaParser[E] extends AnyRef
- sealed trait FreeExpr extends AnyRef
- case class HoTTParser(ctx: Context = Context.Empty, contextMap: Map[String, Context] = Map()) extends Product with Serializable
- trait Inclusion[X[_], Y[_]] extends AnyRef
inclusion of functors
- sealed trait MathExpr extends AnyRef
Expression in a language to represent terms in HoTT and trees representing them in prose, including partially collapsed trees.
Expression in a language to represent terms in HoTT and trees representing them in prose, including partially collapsed trees. At the level of structure, we do not make distinctions between words and phrases; the distinction is specific to trees, where a word is a leaf.
We model expressions that will mostly become Terms in HoTT, mostly following Naproche. At the upper level are sentential phrases. We typically start with a tree that encodes a sentential phrase.
- trait MathReader[D, E] extends AnyRef
- sealed trait MathText extends AnyRef
- trait MathWriter[D, E] extends AnyRef
Type-class for writing to a document of type D in terms of expressions of type E.
Type-class for writing to a document of type D in terms of expressions of type E. We can write statements and begin and end blocks. We append to the document, but the document may come with a cursor that allows insertion instead.
- trait NestedDoc[T] extends AnyRef
- trait OptRestriction[X[_], Y[_]] extends ConeRestriction[X, Y, Option]
restriction on optional functor
- abstract class QuasiInclHList[X, Y, F[_] <: HList] extends QuasiInclusion[X, Y, F]
inclusion of type
Y
inF(X)
withF(_)
anHList
- abstract class QuasiInclusion[X, Y, F[_]] extends AnyRef
inclusion of type
Y
inF(X)
- trait QuasiProjection[X, Y] extends AnyRef
projection of
X
ontoY
- case class Raw(model: TreeModel) extends MathText with MathExpr with Product with Serializable
An unparsed tree, the default parse for iterative debugging.
- sealed trait Scoped[S] extends AnyRef
- sealed trait ShapeTree extends AnyRef
- class ShapeTreeFormat extends TermRec[ShapeTree]
- trait Statement[E] extends AnyRef
A statement obtained from source which affects a document.
- trait SubType[X[_], Y[_]] extends Inclusion[X, Y] with OptRestriction[X, Y]
subtype relation between functors, giving inclusion and optional restriction, explicit, not depending on scala type checking
- class SubTypePattern[X, Y, F[_]] extends AnyRef
Pattern and builder for matching whether, for a term
x: X
,F(x)
is in thesubtype
Y
.Pattern and builder for matching whether, for a term
x: X
,F(x)
is in thesubtype
Y
. HereY
is not just a scala subtype, but we have inclusions and projections making it a direct summand. - class TermParser extends JavaTokenParsers
- trait TermRec[U] extends AnyRef
- class TermToExpr[E] extends AnyRef
- trait Translator[I, O] extends (I) => Option[O]
Translator from an input I to an output O, designed to be built recursively.
Translator from an input I to an output O, designed to be built recursively.
Translation by Splitting and joining
The most import class of translators are constructed from
* a split map I => Option[X], where X is obtained from I by taking Tuples, Lists and sub-types
* a join map Y => Option[O], where Y is obtained from O structurally, in the same way as X is obtained from I, e.g. X = (I, I) and Y = (O, O).
However X and Y may involve taking sub-types independently of each other.
Such a translator splits an input, recursively translates X to Y and combines the result with the join (all steps work optionally).
Combinations, Basic Translators
Translators are built by combining others by OrElse, starting with basic translators specified by a function I => Option[O]. One can instead start with an empty translator.
Note that we can restrict the domain or extend the codomain of a translator by just using it as a function I => Option[O]. However this should be done after making all OrElse combinations, as the wrapped translator does not combine recursively.
A typical example of usage is as below
scala> import provingground._ import provingground._ scala> import translation._, Translator._ import translation._ import Translator._ scala> import cats._, cats.implicits._ import cats._ import cats.implicits._ scala> class A defined class A scala> case class B(x: A, y: A) extends A defined class B scala> case class C(x: A, y: A) extends A defined class C scala> case object D extends A defined object D scala> import Functors._ import Functors._ scala> val Bpat = Pattern.partial[A, II]{case B(x, y) => (x, y)} scala> val Dpat = Pattern.partial[A, Un]{case D => ()} scala> case object E extends A defined object E scala> val trans = Translator.Empty[A, A] || Bpat >>> {case (x, y) => C(x,y)} || Dpat >>> {case _ => E} trans: provingground.translation.Translator.OrElse[A,A] = <function1> scala> trans(B(B(D, D), B(B(D, D), D))) res0: Option[A] = Some(C(C(E,E),C(C(E,E),E))) scala> trans(C(D, D)) res1: Option[A] = None
- sealed trait TreeModel extends AnyRef
- trait Vocabulary[E, C] extends AnyRef
Value Members
- object CodeGen extends Serializable
- object ContextTranslator
- object CoreNLP
direct interface to the Stanford parser; the StanfordParser object which handles LaTeX is used instead.
- object CoreNLPTest
- object Equiv
- object ExprEgs
Examples to experiment and illustrate expression level NLP parsing Issues revealed:
Examples to experiment and illustrate expression level NLP parsing Issues revealed:
- Cardinals should be treated as determiners
- determiners in a phrase e.g. 'divides some ...' need special rules
- useless 'then'
- primes is tagged as a verb, not a noun
- in 'are represented by ...', 'represented by ...'
- copula followed by an adjectival phrase is mishandled
- TeX fragment that is part of a word gives error.
- object ExprLang
- object FansiShow
- object FansiTranslate
- object FormalExpr
- object FreeExpr
- object FreeExprHLPatterns
- object FreeExprPatterns
- object Functors extends CompositeFunctors
Functor and Traverse typeclasses for Tuples, HLists and Compositions of Functors, and for Constant functors.
Functor and Traverse typeclasses for Tuples, HLists and Compositions of Functors, and for Constant functors.
To work around ambiguity in inference, for example so that the type of iterated triples is interpreted as
III(A) = (II(A), Id(A))
, notIII(A) = ((A, A), A)
several functors are explicitly named with the appropriate structure. - object HoTTParser extends Serializable
- object Inclusion
- object MathExpr
Expression in a language to represent terms in HoTT and trees representing them in prose, including partially collapsed trees.
Expression in a language to represent terms in HoTT and trees representing them in prose, including partially collapsed trees. At the level of structure, we do not make distinctions between words and phrases; the distinction is specific to trees, where a word is a leaf.
We model expressions that will mostly become Terms in HoTT, mostly following Naproche. At the upper level are sentential phrases. We typically start with a tree that encodes a sentential phrase.
We have various case classes for syntax, but a single trait
- object MathReader
- object MathText
- object MathWriter
- object NestedDoc
- object NlpProse
Stanford dependency trees and associated methods
- object OptRestriction
- object PennTrees
- object QuasiInclusion
- object QuasiProjection
- object Raw extends Serializable
- object RefineTerms
- object Scoped
- object Script
- object ShapeTree
- object SpecialTerms
- object StanfordParser
Interface to the Stanford parser, handling (inline) TeX by separating tokenizing and POS tagging from parsing.
Interface to the Stanford parser, handling (inline) TeX by separating tokenizing and POS tagging from parsing. Parsing is done by the texParse method
- object Statement
- object StringParse
- object SubTypePattern
- object TeXTranslate
- case object TermLang extends ExprLang[Term] with Domain[Term] with ExprPatterns[Term] with Product with Serializable
- object TermPatterns
Patterns, in the sense of Translator.Pattern, as well as some builders for various kinds of HoTT terms.
Patterns, in the sense of Translator.Pattern, as well as some builders for various kinds of HoTT terms. Includes matching recursively and inductively defined functions.
- object TermShapeTree extends ShapeTreeFormat
- object TermToExpr
- object TestTrait
- object TextToInt
Converts prose numbers to Integers without checking for bad cases
- object Translator
General functorial framework for translation.
General functorial framework for translation.
Translators with
I
the input type andO
the output type are primarily built from Junctions- a
which mappattern
I => Option[X[O]]
, withX[_]
a functor with traverse, e.g. a tuple or a vector. - a
builder
O => Option[I]
to avoid having to specify types too many types, traits Pattern and Builder are defined.
We also have simpler translators for literals and also wrapping translators for a component type.
- a
- object TreeModel
- object TreePatterns
- object TreeToMath