1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-10-21 16:49:02 +02:00

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

Mostly about the changes on types hierarchy
This commit is contained in:
Yann 2015-09-24 14:35:37 +02:00
commit f2027275e3
3 changed files with 23 additions and 13 deletions

View file

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

View file

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

View file

@ -19,7 +19,7 @@ class Command(BaseCommand):
make_option('--max-classes',
action='store',
dest='nclass',
default = 5,
default = 3,
help='Maximum number of classes per classtype',
type="int",
metavar="INT",
@ -35,11 +35,19 @@ class Command(BaseCommand):
make_option('--no-types',
action='store',
dest='notype',
default = 5,
default = 10,
help='Chances for a class to have no types',
type="int",
metavar="INT",
),
make_option('--max-types',
action='store',
dest='ntype',
default = 8,
help='Maximum number of types in a class',
type="int",
metavar="INT",
),
make_option('--sel-opt-field',
action='store',
dest='seltype',
@ -51,7 +59,7 @@ class Command(BaseCommand):
make_option('--superiors',
action='store',
dest='ntypesuperiors',
default = 3,
default = 2,
help='Chances for a type to link with other types (superiors)',
type="int",
metavar="INT",
@ -112,7 +120,7 @@ class Command(BaseCommand):
help = 'Randomly generate an EditorialModel'
def handle(self, *args, **options):
anames = ['classtype','nclass', 'nofg', 'notype', 'seltype', 'ntypesuperiors', 'nofields', 'nfields', 'optfield']
anames = ['classtype','nclass', 'nofg', 'notype', 'ntype', 'seltype', 'ntypesuperiors', 'nofields', 'nfields', 'optfield']
chances = dict()
for n in anames:
chances[n] = options[n]