[kepler-dev] Re: kepler/src/org/geon MomlToGraph.java

Efrat Jaeger efrat at sdsc.edu
Tue May 4 23:42:11 PDT 2004


Hi Christopher,

Thanks for the insightful information. I was translating the moml file into
a set of axioms to enable graph processing, e.g. using prolog.

I'm also working on the other direction, translating a simple graph into a
sub-moml (no location info, etc..). I'm currently following the
drag-and-drop events methods to generate the moml string. Please let me know
if you think there is an simpler solution.

Thanks,

Efrat

----- Original Message ----- 
From: "Christopher Hylands Brooks" <cxh at eecs.berkeley.edu>
To: "Efrat Jaeger" <jaeger at ecoinformatics.org>
Cc: <kepler-dev at ecoinformatics.org>
Sent: Tuesday, May 04, 2004 5:17 PM
Subject: Re: kepler/src/org/geon MomlToGraph.java


> BTW - There is a NamedObj.description() method that might do what you
> want here.
>
> ptolemy/actor/test/CompositeActor.tcl has a test for it:
>
>
> ######################################################################
> ####
> #
> test CompositeActor-7.1 {Test clone and description} {
>     # NOTE: Uses the setup above
>     set e4 [java::cast ptolemy.actor.CompositeActor [$e3 clone $w]]
>     $e4 description
> } {ptolemy.actor.CompositeActor {.E3} attributes {
>     {ptolemy.kernel.util.SingletonConfigurableAttribute
{.E3._iconDescription} attributes {
>     }}
> } ports {
>     {ptolemy.actor.IOPort {.E3.P1} attributes {
>     } links {
>     } insidelinks {
>     } configuration {{width 0}} receivers {
>     } remotereceivers {
>     }}
>     {ptolemy.actor.IOPort {.E3.P2} attributes {
>     } links {
>     } insidelinks {
>     } configuration {input output {width 0}} receivers {
>     } remotereceivers {
>     }}
>     {ptolemy.actor.IOPort {.E3.P3} attributes {
>     } links {
>     } insidelinks {
>     } configuration {output {width 0}} receivers {
>     } remotereceivers {
>     }}
>     {ptolemy.actor.IOPort {.E3.P4} attributes {
>     } links {
>     } insidelinks {
>     } configuration {input {width 0}} receivers {
>     } remotereceivers {
>     }}
>     {ptolemy.actor.IOPort {.E3.P5} attributes {
>     } links {
>     } insidelinks {
>     } configuration {{width 0}} receivers {
>     } remotereceivers {
>     }}
> } classes {
> } entities {
>     {ptolemy.actor.CompositeActor {.E3.E5} attributes {
>         {ptolemy.kernel.util.SingletonConfigurableAttribute
{.E3.E5._iconDescription} attributes {
>         }}
>         {ptolemy.actor.Director {.E3.E5.WORMDIR} attributes {
>             {ptolemy.kernel.util.SingletonConfigurableAttribute
{.E3.E5.WORMDIR._iconDescription} attributes {
>             }}
>         }}
>     } ports {
>     } classes {
>     } entities {
>     } relations {
>     }}
> } relations {
> }}
>
>
> Subclasses define _description methods that get called appropriately
> by description().
>
> It would be great if we had an easier way to provide a visitor pattern
> so that a developer could provide their own syntax, but we don't.
>
> -Christopher
>
>
> ------- Forwarded Message
>
>
> From: jaeger at ecoinformatics.org (Efrat Jaeger)
> To: kepler-cvs at ecoinformatics.org
> Subject: [kepler-cvs] kepler/src/org/geon MomlToGraph.java
> Date: Tue, 4 May 2004 16:51:58 -0700 (PDT)
>
> jaeger      04/05/04 16:51:58
>
>   Added:       src/org/geon MomlToGraph.java
>   Log:
>   Translating a moml file into a simple graph.
>
>   Revision  Changes    Path
>   1.1                  kepler/src/org/geon/MomlToGraph.java
>
>   Index: MomlToGraph.java
>   ===================================================================
>   package org.geon;
>
>   import ptolemy.actor.IOPort;
>   import ptolemy.actor.TypedCompositeActor;
>   import ptolemy.kernel.ComponentEntity;
>   import ptolemy.kernel.ComponentRelation;
>   import ptolemy.kernel.Port;
>   import ptolemy.kernel.util.NamedObj;
>   import ptolemy.moml.MoMLParser;
>
>   import java.io.BufferedWriter;
>   import java.io.File;
>   import java.io.FileWriter;
>   import java.io.IOException;
>   import java.net.URL;
>   import java.util.Enumeration;
>   import java.util.Iterator;
>   import java.util.LinkedList;
>   import java.util.List;
>   import java.util.StringTokenizer;
>   import java.util.Vector;
>
>   import javax.xml.parsers.DocumentBuilder;
>   import javax.xml.parsers.DocumentBuilderFactory;
>
>   import org.w3c.dom.Document;
>   import org.w3c.dom.Element;
>   import org.w3c.dom.Node;
>   import org.w3c.dom.NodeList;
>
>
>   public class MomlToGraph {
>
>           public MomlToGraph() {
>
>           }
>
>           public static void main(String args[]) throws Exception {
>           //TODO: add a file name to args.
>
>           String _momlFileStr =
>           "C:/Projects/kepler/workflows/test/SRBDemo.xml";
>           int ind = _momlFileStr.lastIndexOf("/");
>           String base = "", fileName = "";
>           if (ind > -1) {
>           base =  _momlFileStr.substring(0,ind);
>           fileName = _momlFileStr.substring(ind+1);
>           }
>           ind = fileName.indexOf(".");
>           String outputName = "";
>           if (ind > -1) {
>           outputName = fileName.substring(0,ind) + ".pl";
>           } else {
>           throw new Exception("file name exception");
>           }
>
>               try {
>               File outputFile = new File(base+"/"+outputName);
>                   BufferedWriter out = new BufferedWriter(new
FileWriter(output
>     File.getAbsolutePath(), false));
>                   System.out.println(outputFile.getAbsolutePath());
>               File _momlFile = new File(_momlFileStr);
>               URL _momlUrl = _momlFile.toURL();
>
>               MoMLParser parser = new MoMLParser();
>               parser.reset();
>               NamedObj toplevel = null;
>               toplevel = parser.parse(_momlUrl, _momlUrl);
>               String workspace = toplevel.getFullName();
>               int workspaceLen = workspace.length()+1;
>               TypedCompositeActor TCA = (TypedCompositeActor)toplevel;
>               Enumeration ents = TCA.getEntities();
>               String axiom = "";
>               while (ents.hasMoreElements()) {
>               Object obj = ents.nextElement();
>               ComponentEntity CA = (ComponentEntity) obj;
>               System.out.println(obj.getClass().getName());
>               //ComponentEntity CA = (ComponentEntity) ents.nextEleme
>     nt();
>               System.out.println(CA.getClass());
>               System.out.println(CA.getName());
>               axiom = "Actor(" + CA.getName() + ",";
>               axiom += obj.getClass().getName() + ").";
>               out.write(axiom);
>               out.write("\r\n");
>               }
>               Enumeration rels = TCA.getRelations();
>               while (rels.hasMoreElements()) {
>               //List inputs = new LinkedList();
>               //List outputs = new LinkedList();
>               ComponentRelation CR = (ComponentRelation) rels.nextEle
>     ment();
>               System.out.println(CR.getName());
>               Enumeration ports = CR.linkedPorts();
>               while (ports.hasMoreElements()) {
>               IOPort p = (IOPort)ports.nextElement();
>               System.out.println(p.getName());
>
>               // connect all input ports to output ports.
>               if (p.isInput()) {
>               Iterator connected = p.connectedPortLis
>     t().iterator();
>               while (connected.hasNext()) {
>               // relations between ports.
>               IOPort outPort = (IOPort) conne
>     cted.next();
>               String inP = p.getFullName().su
>     bstring(workspaceLen);
>               String outP = outPort.getFullNa
>     me().substring(workspaceLen);
>                   axiom = "PortRelation(" + inP +
>      "," + outP + ").";
>                   out.write(axiom);
>                   out.write("\r\n");
>                   //relations between actors.
>                   int dotInd = inP.lastIndexOf(".
>     ");
>                   if (dotInd > -1) {
>                   axiom = "Relation(" + i
>     nP.substring(0,dotInd) + ",";
>                   } else {
>                   axiom = "Relation(" + i
>     nP + ",";
>                   }
>                   dotInd = outP.lastIndexOf(".");
>                   if (dotInd > -1) {
>                   axiom += outP.substring
>     (0,dotInd) + ").";
>                   } else {
>                   axiom += outP + ").";
>                   }
>                   out.write(axiom);
>                   out.write("\r\n");
>                   //TODO: TAKE CARE OF COMPOSITE
>     ENTITIES.
>               }
>               }
>               }
>               //Object _rel = rels.nextElement();
>               //System.out.println(_rel.getClass().getName());
>     //          System.out.println(CA.getClass());
>     //          System.out.println(CA.getName());
>               }
>               out.close();
>               parser.reset();
>               toplevel = null;
>               TCA = null;
>                System.out.println("get toplevel here!");
>               } catch (IOException io) {
>               throw io;
>               }
>
>           }
>   }
>
>
>
>
> _______________________________________________
> kepler-cvs mailing list
> kepler-cvs at ecoinformatics.org
> http://www.ecoinformatics.org/mailman/listinfo/kepler-cvs
>
> ------- End of Forwarded Message
>




More information about the Kepler-dev mailing list