@@ -112,6 +112,8 @@ public abstract class ASTTerm
112112
113113 public abstract String literalForm ();
114114
115+ public abstract String tagFunction ();
116+
115117 public void addStereotype (String str )
116118 { String lit = literalForm ();
117119 Vector stereotypes =
@@ -1578,7 +1580,9 @@ public static Vector generateASTExamples(Vector javaASTs)
15781580
15791581 public static void entitiesFromASTs (Vector asts , String suff , Vector es )
15801582 { // For each tag t, create entity t+suff. Add subclass for
1581- // each different arity of t terms.
1583+ // each different arity of t terms.
1584+ // Nesting: (t (t1 x) (t2 y)) becomes
1585+ // t_t1$t_t2, etc.
15821586
15831587 Type treeType = new Type ("OclAny" , null );
15841588
@@ -1625,6 +1629,56 @@ public static void entitiesFromASTs(Vector asts, String suff, Vector es)
16251629 }
16261630 }
16271631
1632+ public static void deepEntitiesFromASTs (Vector asts , String suff , Vector es )
1633+ { // For each different term t, create entity t' + suff.
1634+ // Nesting: (t (t1 x) (t2 y)) entity has name
1635+ // t_t1$t_t2, etc.
1636+
1637+ Type treeType = new Type ("OclAny" , null );
1638+
1639+ for (int i = 0 ; i < asts .size (); i ++)
1640+ { ASTTerm t = (ASTTerm ) asts .get (i );
1641+ String tg = t .tagFunction () + suff ;
1642+ String tgsup = t .getTag () + suff ;
1643+ int n = t .arity ();
1644+ if (n > 0 )
1645+ { Entity sup = (Entity ) ModelElement .lookupByName (tgsup ,es );
1646+ if (sup == null )
1647+ { sup = new Entity (tgsup );
1648+
1649+ System .out .println ("Created entity: " + sup );
1650+
1651+ if (suff .equals ("" ))
1652+ { sup .addStereotype ("source" ); }
1653+ else
1654+ { sup .addStereotype ("target" ); }
1655+
1656+ sup .setAbstract (true );
1657+ Attribute astatt =
1658+ new Attribute ("ast" , treeType , ModelElement .INTERNAL );
1659+ sup .addAttribute (astatt );
1660+ es .add (sup );
1661+ }
1662+
1663+ Entity ee = (Entity ) ModelElement .lookupByName (tg ,es );
1664+ if (ee == null )
1665+ { ee = new Entity (tg );
1666+
1667+ System .out .println ("Created entity: " + tg );
1668+
1669+ if (suff .equals ("" ))
1670+ { ee .addStereotype ("source" ); }
1671+ else
1672+ { ee .addStereotype ("target" ); }
1673+
1674+ ee .setSuperclass (sup );
1675+ sup .addSubclass (ee );
1676+ es .add (ee );
1677+ }
1678+ }
1679+ }
1680+ }
1681+
16281682 public static Vector entityMatchingsFromASTs (Vector sasts ,
16291683 Vector tasts , Vector es )
16301684 { // For corresponding s, t create entity matching
@@ -1640,7 +1694,7 @@ public static Vector entityMatchingsFromASTs(Vector sasts,
16401694 int m = t .arity ();
16411695
16421696 if (n > 0 && m > 0 )
1643- { String sentname = s .getTag () + "_" + n ;
1697+ { String sentname = s .tagFunction (); // Assume it is deep
16441698 Entity sent =
16451699 (Entity ) ModelElement .lookupByName (sentname ,es );
16461700 String tentname = t .getTag () + "$T_" + m ;
@@ -1676,7 +1730,7 @@ public static void modelSpecificationFromASTs(Vector sasts,
16761730 int m = t .arity ();
16771731
16781732 if (n > 0 && m > 0 )
1679- { String sentname = s .getTag () + "_" + n ;
1733+ { String sentname = s .tagFunction () ;
16801734 String tentname = t .getTag () + "$T_" + m ;
16811735 String sinst = sentname .toLowerCase () + "_" + i ;
16821736 String tinst = tentname .toLowerCase () + "_" + i ;
@@ -1745,6 +1799,24 @@ public static void main(String[] args)
17451799 // System.out.println(t.isInteger());
17461800 // System.out.println(t.isBoolean());
17471801
1802+ ASTBasicTerm tt1 = new ASTBasicTerm ("t1" , "aa" );
1803+ ASTBasicTerm tt2 = new ASTBasicTerm ("t2" , "bb" );
1804+ ASTSymbolTerm tts = new ASTSymbolTerm ("&" );
1805+
1806+
1807+ Vector vect = new Vector ();
1808+ vect .add (tt1 );
1809+ vect .add (tts );
1810+ vect .add (tt2 );
1811+
1812+ ASTCompositeTerm ttc =
1813+ new ASTCompositeTerm ("ct" , vect );
1814+
1815+ System .out .println (ttc .tagFunction ());
1816+ }
1817+ }
1818+
1819+ /*
17481820 Vector consts =
17491821 randomBasicASTTermsForTag("Const", 1, 50);
17501822 Vector ops = new Vector();
@@ -1944,8 +2016,9 @@ public static void main(String[] args)
19442016 catch (Exception _fex)
19452017 { System.err.println("! No file: output/asts.txt"); }
19462018
1947- }
1948- }
2019+ } */
2020+
2021+
19492022
19502023/* tree2tree dataset format: */
19512024
0 commit comments