mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 09:32:53 -06:00
generalized pt -transfer so that it goes into subtrees (naive implementation in TreeOperations; using PGF.Expr.match would be better); example given in 'h pt'
This commit is contained in:
@@ -55,6 +55,7 @@ abstract Noun = Cat ** {
|
|||||||
|
|
||||||
-- $Card$ consists of either digits or numeral words.
|
-- $Card$ consists of either digits or numeral words.
|
||||||
|
|
||||||
|
data
|
||||||
NumDigits : Digits -> Card ; -- 51
|
NumDigits : Digits -> Card ; -- 51
|
||||||
NumNumeral : Numeral -> Card ; -- fifty-one
|
NumNumeral : Numeral -> Card ; -- fifty-one
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ abstract Noun = Cat ** {
|
|||||||
|
|
||||||
-- A $Card$ can be modified by certain adverbs.
|
-- A $Card$ can be modified by certain adverbs.
|
||||||
|
|
||||||
|
fun
|
||||||
AdNum : AdN -> Card -> Card ; -- almost 51
|
AdNum : AdN -> Card -> Card ; -- almost 51
|
||||||
|
|
||||||
-- An $Ord$ consists of either digits or numeral words.
|
-- An $Ord$ consists of either digits or numeral words.
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
abstract NumeralTransfer = Numeral ** {
|
abstract NumeralTransfer = Numeral, Noun ** {
|
||||||
|
|
||||||
|
fun digits2numeral : Card -> Card ;
|
||||||
|
def
|
||||||
|
digits2numeral (NumDigits d) = NumNumeral (digits2num d) ;
|
||||||
|
digits2numeral n = n ;
|
||||||
|
|
||||||
fun digits2num : Digits -> Numeral ;
|
fun digits2num : Digits -> Numeral ;
|
||||||
def digits2num (IDig d1) = num (pot2as3 (pot1as2 (pot0as1 (dn10 d1)))) ;
|
def digits2num (IDig d1) = num (pot2as3 (pot1as2 (pot0as1 (dn10 d1)))) ;
|
||||||
@@ -89,4 +94,4 @@ def nd n2 = D_2 ;
|
|||||||
nd n8 = D_8 ;
|
nd n8 = D_8 ;
|
||||||
nd n9 = D_9 ;
|
nd n9 = D_9 ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -649,7 +649,8 @@ allCommands env@(pgf, mos) = Map.fromList [
|
|||||||
"are type checking and semantic computation."
|
"are type checking and semantic computation."
|
||||||
],
|
],
|
||||||
examples = [
|
examples = [
|
||||||
"pt -compute (plus one two) -- compute value"
|
"pt -compute (plus one two) -- compute value",
|
||||||
|
"p \"4 dogs love 5 cats\" | pt -transfer=digits2numeral | l -- four...five..."
|
||||||
],
|
],
|
||||||
exec = \opts ->
|
exec = \opts ->
|
||||||
returnFromExprs . takeOptNum opts . treeOps opts,
|
returnFromExprs . takeOptNum opts . treeOps opts,
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ allTreeOps :: PGF -> [(String,(String,Either TreeOp (CId -> TreeOp)))]
|
|||||||
allTreeOps pgf = [
|
allTreeOps pgf = [
|
||||||
("compute",("compute by using semantic definitions (def)",
|
("compute",("compute by using semantic definitions (def)",
|
||||||
Left $ map (compute pgf))),
|
Left $ map (compute pgf))),
|
||||||
("transfer",("syntactic transfer by applying function and computing",
|
("transfer",("syntactic transfer by applying function, recursively in subtrees",
|
||||||
Right $ \f -> map (compute pgf . EApp (EFun f)))),
|
Right $ \f -> map (transfer pgf f))),
|
||||||
("paraphrase",("paraphrase by using semantic definitions (def)",
|
("paraphrase",("paraphrase by using semantic definitions (def)",
|
||||||
Left $ nub . concatMap (paraphrase pgf))),
|
Left $ nub . concatMap (paraphrase pgf))),
|
||||||
("smallest",("sort trees from smallest to largest, in number of nodes",
|
("smallest",("sort trees from smallest to largest, in number of nodes",
|
||||||
@@ -30,3 +30,17 @@ smallest = sortBy (\t u -> compare (size t) (size u)) where
|
|||||||
EAbs _ _ e -> size e + 1
|
EAbs _ _ e -> size e + 1
|
||||||
EApp e1 e2 -> size e1 + size e2 + 1
|
EApp e1 e2 -> size e1 + size e2 + 1
|
||||||
_ -> 1
|
_ -> 1
|
||||||
|
|
||||||
|
|
||||||
|
--- simple-minded transfer; should use PGF.Expr.match
|
||||||
|
|
||||||
|
transfer :: PGF -> CId -> Expr -> Expr
|
||||||
|
transfer pgf f e = case transf e of
|
||||||
|
v | v /= appf e -> v
|
||||||
|
_ -> case e of
|
||||||
|
EApp g a -> EApp (transfer pgf f g) (transfer pgf f a)
|
||||||
|
_ -> e
|
||||||
|
where
|
||||||
|
appf = EApp (EFun f)
|
||||||
|
transf = compute pgf . appf
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user