コード例 #1
0
class ImageConverter():

    def __init__(self):
        self.plant = PlantUML(url='http://www.plantuml.com/plantuml/img/')

    def produce_image_b(self):
        self.plant.processes_file("uml.txt")
コード例 #2
0
ファイル: puml.py プロジェクト: fretboardfreak/gridrealm
def main():
    """Compile the input files into UML images."""
    args = parse_cmd_line()
    dprint(args)
    outfile = '.'.join(args.input.name.split('.')[:-1] + [args.suffix])
    vprint('Parsing "%s" to "%s"' % (args.input.name, outfile))
    puml = PlantUML()
    return puml.processes_file(args.input.name, outfile=outfile)
コード例 #3
0
def create_pic(filename: str) -> None:
    server = PlantUML(url='http://www.plantuml.com/plantuml/img/',
                      basic_auth={},
                      form_auth={},
                      http_opts={},
                      request_opts={})

    # Send and compile your diagram files to/with the PlantUML server
    server.processes_file(abspath(f'./{filename}'))
コード例 #4
0
 def generate(path):
     server = PlantUML(url='http://www.plantuml.com/plantuml/img/',
                       basic_auth={},
                       form_auth={},
                       http_opts={},
                       request_opts={})
     try:
         if server.processes_file(abspath('./rawUml.txt'), path,
                                  abspath('./output/error/error.txt')):
             print('Done, View your diagram in ' + path)
     except PermissionError:
         print('Permission Error occurred')
     except Exception as e:
         print(e)
コード例 #5
0
    def generate(input_uml):
        plant_uml = PlantUML(url='http://www.plantuml.com/plantuml/img/')
        PlantUMLProcessor.dump_to_file(input_uml,
                                       PlantUMLProcessor.uml_dump_file)
        print("Successfully generated Plant UML notation and saved it in " +
              PlantUMLProcessor.uml_dump_file)

        PlantUMLProcessor.remove_file(PlantUMLProcessor.diagram_image_file)
        PlantUMLProcessor.remove_file(PlantUMLProcessor.error_file)

        plant_uml.processes_file(PlantUMLProcessor.uml_dump_file,
                                 PlantUMLProcessor.diagram_image_file,
                                 PlantUMLProcessor.error_file)

        if not os.path.isfile(PlantUMLProcessor.error_file):
            print(
                "Class Generation has finished executing, a diagram.png was created"
            )
        else:
            print("An error occurred, please check " +
                  PlantUMLProcessor.error_file +
                  " for any errors regarding the Plant UML diagram generation")
コード例 #6
0
ファイル: __init__.py プロジェクト: gsanou/ontogram
 def svg_file(filename):
     """Write the ontology diagram to file as SVG."""
     p = PlantUML(url='http://www.plantuml.com/plantuml/svg/')
     p.processes_file(filename, outfile=filename + '.svg')
コード例 #7
0
ファイル: __init__.py プロジェクト: gsanou/ontogram
 def url(self):
     """Get the URL of the ontology from www.plantuml.com."""
     p = PlantUML(url='http://www.plantuml.com/plantuml/img/')
     return p.get_url(self.plantuml)
コード例 #8
0
import json
import sys
from io import StringIO

# import tokenizers and wordnet
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import wordnet as wn

# import tagging stuff
from nltk import pos_tag
from nltk.help import upenn_tagset
from nltk import RegexpParser as NLTKRegexpParser

# import plantuml
from plantuml import PlantUML
planty = PlantUML(url='http://www.plantuml.com/plantuml/img/')


# merges adjacent text nodes into one text node in a nested object
# really annoying and please don't mess with it
def compact_arrays(tree):

    if isinstance(tree, dict):
        new_tree = {k: compact_arrays(v) for k, v in tree.items()}
        return new_tree

    if isinstance(tree, list):
        new_tree = []
        for item in tree:
            if len(new_tree) == 0:
                if isinstance(item, str):
