Commit aca5d86c authored by Lucas Bourneuf's avatar Lucas Bourneuf

einstein riddle data + new config showing its use

parent 165ceade
......@@ -5,6 +5,10 @@ VERBOSITY=
run-test:
python -m biseau scripts/example.lp scripts/black_theme.json -o out/out.png $(VERBOSITY)
run-fca-test:
python -m biseau -c ./configs/concept-lattice.json -o out/concept-lattice.png $(VERBOSITY)
run-einstein-test:
python -m biseau -c ./configs/einstein-riddle.json -o out/einstein-riddle.png $(VERBOSITY)
run-config-test:
python -m biseau -c ./configs/simple.json $(VERBOSITY)
python -m biseau -c ./configs/concept-lattice.json -o out/concept-lattice.png $(VERBOSITY)
......
......@@ -68,9 +68,10 @@ def build_pipeline_from_json(jsondata:dict, verbosity:int=0) -> [Script]:
for item in jsondata:
yield from build_pipeline_from_json(item)
for name, options in jsondata.items():
scripts = module_loader.build_scripts_from_file(name)
scripts = module_loader.build_scripts_from_file(name, options)
for script in scripts:
script.options_values.update(options)
if isinstance(options, dict):
script.options_values.update(options)
yield script
build_pipeline.from_configfile = build_pipeline_from_configfile
......
......@@ -58,7 +58,7 @@ def gen_scripts_in_dir(dirname:str, extensions:[str]=('py', 'lp', 'json'),
)
def build_scripts_from_file(fname:str) -> [Script]:
def build_scripts_from_file(fname:str, options:dict={}) -> [Script]:
name, ext = os.path.splitext(fname)
if ext == '.json':
yield from build_scripts_from_json_file(fname)
......@@ -74,6 +74,13 @@ def build_scripts_from_file(fname:str) -> [Script]:
print('SCRIPT ERROR:', str(err))
elif ext == '.lp':
yield build_asp_script_from_name(fname)
elif fname.upper().startswith('ASP'):
if isinstance(options, (list, tuple, str)):
yield from build_scripts_from_asp_code(options)
else:
print(f"Unknow type for ASP code: {type(options)}")
else:
print(f"WARNING file '{fname}' was not recognized")
def build_scripts_from_dir(base_dir:str='scripts') -> iter:
......@@ -179,6 +186,22 @@ def build_scripts_from_json_file(fname:str) -> [Script]:
"".format(fname, type(data)))
def build_scripts_from_asp_code(data:str or list) -> [Script]:
"""Yield one Script instance initialized with given source code"""
if isinstance(data, (tuple, list)): # multiple scripts
for source in data:
yield from build_scripts_from_asp_code(source)
elif isinstance(data, str): # only one
yield build_script_from_json({
'name': 'inline ASP code',
'ASP': data,
'description': 'inline ASP code',
'inputs': [],
'outputs': [], # TODO: search for #show's in the file
})
else:
raise ScriptError(f"Given ASP source of type {type(data)} can't be handled.")
def build_script_from_json(module_def:dict) -> Script:
"""From given JSON build a Script instance"""
# let's use a class as placeholder for a module.
......
{
"scripts/context.py": {
"fname": "contexts/einstein-rev-riddle.lp"
},
"ASP1": "ans(A):- rule(A,_).\nr(R):- rule(_,R).\nrel(R,A):- ans(A) ; r(R) ; not rule(A,R).",
"scripts/build_concepts.py": {
"type": "formal",
"careful_parsing": true,
"supremum_and_infimum": true,
"remove_symmetry": false
},
"ASP2": "label(X,\"\") :- concept(X). shape(X,circle):- concept(X).",
"scripts/galois-lattice.json": {},
"scripts/show_galois_lattice.py": {
"dpi": 300,
"use_aoc_as_label": true,
"concept_uid": false
},
"scripts/black_theme.json": {}
}
rel(ans1,1).
rel(ans1,4).
rel(ans1,5).
rel(ans1,7).
rel(ans1,14).
rel(ans2,1).
rel(ans2,15).
rel(ans3,4).
rel(ans3,5).
rel(ans3,7).
rel(ans3,8).
rel(ans4,4).
rel(ans4,9).
rel(ans5,5).
rel(ans5,9).
rel(ans6,5).
rel(ans6,15).
rel(ans7,8).
rel(ans7,15).
rel(ans8,14).
rel(ans8,15).
/home/lbourneu/programs/biseau/contexts/einstein-riddle.lp
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment