mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
started a graphviz visualization for the LR(0) automaton
This commit is contained in:
@@ -48,6 +48,7 @@ exportPGF opts fmt pgf =
|
|||||||
FmtSLF -> single "slf" slfPrinter
|
FmtSLF -> single "slf" slfPrinter
|
||||||
FmtRegExp -> single "rexp" regexpPrinter
|
FmtRegExp -> single "rexp" regexpPrinter
|
||||||
FmtFA -> single "dot" slfGraphvizPrinter
|
FmtFA -> single "dot" slfGraphvizPrinter
|
||||||
|
FmtLR -> single "dot" (\_ -> graphvizLRAutomaton)
|
||||||
where
|
where
|
||||||
name = fromMaybe (abstractName pgf) (flag optName opts)
|
name = fromMaybe (abstractName pgf) (flag optName opts)
|
||||||
|
|
||||||
@@ -58,4 +59,3 @@ exportPGF opts fmt pgf =
|
|||||||
|
|
||||||
single :: String -> (PGF -> Concr -> String) -> [(FilePath,String)]
|
single :: String -> (PGF -> Concr -> String) -> [(FilePath,String)]
|
||||||
single ext pr = [(concreteName cnc <.> ext, pr pgf cnc) | cnc <- Map.elems (languages pgf)]
|
single ext pr = [(concreteName cnc <.> ext, pr pgf cnc) | cnc <- Map.elems (languages pgf)]
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ data OutputFormat = FmtPGFPretty
|
|||||||
| FmtSLF
|
| FmtSLF
|
||||||
| FmtRegExp
|
| FmtRegExp
|
||||||
| FmtFA
|
| FmtFA
|
||||||
|
| FmtLR
|
||||||
deriving (Eq,Ord)
|
deriving (Eq,Ord)
|
||||||
|
|
||||||
data SISRFormat =
|
data SISRFormat =
|
||||||
@@ -490,7 +491,8 @@ outputFormatsExpl =
|
|||||||
(("vxml", FmtVoiceXML),"Voice XML based on abstract syntax"),
|
(("vxml", FmtVoiceXML),"Voice XML based on abstract syntax"),
|
||||||
(("slf", FmtSLF),"SLF speech recognition format"),
|
(("slf", FmtSLF),"SLF speech recognition format"),
|
||||||
(("regexp", FmtRegExp),"regular expression"),
|
(("regexp", FmtRegExp),"regular expression"),
|
||||||
(("fa", FmtFA),"finite automaton in graphviz format")
|
(("fa", FmtFA),"finite automaton in graphviz format"),
|
||||||
|
(("lr", FmtLR),"LR(0) automaton for PMCFG in graphviz format")
|
||||||
]
|
]
|
||||||
|
|
||||||
instance Show OutputFormat where
|
instance Show OutputFormat where
|
||||||
|
|||||||
@@ -3137,3 +3137,30 @@ pgf_align_words(PgfDB *db, PgfConcrRevision revision,
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API PgfText *
|
||||||
|
pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExn *err)
|
||||||
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
|
DB_scope scope(db, READER_SCOPE);
|
||||||
|
|
||||||
|
ref<PgfConcr> concr = db->revision2concr(revision);
|
||||||
|
|
||||||
|
PgfPrinter printer(NULL,0,NULL);
|
||||||
|
|
||||||
|
printer.puts("digraph {");
|
||||||
|
for (size_t i = 0; i < concr->lrtable->len; i++) {
|
||||||
|
ref<PgfLRState> state = vector_elem(concr->lrtable, i);
|
||||||
|
for (size_t j = 0; j < state->shifts->len; j++) {
|
||||||
|
ref<PgfLRShift> shift = vector_elem(state->shifts, j);
|
||||||
|
printer.nprintf(16, " s%zu -> s%zu;\n", i, shift->next_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printer.puts("}");
|
||||||
|
|
||||||
|
return printer.get_text();
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -906,4 +906,8 @@ pgf_align_words(PgfDB *db, PgfConcrRevision revision,
|
|||||||
size_t *n_phrases /* out */,
|
size_t *n_phrases /* out */,
|
||||||
PgfExn* err);
|
PgfExn* err);
|
||||||
|
|
||||||
|
PGF_API PgfText *
|
||||||
|
pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExn *err);
|
||||||
|
|
||||||
#endif // PGF_H_
|
#endif // PGF_H_
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ module PGF2 (-- * PGF
|
|||||||
graphvizAbstractTree, graphvizParseTree,
|
graphvizAbstractTree, graphvizParseTree,
|
||||||
Labels, getDepLabels,
|
Labels, getDepLabels,
|
||||||
graphvizDependencyTree, conlls2latexDoc, getCncDepLabels,
|
graphvizDependencyTree, conlls2latexDoc, getCncDepLabels,
|
||||||
graphvizWordAlignment,
|
graphvizWordAlignment, graphvizLRAutomaton,
|
||||||
|
|
||||||
-- * Concrete syntax
|
-- * Concrete syntax
|
||||||
ConcName,Concr,languages,concreteName,languageCode,concreteFlag,
|
ConcName,Concr,languages,concreteName,languageCode,concreteFlag,
|
||||||
@@ -1389,6 +1389,15 @@ graphvizDependencyTree
|
|||||||
-> String -- ^ Rendered output in the specified format
|
-> String -- ^ Rendered output in the specified format
|
||||||
graphvizDependencyTree format debug mlab mclab concr t = error "TODO: graphvizDependencyTree"
|
graphvizDependencyTree format debug mlab mclab concr t = error "TODO: graphvizDependencyTree"
|
||||||
|
|
||||||
|
graphvizLRAutomaton :: Concr -> String
|
||||||
|
graphvizLRAutomaton c =
|
||||||
|
unsafePerformIO $
|
||||||
|
withForeignPtr (c_revision c) $ \c_revision ->
|
||||||
|
bracket (withPgfExn "graphvizLRAutomaton" (pgf_graphviz_lr_automaton (c_db c) c_revision)) free $ \c_text ->
|
||||||
|
if c_text == nullPtr
|
||||||
|
then return ""
|
||||||
|
else peekText c_text
|
||||||
|
|
||||||
---------------------- should be a separate module?
|
---------------------- should be a separate module?
|
||||||
|
|
||||||
-- visualization with latex output. AR Nov 2015
|
-- visualization with latex output. AR Nov 2015
|
||||||
|
|||||||
@@ -315,6 +315,8 @@ foreign import ccall pgf_graphviz_parse_tree :: Ptr PgfDB -> Ptr Concr -> Stable
|
|||||||
|
|
||||||
foreign import ccall pgf_graphviz_word_alignment :: Ptr PgfDB -> Ptr (Ptr Concr) -> CSize -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfGraphvizOptions -> Ptr PgfExn -> IO (Ptr PgfText)
|
foreign import ccall pgf_graphviz_word_alignment :: Ptr PgfDB -> Ptr (Ptr Concr) -> CSize -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfGraphvizOptions -> Ptr PgfExn -> IO (Ptr PgfText)
|
||||||
|
|
||||||
|
foreign import ccall pgf_graphviz_lr_automaton :: Ptr PgfDB -> Ptr Concr -> Ptr PgfExn -> IO (Ptr PgfText)
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- Texts
|
-- Texts
|
||||||
|
|||||||
Reference in New Issue
Block a user