mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-29 12:48:54 -06:00
better tree viz
This commit is contained in:
@@ -65,9 +65,9 @@ lincat
|
|||||||
V2A = TransVerb ; ----
|
V2A = TransVerb ; ----
|
||||||
V0 = Verb ;
|
V0 = Verb ;
|
||||||
|
|
||||||
---- TP = {s : Str ; b : Bool ; t : Tense ; a : Anteriority} ; --- the Str field is dummy
|
TP = {s : Str ; b : Bool ; t : Tense ; a : Anteriority} ; --- the Str field is dummy
|
||||||
---- Tense = {s : Str ; t : Tense} ;
|
Tense = {s : Str ; t : Tense} ;
|
||||||
---- Ant = {s : Str ; a : Anteriority} ;
|
Ant = {s : Str ; a : Anteriority} ;
|
||||||
|
|
||||||
PP = {s : Str} ;
|
PP = {s : Str} ;
|
||||||
Adv = {s : Str} ;
|
Adv = {s : Str} ;
|
||||||
@@ -76,8 +76,8 @@ lincat
|
|||||||
AdC = {s : Str} ;
|
AdC = {s : Str} ;
|
||||||
|
|
||||||
S = {s : Str} ;
|
S = {s : Str} ;
|
||||||
---- Cl = Clause ;
|
Cl = Clause ;
|
||||||
-- = {s : Order => Bool => SForm => Str} ;
|
-- = {s : SType => Bool => SForm => Str} ;
|
||||||
|
|
||||||
Slash = Sentence ** {s2 : Str ; c : Case} ;
|
Slash = Sentence ** {s2 : Str ; c : Case} ;
|
||||||
|
|
||||||
|
|||||||
@@ -73,24 +73,25 @@ lin
|
|||||||
|
|
||||||
---- PredAS = predAdjSent ;
|
---- PredAS = predAdjSent ;
|
||||||
---- PredV0 rain = predVerbClause (pronNounPhrase pronIt) rain (complVerb rain) ;
|
---- PredV0 rain = predVerbClause (pronNounPhrase pronIt) rain (complVerb rain) ;
|
||||||
{-
|
|
||||||
-- Partial saturation.
|
-- Partial saturation.
|
||||||
|
|
||||||
UseV2 = transAsVerb ;
|
UseV2 v = v ;
|
||||||
|
|
||||||
ComplA2S = predAdjSent2 ;
|
---- ComplA2S = predAdjSent2 ;
|
||||||
|
|
||||||
AdjPart = adjPastPart ;
|
---- AdjPart = adjPastPart ;
|
||||||
|
|
||||||
|
---- UseV2V x = verb2aux x ** {isAux = False} ;
|
||||||
|
|
||||||
UseV2V x = verb2aux x ** {isAux = False} ;
|
|
||||||
UseV2S x = x ;
|
UseV2S x = x ;
|
||||||
UseV2Q x = x ;
|
UseV2Q x = x ;
|
||||||
UseA2S x = x ;
|
UseA2S x = x ;
|
||||||
UseA2V x = x ;
|
UseA2V x = x ;
|
||||||
|
|
||||||
UseCl tp cl = {s = tp.s ++ cl.s ! Dir ! tp.b ! VFinite tp.t tp.a} ;
|
UseCl tp cl = {s = tp.s ++ cl.s ! SDecl ! tp.b ! VFinite tp.t tp.a} ;
|
||||||
UseQCl tp cl = {s = \\q => tp.s ++ cl.s ! tp.b ! VFinite tp.t tp.a ! q} ;
|
---- UseQCl tp cl = {s = \\q => tp.s ++ cl.s ! tp.b ! VFinite tp.t tp.a ! q} ;
|
||||||
UseRCl tp cl = {s = \\a => tp.s ++ cl.s ! tp.b ! VFinite tp.t tp.a ! a} ;
|
---- UseRCl tp cl = {s = \\a => tp.s ++ cl.s ! tp.b ! VFinite tp.t tp.a ! a} ;
|
||||||
|
|
||||||
PosTP t a = {s = t.s ++ a.s ; b = True ; t = t.t ; a = a.a} ;
|
PosTP t a = {s = t.s ++ a.s ; b = True ; t = t.t ; a = a.a} ;
|
||||||
NegTP t a = {s = t.s ++ a.s ; b = False ; t = t.t ; a = a.a} ;
|
NegTP t a = {s = t.s ++ a.s ; b = False ; t = t.t ; a = a.a} ;
|
||||||
@@ -102,7 +103,7 @@ lin
|
|||||||
|
|
||||||
ASimul = {s = [] ; a = Simul} ;
|
ASimul = {s = [] ; a = Simul} ;
|
||||||
AAnter = {s = [] ; a = Anter} ;
|
AAnter = {s = [] ; a = Anter} ;
|
||||||
-}
|
|
||||||
-- Adverbs.
|
-- Adverbs.
|
||||||
|
|
||||||
---- AdjAdv a = ss (a.s ! AAttr ! AAdv) ; --- also APred?
|
---- AdjAdv a = ss (a.s ! AAttr ! AAdv) ; --- also APred?
|
||||||
|
|||||||
@@ -458,12 +458,31 @@ oper
|
|||||||
--
|
--
|
||||||
--3 Verb phrases
|
--3 Verb phrases
|
||||||
--
|
--
|
||||||
|
-- These are parameters for clauses and sentences.
|
||||||
|
|
||||||
|
param
|
||||||
|
|
||||||
|
Tense = Present | Past | Future | Conditional ;
|
||||||
|
Anteriority = Simul | Anter ;
|
||||||
|
|
||||||
|
SForm =
|
||||||
|
VFinite Tense Anteriority
|
||||||
|
| VInfinit Anteriority
|
||||||
|
| VPresPart
|
||||||
|
;
|
||||||
|
|
||||||
|
SType = SDecl | SQuest ;
|
||||||
|
|
||||||
|
oper
|
||||||
|
Clause : Type = {s : SType => Bool => SForm => Str} ;
|
||||||
|
|
||||||
-- Verb phrases are discontinuous: the two parts of a verb phrase are
|
-- Verb phrases are discontinuous: the two parts of a verb phrase are
|
||||||
-- (s) an inflected verb, (s2) a complement.
|
-- (s) an inflected verb, (s2) a complement.
|
||||||
-- For instance: "on" - "kaunis" ; "ei" - "ole kaunis" ; "sisältää" - "rikkiä".
|
-- For instance: "on" - "kaunis" ; "ei" - "ole kaunis" ; "sisältää" - "rikkiä".
|
||||||
-- Moreover, a subject case is needed, because of passive and 'have' verb
|
-- Moreover, a subject case is needed, because of passive and 'have' verb
|
||||||
-- phrases ("minä uin" ; "minut valitaan" ; "minua odotetaan" ; "minulla on jano").
|
-- phrases ("minä uin" ; "minut valitaan" ; "minua odotetaan" ; "minulla on jano").
|
||||||
|
|
||||||
|
oper
|
||||||
VerbPhrase = Verb ** {s2 : VForm => Str ; c : ComplCase} ;
|
VerbPhrase = Verb ** {s2 : VForm => Str ; c : ComplCase} ;
|
||||||
VerbGroup = {s,s2 : Bool => VForm => Str ; c : ComplCase} ;
|
VerbGroup = {s,s2 : Bool => VForm => Str ; c : ComplCase} ;
|
||||||
|
|
||||||
|
|||||||
@@ -26,28 +26,31 @@ import Data.List (intersperse, nub)
|
|||||||
import Data.Maybe (maybeToList)
|
import Data.Maybe (maybeToList)
|
||||||
|
|
||||||
visualizeTrees :: Options -> [Tree] -> String
|
visualizeTrees :: Options -> [Tree] -> String
|
||||||
visualizeTrees opts = unlines . map (prGraph . tree2graph opts)
|
visualizeTrees opts = unlines . map (prGraph opts . tree2graph opts)
|
||||||
|
|
||||||
tree2graph :: Options -> Tree -> [String]
|
tree2graph :: Options -> Tree -> [String]
|
||||||
tree2graph opts = prf (0,0) where
|
tree2graph opts = prf [] where
|
||||||
prf (i,j) t@(Tr (node, trees)) =
|
prf ps t@(Tr (node, trees)) =
|
||||||
let nod = prn (i,j) node in
|
let (nod,lab) = prn ps node in
|
||||||
(nod ++ " [style = \"solid\", shape = \"plaintext\"] ;") :
|
(nod ++ " [label = " ++ lab ++ ", style = \"solid\", shape = \"plaintext\"] ;") :
|
||||||
[pra (i+1,j) nod t | (j,t) <- zip [0..] trees] ++
|
[ pra (j:ps) nod t | (j,t) <- zip [0..] trees] ++
|
||||||
concat [prf (i+1,j) t | (j,t) <- zip [0..] trees]
|
concat [prf (j:ps) t | (j,t) <- zip [0..] trees]
|
||||||
prn (i,j) (N (bi,at,val,_,_)) =
|
prn ps (N (bi,at,val,_,_)) =
|
||||||
"\"" ++ prs i ++
|
let
|
||||||
|
lab =
|
||||||
|
"\"" ++
|
||||||
prb bi ++
|
prb bi ++
|
||||||
prc at val ++
|
prc at val ++
|
||||||
prs j ++ "\""
|
"\""
|
||||||
|
in if oElem (iOpt "g") opts then (lab,lab) else (show(show (ps :: [Int])),lab)
|
||||||
prb [] = ""
|
prb [] = ""
|
||||||
prb bi = "\\" ++ concat (intersperse "," (map (prt_ . fst) bi)) ++ " -> "
|
prb bi = "\\" ++ concat (intersperse "," (map (prt_ . fst) bi)) ++ " -> "
|
||||||
pra i nod t@(Tr (node,_)) = nod ++ " -- " ++ prn i node ++ " [style = \"solid\"];"
|
pra i nod t@(Tr (node,_)) = nod ++ arr ++ fst (prn i node) ++ " [style = \"solid\"];"
|
||||||
|
|
||||||
prs k = if oElem (iOpt "g") opts then "" else replicate k ' '
|
|
||||||
prc a v
|
prc a v
|
||||||
| oElem (iOpt "c") opts = prt_ v
|
| oElem (iOpt "c") opts = prt_ v
|
||||||
| oElem (iOpt "f") opts = prt_ a
|
| oElem (iOpt "f") opts = prt_ a
|
||||||
| otherwise = prt_ a ++ " : " ++ prt_ v
|
| otherwise = prt_ a ++ " : " ++ prt_ v
|
||||||
|
arr = if oElem (iOpt "g") opts then " -> " else " -- "
|
||||||
|
|
||||||
prGraph ns = concat $ map (++"\n") $ ["graph {\n"] ++ ns ++ ["}"]
|
prGraph opts ns = concat $ map (++"\n") $ [graph ++ "{\n"] ++ ns ++ ["}"] where
|
||||||
|
graph = if oElem (iOpt "g") opts then "digraph" else "graph"
|
||||||
|
|||||||
Reference in New Issue
Block a user