Commit f6de6dcc authored by Lucas Bourneuf's avatar Lucas Bourneuf

Merge branch 'master' of

parents 97e4cd4d ebd1c0cb
__version__ = '0.0.17.dev0'
__version__ = '0.0.18.dev0'
from .script import Script
from .core import run, single_image_from_filenames, multiple_images_from_filenames, gif_from_filenames, compile_to_single_image, compile_to_images, compile_context_to_dots, compile_context_to_dot, compile_contexts_to_dots, compile_contexts_to_dot
......@@ -72,7 +72,7 @@ def visual_config_from_atoms(atoms:dict, base_atoms:dict,
def get_uid_from_atom(atom:str or tuple):
if isinstance(atom, str):
return atom
return atom.strip('"')
elif isinstance(atom, int):
return str(atom)
elif isinstance(atom, tuple):
......@@ -140,11 +140,11 @@ def visual_config_from_atoms(atoms:dict, base_atoms:dict,
if len(colored) == 2: # node
node, color = colored
node = get_uid_from_atom(node)
elif len(colored) == 3: # edge
src, trg, color = colored
src, trg = map(get_uid_from_atom, (src, trg))
properties[src, trg]['color'].add(color) # fillcolor do not exists for edges
properties[src, trg]['color'].add(color.strip('"')) # fillcolor do not exists for edges
for shaped in get_atoms_of_predicate('shape'):
if len(shaped) == 2: # node
node, shape = shaped
......@@ -13,10 +13,8 @@ import itertools
from functools import partial
from collections import defaultdict
import clyngor
from biseau import utils
from biseau import run_on_types
from biseau import script as script_functions
from biseau.script import Script, Module
......@@ -136,8 +136,8 @@ def solve_context(context:str, *, nb_model:int=0) -> clyngor.Answers:
return clyngor.solve(inline=context, nb_model=nb_model, options='--project').by_predicate.careful_parsing.int_not_parsed
def call_script(script, context:str, verbosity:int=0):
"""Uniformized call to a Script object"""
def call_script(script, context:str, verbosity:int=0) -> str:
"""Uniformized call to a Script object ; return the new context"""
if script.input_mode is str:
input_data = context
else: # need a solving
......@@ -13,7 +13,6 @@ HANDLED_COLORS = {'red', 'green', 'blue'}
def color_from_colors(colors:set) -> str:
"""Return one color that represents the given ones"""
if all(color in HANDLED_COLORS for color in colors):
if len(colors) == 1: return next(iter(colors))
if len(colors) == 2:
if 'red' in colors:
# User Documentation
......@@ -150,7 +149,7 @@ The ASP atoms that have an effect on dot file generation are:
- `node(N)`: graph contains node N.
- `link(A,B)`: two nodes, A and B, are linked in the graph (A is source, B target).
- `color(N,C)`: the node N, if exists, is colored in color C (see [colors](
- `color(N,C)`: the node N, if exists, is colored in color C (see [colors](
- `color(A,B,C)`: the edge A->B, if exists, is colored in color C.
- `shape(N,S)`: the node N, if exists, will be shaped as indicated (rectangle, ellipse, circle,…).
- `annot(M)`: Apply a multiplier M to node distance for annotations, depending of the number of lines of annotations. Value of 0.85 was successful for default dot font size.
python -m biseau hitman.lp -o hitman.png
xdg-open hitman.png
% Drawing of the graph hitman.png,
% where the different game packaging are represented as nodes
% and buyable items are represented as edges.
% The green path is the advised one for a newcomer wanting the full content.
% obj_property(graph,rankdir,"LR").
label((u_1;u_2),""). label(u_1,u_2,"advised path"). % label(u_2,"advised path";u_1,"").
color(X,Y,blue) :- advised(X,Y).
use(none,hitman2_gold,"HITMAN 2 Gold edition").
use(none,hitman2_silver,"HITMAN 2 Silver edition").
use(none,hitman2_standard,"HITMAN 2 Standard edition").
use(hitman1,hitman2_gold_legacy,"HITMAN 2 Gold edition").
use(hitman1,hitman2_silver_legacy,"HITMAN 2 Silver edition").
use(hitman1,hitman2_standard_legacy,"HITMAN 2 Standard edition").
use(hitman2_gold,hitman2_gold_gotylegacy,"GOTY Legacy Pack").
use(hitman2_silver,hitman2_silver_gotylegacy,"GOTY Legacy Pack").
use(hitman2_standard,hitman2_standard_gotylegacy,"GOTY Legacy Pack").
use(hitman2_gold_legacy,hitman2_gold_gotylegacy,"GOTY Legacy Pack Upgrade").
use(hitman2_silver_legacy,hitman2_silver_gotylegacy,"GOTY Legacy Pack Upgrade").
use(hitman2_standard_legacy,hitman2_standard_gotylegacy,"GOTY Legacy Pack Upgrade").
use(hitman2_silver,hitman2_gold,"Silver to Gold").
use(hitman2_silver_gotylegacy,hitman2_gold_gotylegacy,"Silver to Gold").
link(X,Y) :- use(X,Y,_).
label(X,Y,L) :- use(X,Y,L).
% Name of packages
label(none,"No Hitman content possessed").
label(hitman1,"HITMAN 2016 (all episodes)").
label(hitman2_standard,"HITMAN 2 Standard Edition").
label(hitman2_silver,"HITMAN 2 Silver Edition").
label(hitman2_gold,"HITMAN 2 Gold Edition").
label(hitman2_standard_legacy,"HITMAN 2 Standard Edition\n+ HITMAN 1 (main locations)").
label(hitman2_silver_legacy,"HITMAN 2 Silver Edition\n+ HITMAN 1 (main locations)").
label(hitman2_gold_legacy,"HITMAN 2 Gold Edition\n+ HITMAN 1 (main locations)").
label(hitman2_standard_gotylegacy,"HITMAN 2 Standard Edition\n+ Full content HITMAN 1").
label(hitman2_silver_gotylegacy,"HITMAN 2 Silver Edition\n+ Full content HITMAN 1").
label(hitman2_gold_gotylegacy,"Full content HITMAN (1 & 2 & all extensions)").
......@@ -12,10 +12,24 @@ def test_basic_visual_config():
assert == {'a': {'fillcolor': 'red'}}
def test_basic_visual_config():
def test_basic_visual_config_2():
config = asp_to_dot.visual_config_from_atoms({}, {
'link': {('a', 'b'), ('c', 'd')},
'node': {('e',)},
}, ' ')
assert set(config.arcs) == {('a', 'b'), ('c', 'd')}
assert set(config.nodes) == {'e'}
def test_complex_labelling():
config = asp_to_dot.visual_config_from_atoms({}, {
'link': {('a', 'b'), ('c', 'd')},
'label': {('a', '"toto"'), ('a', '"tutu"')},
'color': {('a','green'), ('b','green:red;0.25:blue')},
}, ' ')
assert set(config.arcs) == {('a', 'b'), ('c', 'd')}
# print(dir(config))
assert set(['a']['label'].split()) == {'toto', 'tutu'}
assert['a']['fillcolor'] == 'green'
assert['b']['fillcolor'] == 'green:red;0.25:blue'
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment