Commit 1cf50e7e authored by jfschaefer's avatar jfschaefer
Browse files

can parse prime example sentence now

parent 5b18ed44
......@@ -2,6 +2,15 @@
abstract FGrammar = MCats ** {
fun
fidentifier_to_fcomplexidentifier : FIdentifier -> FComplexIdentifier; -- n -> mi ( n )
fnumeral_to_fexpression : FNumeral -> FExpression; -- 1 -> mn ( 1 )
fcomplexidentifier_to_fexpression : FComplexIdentifier -> FExpression;
fexpression_row : FExpression -> FExpression;
apply_bin_rel : FBinRelation -> FExpression -> FExpression -> FStatement;
fstatement_to_statement : FStatement -> Statement;
fcomplexidentifier_to_mathcn : FComplexIdentifier -> MathCN; -- mi ( n ) => $ mi ( cn )
fexpr_fbinrel_fcid_fbinrel_fexpr_to_mathcn : -- introduces one identifier (like in 1 < n < 10)
FExpression -> FBinRelation -> FComplexIdentifier -> FBinRelation -> FExpression -> MathCN;
}
concrete FGrammarEng of FGrammar = MCatsEng ** open ParadigmsEng in {
concrete FGrammarEng of FGrammar = MCatsEng, CatEng ** open ParadigmsEng, ResEng, Prelude in {
oper
wrap_mml : Str -> Str -> Str = \wrapper,content -> wrapper ++ "(" ++ content ++ ")";
wrap_mml : Str -> Str -> Str = \wrapper,content -> wrapper + "(" ++ content ++ ")";
mkMathCN_sg : Str -> CN = \s -> lin CN { s = table { Sg => table { _ => s }; _ => table { _ => "???" } }; g = nonhuman };
lin
fidentifier_to_fcomplexidentifier i = wrap_mml "mi" i;
fcomplexidentifier_to_mathcn fci = lin CN {
s = table { singular => table { _ => "$" ++ fci ++ "$" } };
g = nonhuman };
fnumeral_to_fexpression n = wrap_mml "mn" n;
fcomplexidentifier_to_fexpression c = c;
fexpression_row expr = wrap_mml "mrow" expr;
apply_bin_rel rel a b = wrap_mml "mrow" (a ++ (wrap_mml "mo" rel) ++ b);
fstatement_to_statement fstmt = lin Cl { s = table {
Pres => table {
Simul => table { CPos => table { _ => "$" ++ fstmt ++ "$" }; _ => table { _ => "???" } };
_ => table { _ => table { _ => "???" } } };
_ => table { _ => table { _ => table { _ => "???" } } } } };
fcomplexidentifier_to_mathcn fci = mkMathCN_sg ("$" ++ fci ++ "$");
fexpr_fbinrel_fcid_fbinrel_fexpr_to_mathcn a r1 b r2 c =
mkMathCN_sg ("$" ++ (wrap_mml "mrow" (a ++ (wrap_mml "mo" r1) ++ b ++ (wrap_mml "mo" r2) ++ c)) ++ "$");
}
......@@ -3,4 +3,10 @@
abstract FLexicon = MCats ** {
fun
n_FIdentifier : FIdentifier;
m_FIdentifier : FIdentifier;
one_FNumeral : FNumeral;
lessThan_FBinRelation : FBinRelation;
divides_FBinRelation : FBinRelation;
}
concrete FLexiconEng of FLexicon = MCatsEng ** {
lin
n_FIdentifier = "n";
m_FIdentifier = "m";
one_FNumeral = "1";
lessThan_FBinRelation = "<";
divides_FBinRelation = "|";
}
-- categories
abstract MCats = {
cat
-- natural language
PosNegPol; -- category for the polarity of a statement (is the case vs is not the case)
DefMObj; -- definite math object ("the largest element", ...)
MObj; -- math object ("prime number", "group", ...)
MObjProp; -- math object properties ("eve", "prime", "divisble by 2", ...)
......@@ -9,7 +12,14 @@ abstract MCats = {
Definition; -- definition
Utterance; -- (finished) statement or definition
-- formulae
FIdentifier; -- identifier literals in formulae (e.g. "n")
FNumeral; -- numeral (e.g. "1")
FBinRelation; -- binary relations (e.g. "<")
FComplexIdentifier; -- complex identifier in formuale (e.g. "x_1")
FExpression; -- expression
FStatement; -- statement
MathCN; -- math common noun (e.g. $ mo ( n ) $)
}
concrete MCatsEng of MCats = open SyntaxEng in {
lincat
-- natural language
PosNegPol = Pol;
DefMObj = NP;
MObj = CN;
MObjProp = AP;
Statement = Cl;
StatementFin = S;
Definition = Cl;
Definition = S;
Utterance = Utt;
-- formulae
FIdentifier = Str;
FNumeral = Str;
FBinRelation = Str;
FComplexIdentifier = Str;
FExpression = Str;
FStatement = Str;
MathCN = CN;
}
-- abstract grammar for natural language
abstract NGrammar = MCats, Grammar, Extra, ExtraEngAbs ** {
fun
PosPol : PosNegPol;
NegPol : PosNegPol;
restrict_mobj : MObjProp -> MObj -> MObj; -- "even" -> "integer" -> "even integer"
mobj_such_that : MObj -> Statement -> PosNegPol -> MObj; -- "integer such that ..."
def_descr_mobj : MObj -> DefMObj; -- "cube" -> "the cube"
appo_mobj : MObj -> MathCN -> MObj; -- "an integer $ mi ( n ) $
......@@ -9,13 +14,13 @@ abstract NGrammar = MCats, Grammar, Extra, ExtraEngAbs ** {
not_exists_statement : MObj -> Statement; -- "integer" -> "there is no integer"
eq_defmobj_defmobj : DefMObj -> DefMObj -> Statement; -- "the largest element is the maximum"
state : Statement -> StatementFin; -- essentially identity
neg_state : Statement -> StatementFin; -- negation
state : Statement -> PosNegPol -> StatementFin;
iff_statementfin : StatementFin -> StatementFin -> StatementFin;
and_statementfin : StatementFin -> StatementFin -> StatementFin;
or_statementfin : StatementFin -> StatementFin -> StatementFin;
def_mobj_mobjprop : MObj -> MObjProp -> Definition; -- "an integer is called prime"
iff_definition : Definition -> StatementFin -> Definition; -- "... is called ... iff ..."
utter_statement : StatementFin -> Utterance; -- essentially identity
utter_definition : Definition -> Utterance; -- essentially identity
......
concrete NGrammarEng of NGrammar = MCatsEng, GrammarEng, ExtraEng ** open SyntaxEng, ParadigmsEng in {
lin
PosPol = GrammarEng.PPos;
NegPol = GrammarEng.PNeg;
restrict_mobj prop obj = mkCN prop obj;
def_descr_mobj obj = mkNP the_Art obj;
mobj_such_that obj restr pol = mkCN obj (mkRS pol (mkRCl restr));
appo_mobj obj mcn = lin CN { s = \\number,case_ => obj.s ! number ! case_ ++ mcn.s ! number ! case_; g = obj.g };
exists_statement obj = mkCl obj | ExistsNP (mkNP aSg_Det obj);
not_exists_statement obj = mkCl (mkNP no_Quant obj) | ExistsNP (mkNP no_Quant obj);
eq_defmobj_defmobj a b = mkCl a b;
state s = mkS GrammarEng.PPos s;
neg_state s = mkS GrammarEng.PNeg s;
state s pol = mkS pol s;
iff_statementfin a b = mkS (mkConj "iff") a b;
and_statementfin a b = mkS (mkConj "and") a b;
or_statementfin a b = mkS (mkConj "or") a b;
def_mobj_mobjprop obj prop = mkCl
def_mobj_mobjprop obj prop = mkS (mkCl
(mkNP aSg_Det obj)
(PastPartAP (mkVPSlash (mkV2A (mkV "call" "calls" "called" "called" "calling") noPrep) prop));
(PastPartAP (mkVPSlash (mkV2A (mkV "call" "calls" "called" "called" "calling") noPrep) prop)));
-- iff_definition defi condition = lin S { s = "iff" }; -- better solution for this?
iff_definition defi condition = lin S { s = defi.s ++ "iff" ++ condition.s }; -- better solution for this?
utter_statement s = mkUtt s;
utter_definition s = mkUtt s;
......
......@@ -3,4 +3,6 @@ abstract NLexicon = MCats ** {
fun
integer_MObj : MObj;
even_MObjProp : MObjProp;
positive_MObjProp : MObjProp;
prime_MObjProp : MObjProp;
}
......@@ -2,4 +2,6 @@ concrete NLexiconEng of NLexicon = MCatsEng ** open SyntaxEng, ParadigmsEng in {
lin
integer_MObj = mkCN (mkN "integer");
even_MObjProp = mkAP (mkA "even");
positive_MObjProp = mkAP (mkA "positive");
prime_MObjProp = mkAP (mkA "prime");
}
i MNlpEng.gf
parse "a positive integer $ mi( n ) $ is called prime iff there is no integer $ mrow( mn( 1 ) mo( < ) mi( m ) mo( < ) mi( n ) ) $ such that $ mrow( mi( m ) mo( | ) mi( n ) ) $"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment