Venn diagram generation software from RCC(8) specification or similar

后端 未结 3 518
暗喜
暗喜 2021-02-02 10:41

Please note: While the bounty is no longer available, I\'m still keen for anyone with an answer to this question to contribute; I\'m still watching it, and I\'m

相关标签:
3条回答
  • 2021-02-02 11:02

    Have you evaluated antlr, You could define an EBNF grammar for RCC8. Use antlr to generate an item list. This item list can be used as an input to software like VennMaster for drawing diagrams.

    Other options are Goolge Charts ,

    http://bioinfogp.cnb.csic.es/tools/venny/index.html

    0 讨论(0)
  • 2021-02-02 11:04

    Who need's a backend? Here's a working prototype using HTML/CSS/JS:

    http://jsfiddle.net/RuvE6/6/

    Just enter the RCC8 code syntax in the field and hit the button!

    HTML/CSS/JS RCC8 Diagram Builder

    Some current limitations:

    • Doesn't handle ambiguity
    • There's no error handling if syntax is off
    • Probably breaks in some valid cases (I haven't tested very much)
    • Didn't implement any inverse cases (yet?)

    Edit: How it works

    Basically, there are two families of relationships shown with these diagrams:

    • A contains B
    • A is adjacent to B.

    There are then sub-types or variations, like:

    • A contains B and B is tangential to A
    • A is adjacent to B and A overlaps with to B

    Both of the basic concepts are kind of baked into the HTML rendering world:

    • containment --> nested HTML elements: <div class="region"><div class="region"></div></div>
    • adjacency --> sibling HTML elements: <div class="region"></div><div class="region"></div>

    I handle the variations with special classes that (rather crudely) wiggle margins around to accomplish the desired layout:

    • containment, with tangent: <div class="region"><div class="region touches-parent"></div></div> (child has negative top margin to touch parent)
    • adjacency, with overlap: <div class="ven"><div class="region"></div><div class="region touches-parent"></div></div> (a wrapper is added to trigger CSS on the children - the second element has negative left margin to overlap the first.)

    There is some static markup commented out in the jsfiddle showing the structure I started with.

    To complete the functional loop, there is a bit of code that parses the RCC8 statement into A {XX} B parts, and attempts to render the necessary markup for each part. It checks as it goes to not duplicate regions. I also go through afterwards and set the heights of all sibling the same, which ensures they will overlap and/or abut properly.

    This code is really just a start, and it has it's conceits. It's basically a linear diagram, which means it doesn't, for instance, handle cases where there are complicated adjacencies, like this:

    A {EC} B, C {EC} B, D {EC} B

    These might be handled be smarted JS parsing and more complicated CSS, but probably quickly venture into the realm of more force-directed layouts (a smarter bubble chart, for instance).

    0 讨论(0)
  • 2021-02-02 11:06

    I don't know of any software that can generate such diagrams. However, If I had to tackle your problem I would probably explore the possibility of using Scalable Vector Graphics (SVG). I think you can translate your DSL for RCC into SVG XML, and then you can render it (maybe in a Web browser). You can easily find examples on the Web by searching for "svg venn diagram". A nice one is here: here's a diagram that I generate from that website

    enter image description here

    and here's the corresponding SVG code (also from the website):

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
    <svg 
        height="150" 
        width="200" 
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:svg="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink">    
    <title >WIBR Venn diagram</title>
        <ellipse 
            cx="141.795128105731" 
            cy="75" 
            id="circle2" 
            rx="58.2048718942687" 
            ry="58.2048718942687" 
            style="fill: gray; fill-opacity: 0.5; stroke: black; stroke-width: 1; stroke-opacity: 1" />
        <ellipse 
            cx="67.2091969126074" 
            cy="75" id="circle1" 
            rx="67.2091969126074" ry="67.2091969126074" 
            style="fill: darkgray; fill-opacity: 0.5; stroke: black; stroke-width: 1; stroke-opacity: 1"/>
    </svg>
    

    There's also an Apache toolkit for SVG called Batik, which should support display, generation or manipulation of SVGs.

    Another option is to use TikZ & PGF with LaTeX: there you have powerful macros that let you programmatically place shapes, and the rendering is done by LaTeX. Here's an example:

    \documentclass[a4paper,10pt]{article}
    
    \usepackage{tikz}
    \usetikzlibrary{shapes,calc}
    
    \begin{document}
    
    \pagestyle{empty}
    
    \begin{tikzpicture}
    
        \node (TPP) {X TPP Y};
    
        \node
            [ circle,
                draw,
                minimum width=2cm,
                label={[label distance=-0.7cm]145:X},
            ] (X) [right of=TPP,xshift=1cm] {};
    
        \node
            [ circle,
                draw,
                minimum width=1cm,
                anchor=south east,
            ] (Y) at (X.south east) {Y}; 
    
    \end{tikzpicture}
    
    \end{document}
    

    which produces the following (i.e. the RCC8 TPP relation):

    enter image description here

    You can see from the LaTeX code that you can draw the Y circle at south west of X (X.south west) saying that Y's anchor is also at south west (anchor=south west). You can find a more complex example here, and some additional discussion here.

    Although this is not yet a layout algorithm that draws RCC8 relation for you, I think you can define LaTeX macro that translate RCC8 relations into PGF/TikZ macros. The drawback is that you must then compile the LaTeX code.

    I hope this helps and good luck!

    0 讨论(0)
提交回复
热议问题