コード例 #9
0
    async def uml_image(
        self,
        output: str = "svg",
        *,
        show_packages: Optional[List[str]] = None,
        hide_packages: Optional[List[str]] = None,
        with_inheritance: bool = True,
        with_base_classes: bool = False,
        with_subclasses: bool = False,
        dependency_edges: Optional[Set[str]] = None,
        with_predecessors: bool = False,
        with_successors: bool = False,
        with_properties: bool = True,
        link_classes: bool = False,
    ) -> bytes:
        allowed_edge_types: Set[str] = dependency_edges or set()
        assert output in ("svg", "png"), "Only svg and png is supported!"
        model = await self.load_model()
        graph = model.graph()
        show = [re.compile(s) for s in show_packages] if show_packages else None
        hide = [re.compile(s) for s in hide_packages] if hide_packages else None

        def not_hidden(key: str) -> bool:
            k: Kind = graph.nodes[key]["data"]
            return not (hide and exist(lambda r: r.fullmatch(k.fqn), hide))

        def node_visible(key: str) -> bool:
            k: Kind = graph.nodes[key]["data"]
            if hide and exist(lambda r: r.fullmatch(k.fqn), hide):
                return False
            if show is None:
                return True
            else:
                return exist(lambda r: r.fullmatch(k.fqn), show)

        def class_node(cpx: ComplexKind) -> str:
            props = "\n".join([f"**{p.name}**: {p.kind}" for p in cpx.properties]) if with_properties else ""
            link = f" [[#{cpx.fqn}]]" if link_classes else ""
            return f"class {cpx.fqn}{link} {{\n{props}\n}}"

        def descendants(cpx: ComplexKind) -> Set[str]:
            return {kind.fqn for kind in model.complex_kinds() if cpx.fqn in kind.kind_hierarchy()}

        def predecessors(cpx: ComplexKind) -> Set[str]:
            return {
                kind.fqn
                for kind in model.complex_kinds()
                for et in allowed_edge_types
                if cpx.fqn in kind.successor_kinds.get(et, [])
            }

        def successors(cpx: ComplexKind) -> Set[str]:
            return (
                {kind for et in allowed_edge_types for kind in cpx.successor_kinds.get(et, [])}
                if isinstance(cpx, ComplexKind)
                else set()
            )

        visible_kinds = [node["data"] for nid, node in graph.nodes(data=True) if node_visible(nid)]
        visible = {v.fqn for v in visible_kinds}

        def add_visible(fn: Callable[[ComplexKind], Set[str]]) -> None:
            selected: Set[str] = reduce(lambda res, cpl: res.union(fn(cpl)), visible_kinds, set())
            visible.update(n for n in selected if not_hidden(n))

        if with_base_classes:
            add_visible(lambda cpl: cpl.kind_hierarchy())
        if with_subclasses:
            add_visible(descendants)
        if with_predecessors:
            add_visible(predecessors)
        if with_successors:
            add_visible(successors)

        nodes = "\n".join([class_node(node["data"]) for nid, node in graph.nodes(data=True) if nid in visible])
        edges = ""
        for fr, to, data in graph.edges(data=True):
            if fr in visible and to in visible:
                if with_inheritance and data["type"] == "inheritance":
                    edges += f"{to} <|--- {fr}\n"
                elif data["type"] == "successor" and data["edge_type"] in allowed_edge_types:
                    edges += f"{fr} -[#1A83AF]-> {to}\n"

        puml = PlantUML(f"{self.plantuml_server}/{output}/")
        return await run_async(puml.processes, f"@startuml\n{PlantUmlAttrs}\n{nodes}\n{edges}\n@enduml")  # type: ignore
コード例 #10
0
 def _render_remote_uml_image(self, plantuml_code, img_format):
     return PlantUML("%s/%s/" % (self.config['server'], img_format)).processes(plantuml_code)
コード例 #11
0
 def __init__(self):
     self.plant = PlantUML(url='http://www.plantuml.com/plantuml/img/')
コード例 #12
0
    async def uml_image(
        self,
        show_packages: Optional[List[str]] = None,
        hide_packages: Optional[List[str]] = None,
        output: str = "svg",
        *,
        with_bases: bool = False,
        with_descendants: bool = False,
    ) -> bytes:
        assert output in ("svg", "png"), "Only svg and png is supported!"
        model = await self.load_model()
        graph = model.graph()
        show = [re.compile(s)
                for s in show_packages] if show_packages else None
        hide = [re.compile(s)
                for s in hide_packages] if hide_packages else None

        def node_visible(key: str) -> bool:
            k: Kind = graph.nodes[key]["data"]
            if hide and exist(lambda r: r.fullmatch(k.fqn), hide):
                return False
            if show is None:
                return True
            else:
                return exist(lambda r: r.fullmatch(k.fqn), show)

        def class_node(cpx: ComplexKind) -> str:
            props = "\n".join(
                [f"**{p.name}**: {p.kind}" for p in cpx.properties])
            return f"class {cpx.fqn} {{\n{props}\n}}"

        def class_inheritance(from_node: str, to_node: str) -> str:
            return f"{to_node} <|--- {from_node}"

        def descendants(fqn: str) -> Set[str]:
            return {
                kind.fqn
                for kind in model.complex_kinds()
                if fqn in kind.kind_hierarchy()
            }

        visible_kinds = [
            node["data"] for nid, node in graph.nodes(data=True)
            if node_visible(nid)
        ]
        visible = {v.fqn for v in visible_kinds}
        if with_bases:
            bases: Set[str] = reduce(
                lambda res, cpl: res.union(cpl.kind_hierarchy()),
                visible_kinds, set())
            visible.update(bases)
        if with_descendants:
            desc: Set[str] = reduce(
                lambda res, cpl: res.union(descendants(cpl.fqn)),
                visible_kinds, set())
            visible.update(desc)

        params = ("hide empty members\n"
                  "skinparam ArrowColor #ffaf37\n"
                  "skinparam ArrowThickness 2\n"
                  "skinparam BackgroundColor transparent\n"
                  "skinparam ClassAttributeFontColor #d9b8ff\n"
                  "skinparam ClassBackgroundColor #3d176e\n"
                  "skinparam ClassBorderColor #000d19\n"
                  "skinparam ClassFontColor #d9b8ff\n"
                  "skinparam ClassFontName Helvetica\n"
                  "skinparam ClassFontSize 17\n"
                  "skinparam Padding 5\n"
                  "skinparam RoundCorner 5\n"
                  "skinparam Shadowing false\n"
                  "skinparam stereotypeCBackgroundColor #e98df7\n"
                  "skinparam stereotypeIBackgroundColor #e98df7\n")

        nodes = "\n".join([
            class_node(node["data"]) for nid, node in graph.nodes(data=True)
            if nid in visible
        ])
        edges = "\n".join([
            class_inheritance(fr, to) for fr, to in graph.edges()
            if fr in visible and to in visible
        ])
        puml = PlantUML(f"{self.plantuml_server}/{output}/")
        return await run_async(
            puml.processes,
            f"@startuml\n{params}\n{nodes}\n{edges}\n@enduml")  # type: ignore