Browse Source

Addapt graphviz backend and random EM generator to changes on master branch

Mostly about the changes on types hierarchy
Yann Weber 9 years ago
parent
commit
f2027275e3
3 changed files with 23 additions and 13 deletions
  1. 3
    2
      EditorialModel/backend/graphviz.py
  2. 8
    7
      EditorialModel/model.py
  3. 12
    4
      Lodel/management/commands/emgen.py

+ 3
- 2
EditorialModel/backend/graphviz.py View File

@@ -61,8 +61,9 @@ class EmBackendGraphviz(object):
61 61
                 self.edges += cid+' -> '+self._component_id(c.em_class)+' [ style="dotted" ]\n'
62 62
                 for fg in c.fieldgroups():
63 63
                     self.edges += cid+' -> '+self._component_id(fg)+' [ style="dashed" ]\n'
64
-                for nat in c.superiors():
65
-                    self.edges += cid+' -> '+self._component_id(c.superiors()[nat])+' [ label="%s" color="green" ]'%nat
64
+                for nat, sups in c.superiors().items():
65
+                    for sup in sups:
66
+                        self.edges += cid+' -> '+self._component_id(sup)+' [ label="%s" color="green" ]'%nat
66 67
             #dotfp.write("}\n")
67 68
 
68 69
             dotfp.write(self.edges)

+ 8
- 7
EditorialModel/model.py View File

@@ -294,10 +294,10 @@ class Model(object):
294 294
             'nclass': 5, #max number of classes per classtype
295 295
             'nofg': 10, #no fieldgroup in a class
296 296
             'nfg': 5, #max number of fieldgroups per classes
297
-            'notype': 5, # no types in a class
298
-            'ntype': 3,  # max number of types in a class
297
+            'notype': 10, # no types in a class
298
+            'ntype': 8,  # max number of types in a class
299 299
             'seltype': 2, #chances to select an optional field
300
-            'ntypesuperiors': 3, #chances to link with a superior
300
+            'ntypesuperiors': 2, #chances to link with a superior
301 301
             'nofields': 10, # no fields in a fieldgroup
302 302
             'nfields' : 8, #max number of fields per fieldgroups
303 303
             'rfields': 5,#max number of attributes relation fields
@@ -338,9 +338,10 @@ class Model(object):
338 338
         for emtype in em.components(EmType):
339 339
             possible = emtype.possible_superiors()
340 340
             for nat in possible:
341
-                while random.randint(0, chances['ntypesuperiors']) == 0 and len(possible[nat]) > 0:
342
-                    i = random.randint(0,len(possible[nat])-1)
343
-                    emtype.add_superior(possible[nat][i], nat)
341
+                if len(possible[nat]) > 0 and random.randint(0, chances['ntypesuperiors']) == 0:
342
+                    random.shuffle(possible[nat])
343
+                    for i in range(random.randint(1, len(possible[nat]))):
344
+                        emtype.add_superior(possible[nat][i], nat)
344 345
 
345 346
 
346 347
         #fields creation
@@ -392,7 +393,7 @@ class Model(object):
392 393
         if '_words' not in globals() or globals()['_words_fname'] != words_src:
393 394
             globals()['_words_fname'] = words_src
394 395
             with open(words_src, 'r') as fpw:
395
-                globals()['_words'] = [ l for l in fpw ]
396
+                globals()['_words'] = [ l.strip() for l in fpw ]
396 397
         words = globals()['_words']
397 398
         return words[random.randint(0,len(words)-1)]
398 399
         

+ 12
- 4
Lodel/management/commands/emgen.py View File

@@ -19,7 +19,7 @@ class Command(BaseCommand):
19 19
         make_option('--max-classes',
20 20
             action='store',
21 21
             dest='nclass',
22
-            default = 5,
22
+            default = 3,
23 23
             help='Maximum number of classes per classtype',
24 24
             type="int",
25 25
             metavar="INT",
@@ -35,11 +35,19 @@ class Command(BaseCommand):
35 35
         make_option('--no-types',
36 36
             action='store',
37 37
             dest='notype',
38
-            default = 5,
38
+            default = 10,
39 39
             help='Chances for a class to have no types',
40 40
             type="int",
41 41
             metavar="INT",
42 42
         ),
43
+        make_option('--max-types',
44
+            action='store',
45
+            dest='ntype',
46
+            default = 8,
47
+            help='Maximum number of types in a class',
48
+            type="int",
49
+            metavar="INT",
50
+        ),
43 51
         make_option('--sel-opt-field',
44 52
             action='store',
45 53
             dest='seltype',
@@ -51,7 +59,7 @@ class Command(BaseCommand):
51 59
         make_option('--superiors',
52 60
             action='store',
53 61
             dest='ntypesuperiors',
54
-            default = 3,
62
+            default = 2,
55 63
             help='Chances for a type to link with other types (superiors)',
56 64
             type="int",
57 65
             metavar="INT",
@@ -112,7 +120,7 @@ class Command(BaseCommand):
112 120
     help = 'Randomly generate an EditorialModel'
113 121
 
114 122
     def handle(self, *args, **options):
115
-        anames = ['classtype','nclass', 'nofg', 'notype', 'seltype', 'ntypesuperiors', 'nofields', 'nfields', 'optfield']
123
+        anames = ['classtype','nclass', 'nofg', 'notype', 'ntype', 'seltype', 'ntypesuperiors', 'nofields', 'nfields', 'optfield']
116 124
         chances = dict()
117 125
         for n in anames:
118 126
             chances[n] = options[n]

Loading…
Cancel
Save