Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Diagram to Text and Vice Versa (DAG, RTN)

by dimar (Curate)
on Nov 08, 2004 at 15:56 UTC ( #406087=perlquestion: print w/replies, xml ) Need Help??

dimar has asked for the wisdom of the Perl Monks concerning the following question:

I am requesting leads, suggestions and comments for the following problem. The problem is, how can one graphically 'draw' *diagrams* (aka graphs, directed-graphs, recursive transition networks, etc) and have that *diagram* be spit out into text? (We already know how to do the reverse with perl and GraphViz).

In other words, I would like to be able to start by drawing something like specimen1 and then from that, automatically generate something like specimen2. I would also like to be able to do the reverse.

The key sticking point is *bi-directional interactivity* it should be easy to go from diagram to text or text to diagram. It doesn't have to be native perl, (XML, SVG, GraphViz dot files or anything works, just as long as it is text or non-proprietary binary format).

No. This is not a homework question. It is part of my due dilligence investigation before I undertake to develop this myself, because if there is no such tool out there, I think it would be useful to either make one, or morph something that already exists into what is described here. In case anyone is wondering, I am leaning toward wxPerl, because of the highly graphical and lexical nature of this undertaking. Critique is welcome.


sentence:                     +-----------+
                            +>| adjective |>+
          +-------------+   | +-----------+ | +------+  +------+
(start)->-| preposition |->-+------->-------+>| noun |--| verb |-(end)
          +-------------+                     +------+  +------+
adjective:       +---------+
             +---| "large" |--+
             |   +---------+  |
             |   +---------+  |
(start) -->--+---| "green" |--+-->-- (end)
             |   +---------+  |
             |   +---------+  |
             +---| "round" |--+


sentence: pronoun ( adjective | "" ) noun verb ;

adjective: "large" | "green" | "round" ;

The information here and here and here was useful, but unfortunately none of them address both the *bidirectional* aspect and the *graphical* aspect ... the combined goal here.

Any welcome suggestions?

  • Comment on Diagram to Text and Vice Versa (DAG, RTN)

Replies are listed 'Best First'.
Re: Diagram to Text and Vice Versa (DAG, RTN)
by ikegami (Pope) on Nov 08, 2004 at 16:38 UTC
    I've done work on converting from graph form to text form. (Well, technically, I went from graph to a parse tree, but it's trivial to convert the parse tree into something with the syntax of "specimen 2".) Check out the working code at Parsing 2D Graphs and the Parse::RecDescent version. (Update: I just noticed you link to these indirectly through castaway's post.) It wasn't easy, but it handles choices and loops. The problem with it is that it expects valid data. Adding error checking is doable, but it would take time. Feel free to use any or all parts of it, and feel free to ask me any questions, given how poorly it is documented.
Re: Diagram to Text and Vice Versa (DAG, RTN)
by elwarren (Curate) on Nov 08, 2004 at 20:06 UTC
    Check out JT's Text::Flowchart to save you some work generating your text rendering.

    If you want all of these things to be interchangable and bi-directional, you're going to need to store your metadata and regenerate your diagrams. That's the only way to keep them consistent.

Re: Diagram to Text and Vice Versa (DAG, RTN)
by toma (Vicar) on Nov 09, 2004 at 05:32 UTC
    In electronic design the diagram is a 'schematic' and the text is a 'netlist'. Open source code, which is almost all not perl, is at Open Collector.

    There are tools to extract netlists, compare netlists, check for errors (eg outputs connected to outputs), etc.

    It would be great to build a netlister and schematic drawing program, and also create tools to build a library of graphical symbols. An online database to instantiate the symbols into the schematic is also a great tool.

    Perl is a great language for building this type of system. Your example shows a grammar, but you could also make a regular expression builder or an electronic design system.

    One would think that Visio might be good at this sort of thing, but it is lame in this respect.

    It should work perfectly the first time! - toma
Re: Diagram to Text and Vice Versa (DAG, RTN)
by dave0 (Friar) on Nov 09, 2004 at 18:12 UTC
    Check out Dia ( ). It's basically an opensource replacement for Visio. Dia data is saved as XML, so it should be possible to draw your diagram in Dia, then parse and modify it with standard Perl XML modules.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://406087]
Approved by Old_Gray_Bear
Front-paged by Courage
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-05-07 16:29 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (93 votes). Check out past polls.