将某种 XML/Json 文件编译成 Graphiz/有限状态自动机。有什么建议吗?

发布于 2024-09-30 02:48:15 字数 150 浏览 3 评论 0原文

我有一个任务,我需要拍摄一些现有的图片[显示一些自动机(DFA、NFA、图灵机)]并以某种方式将它们转换为一种格式,这使我能够使用数据将其表示为自动机以及将其编译成某种图形表示形式。你们中有人以前做过类似的事情吗?是否有任何 Python 库/框架可以让我以图形方式呈现一些自动机数据?

I have a task where I need to take some existing pictures[ which show some automata (DFA, NFA, Turing machines)] and somehow convert them into a format, which enables me to use the data to represent it as an automata as well as compile it into some graphical representation. Has any of you done something similar before? Are there any Python libs/frameworks which let me present some automata data graphically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

污味仙女 2024-10-07 02:48:15

Graphviz 可以提供解决方案。从图中可以看出,有向无环图 (DAG) 的数据表示是直接且简单的。如果您按照您的评论建议手动进行操作,则可以轻松地从图表中“读取”它。下面列出了复杂图的表示(几个不同的面板,每个面板包含一个独立的 DAG)。正如 @Constantin 所说,DFA 和 NFA 可以表示为 DAG。我不确定图灵机使用什么符号,但有几种 例如无向图;我还附上生成的图的副本。

    Digraph {
graph [label="Problem Frame\nmapping editor\n",labelloc=t,fontsize=18,compound=true];
node[shape = record,fontsize = 10];
edge[arrowtail=none,arrowhead=none,arrowsize=0.8,color=ivory4,fontsize=8];

subgraph "cluster0" {
graph [label = "Model Fragment"];
A01 [label = "{Domain|class::marking\lisTemplate::boolean default false\lname::name\ltype::domain type\l}"];
A02 [label = "{Requirement|isTemplate::boolean default false\lname::name\l}"];
A03 [label = "{Requirement Reference\n\<\<associative\>\>|content::name\lis template::boolean default false\ltype::requirement reference type\l}",shape=Mrecord,style=dotted];
A04 [label = "{Shared Phenomena Set\n\<\<associative\>\>|content::name\lis template::boolean default false\ltype::phenomena type\l}",shape=Mrecord,style=dotted];

/* 1:1-0:M */
edge[dir=both,arrowhead=crowodot,arrowtail=none];
A01 -> A03 [style=dashed];
A01 -> A04 [style = dashed];
A01 -> A04 [style = dashed];
A02 -> A03 [style = dashed];
}

subgraph "cluster1" {
graph [label = "\>\>\>",fontsize = 24];
B01 [label = "{Domain}"];
B02 [label = "{Requirement}"];
B03 [label = "{Requirement\nReference\n}",shape=Mrecord,style=dotted];
B04 [label = "{Shared\nPhenomena\nSet\n}",shape=Mrecord,style=dotted];
F01 [label = "{C0001|if \[-\> controls -\> describes.isTemplate\]\l}"];
F02 [label = "{C0002|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F03 [label = "{C0003|if \[-\> controls -\> describes.type = designed\]\l}"];
F04 [label = "{C0004|if \[-\> controls -\> describes.type = given\]\l}"];
F05 [label = "{C0005|if \[-\> controls -\> describes.type = machine\]\l}"];
F06 [label = "{C0006|if \[-\> controls -\> describes.marking = biddable\]\l}"];
F07 [label = "{C0007|if \[-\> controls -\> describes.marking = causal\]\l}"];
F08 [label = "{C0008|if \[-\> controls -\> describes.marking = lexical\]\l}"];
F09 [label = "{C0009|if \[-\> controls -\> describes.marking = null\]\l}"];
F10 [label = "{C0010|if \[-\> controls -\> describes.isTemplate\]\l}"];
F11 [label = "{C0011|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F12 [label = "{C0012|if \[-\> controls -\> describes.isTemplate\]\l}"];
F13 [label = "{C0013|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F14 [label = "{C0014|if \[-\> controls -\> describes.type = non-constraining\]\l}"];
F15 [label = "{C0015|if not \[-\> controls -\> describes.type = constraining\]\l}"];
F16 [label = "{C0016|if \[-\> controls -\> describes.isTemplate\]\l}"];
F17 [label = "{C0017|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F18 [label = "{C0018|if \[-\> controls -\> describes.type = causal\]\l}"];
F19 [label = "{C0019|if \[-\> controls -\> describes.type = event\]\l}"];
F20 [label = "{C0020|if \[-\> controls -\> describes.type = symbolic\]\l}"];

edge [style = solid];
B01 -> F01 -> F02 -> F03 -> F04 -> F05 -> F06 -> F07 -> F08 -> F09;
B02 -> F10 -> F11;
B03 -> F12 -> F13 -> F14 -> F15;
B04 -> F16 -> F17 -> F18 -> F19 -> F20;

edge [style = invis];
B01 -> B02 -> B03 -> B04;
}

subgraph "cluster2" {
graph [label = "\<\<\<",fontsize = 24];
C01 [label = "{Edge|name := Constraining Reference\larrowtail := normal\ldir := both\lpermitted node1 := domain icon\lpermitted node2 := requirement icon\lstyle := dotted\l}"];
D02 [label = "{Attribute|name::oName\lvalue::-\> describes\l-\> described by.content\l}"];
C02 [label = "{Diagram|name := Frame Diagram\l}"];
C03 [label = "{Node|name := Domain Icon\lcolor = gray\lfillcolor = gold\lfontsize := 12\llabel := describes.preLabel\l + oName + describes.postLabel\lshape := Mrecord\lstyle := filled\l}"];
D03 [label = "{Attribute|name::oClass\lvalue :=-\> describes\l-\> described by.class\l}"];
D04 [label = "{Attribute|name::oName\lvalue := -\> describes\l-\> described by.name\l}"];
D05 [label = "{Attribute|name::postlabel\lvalue := \}\"\l}"];
D06 [label = "{Attribute|name::postlabel\lvalue := \|\{\|b\}\}\"\l}"];
D07 [label = "{Attribute|name::postlabel\lvalue := \|\{\|c\}\}\"\l}"];
D08 [label = "{Attribute|name::postlabel\lvalue := \|\{\|x\}\}\"\l}"];
D09 [label = "{Attribute|name::prelabel\lvalue := \"\{\|\l}"];
D10 [label = "{Attribute|name::prelabel\lvalue := \"\{\l}"];
D11 [label = "{Attribute|name::prelabel\lvalue := \"\{\|\|\l}"];
D12 [label = "{Attribute|name::oType\lvalue := -\> describes \l-\> described by.type\l}"];
C04 [label = "{Holding Box|name := Domain Template\lcolor := slategray\lfillcolor := white\lfontcolor := slategray\lfontsize := 9\llabel := oName\lreadonly := true\l}"];
D13 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.name\l}"];
C05 [label = "{Edge|name := Edge Template\lcolor := white\llabel = oName\lstyle := invis\l}"];
D14 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
C06 [label = "{Node|name := Phenomena\l}"];
D15 [label = "{Attribute|name::oName\lvalue::-\> describes\l\-\> described by.contents\l}"];
C07 [label = "{Edge|name := Reference\l}"];
D16 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
C08 [label = "{Node|name := Requirement Icon\l}"];
D17 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.name\l}"];
C09 [label = "{Edge|name := Shared Phenomena\l}"];
D18 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
D19 [label = "{Attribute|name::oType\lvalue := C\l}"];
D20 [label = "{Attribute|name::oType\lvalue := E\l}"];
D21 [label = "{Attribute|name::oType\lvalue := Y\l}"];

C01 -> D02;
C03 -> D03 -> D04 -> D05 -> D06 -> D07 -> D08 -> D09 -> D10 -> D11 -> D12;
C04 -> D13;
C05 -> D14;
C06 -> D15;
C07 -> D16;
C08 -> D17;
C09 -> D18 -> D19 -> D20 -> D21;

edge[style="invis"];
C01 -> C02 -> C03 -> C04 -> C05 -> C06 -> C07 -> C08 -> C09;
}

subgraph "cluster5" {
graph [label = "Editor Elements"];
E01 [label = "{Node\n|color::color\lfillcolor::fillcolor\lfontname::font\lfontsize::fontsize\llabel::name\lname::name\lreadonly::boolean default false\lshape::shape\lstyle::style\l}"];
E02 [label = "{Edge\n|arrowtail::edge end\ldir::dir\lname::name\lpermitted node1::name\lpermitted node2::name\lstyle::style\l}"];
E03 [label = "{Attribute\n|name::name\lvalue::text\l}"];
E04 [label = "{Diagram\n|defaults::attributes\ledge defaults::attributes\lname::name\lnode attributes::attributes\l}"];
E05 [label = "{Holding Box|color::color\lfillcolor::fillcolor\lfontname::font\lfontsize::fontsize\llabel::name\lname::name\lreadonly::boolean default false\lshape::shape\lstyle::style\l}"];

/* 0:1-N:M */
E01 -> E02 [arrowhead = crowodot, label = "links", taillabel = " 2:2"];

/* 1:1-0:M  */
edge[dir=both,arrowtail=none,arrowhead=crowodot];
E04 -> E01 [label = nodes];
E04 -> E02 [label = edges];
E04 -> E05 [label = "holding boxes"];

/* 0:1-0:M  */
edge[dir=both,arrowtail=odot,arrowhead=crowodot];
E05 -> E01 [label = "contained nodes"];
E05 -> E02 [label = "contained edges"];
E05 -> E05 [label = contains];

/* 0:1-0:M  */
edge[dir=both,arrowtail=odot,arrowhead=crowodot];
E01 -> E03 [label = characteristics];
E02 -> E03 [label = parameters];
E04 -> E03 [label = attributes];
E04 -> E03 [label = attributes];
E04 -> E03 [label = attributes];
}

{rank = min B01 C01}

edge[style="solid"];
F01 -> C04 [ltail = cluster1];
F02 -> C03 [ltail = cluster1];
F03 -> D09 [ltail = cluster1];
F04 -> D10 [ltail = cluster1];
F05 -> D11 [ltail = cluster1];
F06 -> D06 [ltail = cluster1];
F07 -> D07 [ltail = cluster1];
F08 -> D08 [ltail = cluster1];
F09 -> D05 [ltail = cluster1];
F10 -> C04 [ltail = cluster1];
F11 -> C06 [ltail = cluster1];
F11 -> C08 [ltail = cluster1];
F12 -> C05 [ltail = cluster1];
F14 -> C07 [ltail = cluster1];
F15 -> C01 [ltail = cluster1];
F16 -> C05 [ltail = cluster1];
F17 -> C06 [ltail = cluster1];
F17 -> C09 [ltail = cluster1];
F18 -> D19 [ltail = cluster1];
F19 -> D20 [ltail = cluster1];
F20 -> D21 [ltail = cluster1]; 
}

可以以类似的方式读取结构化图, https://i.sstatic.net/ksXot.png" alt="替代文本">

Graphviz can provide a solution. The data representation for a Directed Acyclic Graph (DAG) is direct and simple from the picture. It can readily be "read" off the diagram if you are doing it by hand as your comment suggests. The representation of a complex diagram (several distinct panels each containing an independent DAG is listed below. As @Constantin says, DFA and NFA can be represented as DAGs. I'm not sure about what notation is used for Turing machines, but several sorts of structured diagram can be read off in a similar fashion, eg tree structures; undirected graphs. I also attach a copy of the resulting diagram. The individual lines of the .dot file are the data items you are seeking.

    Digraph {
graph [label="Problem Frame\nmapping editor\n",labelloc=t,fontsize=18,compound=true];
node[shape = record,fontsize = 10];
edge[arrowtail=none,arrowhead=none,arrowsize=0.8,color=ivory4,fontsize=8];

subgraph "cluster0" {
graph [label = "Model Fragment"];
A01 [label = "{Domain|class::marking\lisTemplate::boolean default false\lname::name\ltype::domain type\l}"];
A02 [label = "{Requirement|isTemplate::boolean default false\lname::name\l}"];
A03 [label = "{Requirement Reference\n\<\<associative\>\>|content::name\lis template::boolean default false\ltype::requirement reference type\l}",shape=Mrecord,style=dotted];
A04 [label = "{Shared Phenomena Set\n\<\<associative\>\>|content::name\lis template::boolean default false\ltype::phenomena type\l}",shape=Mrecord,style=dotted];

/* 1:1-0:M */
edge[dir=both,arrowhead=crowodot,arrowtail=none];
A01 -> A03 [style=dashed];
A01 -> A04 [style = dashed];
A01 -> A04 [style = dashed];
A02 -> A03 [style = dashed];
}

subgraph "cluster1" {
graph [label = "\>\>\>",fontsize = 24];
B01 [label = "{Domain}"];
B02 [label = "{Requirement}"];
B03 [label = "{Requirement\nReference\n}",shape=Mrecord,style=dotted];
B04 [label = "{Shared\nPhenomena\nSet\n}",shape=Mrecord,style=dotted];
F01 [label = "{C0001|if \[-\> controls -\> describes.isTemplate\]\l}"];
F02 [label = "{C0002|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F03 [label = "{C0003|if \[-\> controls -\> describes.type = designed\]\l}"];
F04 [label = "{C0004|if \[-\> controls -\> describes.type = given\]\l}"];
F05 [label = "{C0005|if \[-\> controls -\> describes.type = machine\]\l}"];
F06 [label = "{C0006|if \[-\> controls -\> describes.marking = biddable\]\l}"];
F07 [label = "{C0007|if \[-\> controls -\> describes.marking = causal\]\l}"];
F08 [label = "{C0008|if \[-\> controls -\> describes.marking = lexical\]\l}"];
F09 [label = "{C0009|if \[-\> controls -\> describes.marking = null\]\l}"];
F10 [label = "{C0010|if \[-\> controls -\> describes.isTemplate\]\l}"];
F11 [label = "{C0011|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F12 [label = "{C0012|if \[-\> controls -\> describes.isTemplate\]\l}"];
F13 [label = "{C0013|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F14 [label = "{C0014|if \[-\> controls -\> describes.type = non-constraining\]\l}"];
F15 [label = "{C0015|if not \[-\> controls -\> describes.type = constraining\]\l}"];
F16 [label = "{C0016|if \[-\> controls -\> describes.isTemplate\]\l}"];
F17 [label = "{C0017|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F18 [label = "{C0018|if \[-\> controls -\> describes.type = causal\]\l}"];
F19 [label = "{C0019|if \[-\> controls -\> describes.type = event\]\l}"];
F20 [label = "{C0020|if \[-\> controls -\> describes.type = symbolic\]\l}"];

edge [style = solid];
B01 -> F01 -> F02 -> F03 -> F04 -> F05 -> F06 -> F07 -> F08 -> F09;
B02 -> F10 -> F11;
B03 -> F12 -> F13 -> F14 -> F15;
B04 -> F16 -> F17 -> F18 -> F19 -> F20;

edge [style = invis];
B01 -> B02 -> B03 -> B04;
}

subgraph "cluster2" {
graph [label = "\<\<\<",fontsize = 24];
C01 [label = "{Edge|name := Constraining Reference\larrowtail := normal\ldir := both\lpermitted node1 := domain icon\lpermitted node2 := requirement icon\lstyle := dotted\l}"];
D02 [label = "{Attribute|name::oName\lvalue::-\> describes\l-\> described by.content\l}"];
C02 [label = "{Diagram|name := Frame Diagram\l}"];
C03 [label = "{Node|name := Domain Icon\lcolor = gray\lfillcolor = gold\lfontsize := 12\llabel := describes.preLabel\l + oName + describes.postLabel\lshape := Mrecord\lstyle := filled\l}"];
D03 [label = "{Attribute|name::oClass\lvalue :=-\> describes\l-\> described by.class\l}"];
D04 [label = "{Attribute|name::oName\lvalue := -\> describes\l-\> described by.name\l}"];
D05 [label = "{Attribute|name::postlabel\lvalue := \}\"\l}"];
D06 [label = "{Attribute|name::postlabel\lvalue := \|\{\|b\}\}\"\l}"];
D07 [label = "{Attribute|name::postlabel\lvalue := \|\{\|c\}\}\"\l}"];
D08 [label = "{Attribute|name::postlabel\lvalue := \|\{\|x\}\}\"\l}"];
D09 [label = "{Attribute|name::prelabel\lvalue := \"\{\|\l}"];
D10 [label = "{Attribute|name::prelabel\lvalue := \"\{\l}"];
D11 [label = "{Attribute|name::prelabel\lvalue := \"\{\|\|\l}"];
D12 [label = "{Attribute|name::oType\lvalue := -\> describes \l-\> described by.type\l}"];
C04 [label = "{Holding Box|name := Domain Template\lcolor := slategray\lfillcolor := white\lfontcolor := slategray\lfontsize := 9\llabel := oName\lreadonly := true\l}"];
D13 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.name\l}"];
C05 [label = "{Edge|name := Edge Template\lcolor := white\llabel = oName\lstyle := invis\l}"];
D14 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
C06 [label = "{Node|name := Phenomena\l}"];
D15 [label = "{Attribute|name::oName\lvalue::-\> describes\l\-\> described by.contents\l}"];
C07 [label = "{Edge|name := Reference\l}"];
D16 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
C08 [label = "{Node|name := Requirement Icon\l}"];
D17 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.name\l}"];
C09 [label = "{Edge|name := Shared Phenomena\l}"];
D18 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
D19 [label = "{Attribute|name::oType\lvalue := C\l}"];
D20 [label = "{Attribute|name::oType\lvalue := E\l}"];
D21 [label = "{Attribute|name::oType\lvalue := Y\l}"];

C01 -> D02;
C03 -> D03 -> D04 -> D05 -> D06 -> D07 -> D08 -> D09 -> D10 -> D11 -> D12;
C04 -> D13;
C05 -> D14;
C06 -> D15;
C07 -> D16;
C08 -> D17;
C09 -> D18 -> D19 -> D20 -> D21;

edge[style="invis"];
C01 -> C02 -> C03 -> C04 -> C05 -> C06 -> C07 -> C08 -> C09;
}

subgraph "cluster5" {
graph [label = "Editor Elements"];
E01 [label = "{Node\n|color::color\lfillcolor::fillcolor\lfontname::font\lfontsize::fontsize\llabel::name\lname::name\lreadonly::boolean default false\lshape::shape\lstyle::style\l}"];
E02 [label = "{Edge\n|arrowtail::edge end\ldir::dir\lname::name\lpermitted node1::name\lpermitted node2::name\lstyle::style\l}"];
E03 [label = "{Attribute\n|name::name\lvalue::text\l}"];
E04 [label = "{Diagram\n|defaults::attributes\ledge defaults::attributes\lname::name\lnode attributes::attributes\l}"];
E05 [label = "{Holding Box|color::color\lfillcolor::fillcolor\lfontname::font\lfontsize::fontsize\llabel::name\lname::name\lreadonly::boolean default false\lshape::shape\lstyle::style\l}"];

/* 0:1-N:M */
E01 -> E02 [arrowhead = crowodot, label = "links", taillabel = " 2:2"];

/* 1:1-0:M  */
edge[dir=both,arrowtail=none,arrowhead=crowodot];
E04 -> E01 [label = nodes];
E04 -> E02 [label = edges];
E04 -> E05 [label = "holding boxes"];

/* 0:1-0:M  */
edge[dir=both,arrowtail=odot,arrowhead=crowodot];
E05 -> E01 [label = "contained nodes"];
E05 -> E02 [label = "contained edges"];
E05 -> E05 [label = contains];

/* 0:1-0:M  */
edge[dir=both,arrowtail=odot,arrowhead=crowodot];
E01 -> E03 [label = characteristics];
E02 -> E03 [label = parameters];
E04 -> E03 [label = attributes];
E04 -> E03 [label = attributes];
E04 -> E03 [label = attributes];
}

{rank = min B01 C01}

edge[style="solid"];
F01 -> C04 [ltail = cluster1];
F02 -> C03 [ltail = cluster1];
F03 -> D09 [ltail = cluster1];
F04 -> D10 [ltail = cluster1];
F05 -> D11 [ltail = cluster1];
F06 -> D06 [ltail = cluster1];
F07 -> D07 [ltail = cluster1];
F08 -> D08 [ltail = cluster1];
F09 -> D05 [ltail = cluster1];
F10 -> C04 [ltail = cluster1];
F11 -> C06 [ltail = cluster1];
F11 -> C08 [ltail = cluster1];
F12 -> C05 [ltail = cluster1];
F14 -> C07 [ltail = cluster1];
F15 -> C01 [ltail = cluster1];
F16 -> C05 [ltail = cluster1];
F17 -> C06 [ltail = cluster1];
F17 -> C09 [ltail = cluster1];
F18 -> D19 [ltail = cluster1];
F19 -> D20 [ltail = cluster1];
F20 -> D21 [ltail = cluster1]; 
}

alt text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文