metacoma / mindwm

22 stars 1 forks source link

Add tooling to make it easier to write a frontend. Or at least define a schema #29

Open AriSweedler opened 1 year ago

AriSweedler commented 1 year ago

From #23, I see that you write an awk script to convert shell output to groovy code (the groovy code is what codes for freeplane graphs)

As is, one can write a compiler in any language, it doesn't have to be awk. However, the only accepted target data format is groovy code. It would make more sense to me if I could target a schema. Like let's say we choose JSON to implement theschema. So then instead of shell output --awk--> groovy it would go shell output --anything(targets schema)--> JSON data structure --compiler--> groovy.

What is the schema? I would love to write some frontends for some of my favorite commands. I would target the schema you told me about. I could also try and take the schema and write a backend that will generate the groovy from the schema.

metacoma commented 1 year ago

hey @AriSweedler !

Thank you for your interest. Your question is good and important, and I have personally answered it as follows.

I would like to bring your attention to the freeplane_grpc_plugin, which I wrote a couple of weeks ago freeplane_plugin_grpc

I hope the following diagram will provide clarity.

image

This plugin enables you to perform Freeplane functions via the gRPC interface, which is a network remote procedure call.

My next objective is to develop "parsers" for the following .yaml files (approximate version).

io-context:
   stdin: ^ifconfig  # regex pattern 
   parser: # You can write parsers in any language that supports gRPC.
      #!/usr/bin/env python

      # io-context['stdin']  key holds the standard input, which is the data entered by the user.
      # io-context['stdout']  stores the combination of the standard output (stdout) and error (stderr) streams.

      ifconfig_interfaces = ifconfig_python_parser(io-context['stdout'])

      # create root node 
      ifconfig = fp.CreateChild(freeplane_pb2.CreateChildRequest(name="ifconfig", parent_node_id = ""))

      for interface in ifconfig_interfaces:
         interface_node = fp.CreateChild(freeplane_pb2.CreateChildRequest(name=interface['name'], parent_node_id = ifconfig.node_id))
         for ip_address in interface:
            fp.NodeAttributeAdd(freeplane_pb2.NodeAttributeAddRequest(node_id=interface_node.node_id, attribute_name="Ip address", attribute_value=ip_address))  

The same parser, with ruby implementation

io-context:
   stdin: ^ifconfig  # regex pattern 
   parser: # You can write parsers in any language that supports gRPC.
     #!/usr/bin/env ruby

     # io-context['stdin']  variable holds the standard input, which is the data entered by the user.
     # io-context['stdout']  stores the combination of the standard output (stdout) and error (stderr) streams.
     ifconfig_interfaces = ifconfig_ruby_parser(io-context['stdout'])

     # create root node
     ifconfig = stub.create_child(Freeplane::CreateChildRequest.new(name: "ifconfig", parent_node_id: ""))

     for interface in ifconfig_interfaces do
        interface_node = stub.create_child(Freeplane::CreateChildRequest.new(name: interface["name"], parent_node_id: ifconfig.node_id))
        for ip_address in interface do
          stub.node_attribute_add(Freeplane::NodeAttributeAddRequest.new(node_id: interface_node["node_id"], attribute_name: "IP", attribute_value: ip_address))
        end
     end

So then instead of shell output --awk--> groovy it would go shell output --anything(targets schema)--> JSON data structure --compiler--> groovy What is the schema? I would love to write some frontends for some of my favorite commands. I would target the schema you told me about. I could also try and take the schema and write a backend that will generate the groovy from the schema.

Yes, that's another good point. I have a plan to implement gRPC calls to import data in various formats such as XML/JSON/YAML/TOML, etc, like:

freeplane.importJson(json_data)
freeplane.importYaml(yaml_data)
freeplane.importXML(xml_data)

https://github.com/metacoma/freeplane_plugin_grpc/issues/2

I hope I was able to answer your question. Please feel free to ask anything or offer your own ideas regarding gRPC or JSON schema formats for importing structured data into Freeplane.