-
Notifications
You must be signed in to change notification settings - Fork 0
aspreify - reify answer set programs, produces facts or RDF
License
vluukkal/aspreify
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
aspreify - reify answer set programs The purpose of this program is to parse textual answer set programs (ASP, Prolog like syntax) as accepted by lparse (http://www.tcs.hut.fi/Software/smodels/) and produce a description of the input program as ASP facts, effectively reifying the input program allowing, among other things, ASP programs to be interpreted or modified by other ASP programs. The reified format can be converted back to plain rules. Decomposing the the rules to facts enables the evaluator to reason over and maintain the provenance of the source information as well as the rules themselves, which is important in distributed reasoning. An evaluator in ASP, a metaevaluator, allows specifying the semantics of the ASP evaluation within the same ASP framework. An ASP metaevaluator for reified variable free ASP programs is provided, the variabled case is under construction, but emerging, starting with a metagrounder supporting variables. For more elaboration: @inproceedings{DBLP:conf/rr/JanhunenL12, author = {Tomi Janhunen and Vesa Luukkala}, title = {Meta Programming with Answer Sets for Smart Spaces}, booktitle = {RR}, year = {2012}, pages = {106-121}, ee = {http://dx.doi.org/10.1007/978-3-642-33203-6_9} } Vesa Luukkala (vesa.luukkala@gmail.com), 29.11.2012 1. Building Requires Haskell platform (http://www.haskell.org/platform/), tested on 2012.2.0.0. To produce an executable: > ghc -o aspreify main.hs rdfrender.hs txtrender.hs factrender.hs aspparse.hs dereify.hs Obtain the sources initially: > git clone git://www.github.com/vluukkal/aspreify Update later on after initially fetching them: > git remote update To run whole metagrounding chain: > ./ground.sh tests/ground_input/uncle3.lp produces uncle3.lp.reified.res Some simple examples highlighting particular features of aspreify: > ./aspreify tests/hamiltonian_cycle.lp produces tests/hamiltonian_cycle.lp.reified > ./aspreify -t tests/hamiltonian_cycle.lp The result has the same unreified rules as the input, used for testing. Produced to tests/hamiltonian_cycle.lp.lp > ./aspreify -r tests/hamiltonian_cycle.lp The reified result is RDF/N3-like format produced to tests/hamiltonian_cycle.lp.ssls > ./aspreify -d tests/hamiltonian_cycle.lp.reified The result is corresponding set of dereified rules produced to tests/hamiltonian_cycle.lp.reified.dereified > ./aspreify -g tests/hamiltonian_cycle.lp.reified The result is corresponding set of dereified and ground rules produced to tests/hamiltonian_cycle.lp.reified.ground The actual grounding must have been done beforehand; the input file must contain facts which describe the grounding. 2. Limitations 2.1 Error handling Error handling is rudimentary, syntax errors are reported, but often indicated to be after the actual error. Errors are not signaled with the return values, but the result file contains the syntax error. 2.2 Issues in input syntax All of the examples in lparse distribution examples/ directory are parsed. All syntax should be parsed, but at this version only the -t option will render the following declarations, default and -r will ignore them in the result: - maximize, minimize, compute, function, external, show, hide - #show, #hide Sometimes the hashed primitives will be converted back to nonhashed ones, e.g. #mod -> mod. At times the parser may be more liberal than the lparse one, e.g. minimize { a(X), b(Y) } will be accepted. The dereifier and grounder do not yet support the following syntactical constructs: - weighted statments - choice staments - full expressions - maximize, minimize, compute, function, external, show, hide - #show, #hide 3. Self tests Compile the parser test suite and run it: > ghc -o runparsertests testaspparse.hs aspparse.hs > ./runparsertests Run the grounding tests: > cd tests > for i in ground_input/*; do ./rungroundtest.sh $i; done 4. Use cases The directory metaeval/ contains some example programs to show potential applications for reification. 4.1 Metaevaluation metaeval/simple_variable_free.lp contains a simplistic program with no variables and metaeval/meta.lp contains a metaevaluator for variable-free answer set programs. 1. Reify the program: ./aspreify metaeval/simple_variable_free.lp to produce metaeval/simple_variable_free.lp.reified 2. Combine the metaevaluator with the reified program: cat metaeval/meta.lp metaeval/simple_variable_free.lp.reified > metaeval/x.lp 3. Calculate the answer sets: gringo metaeval/x.lp | clasp -n 0 Compare this with direct evaluation: lparse metaeval/simple_variable_free.lp | smodels 0 Or with gringo metaeval/x.lp | clasp -n 0 4.2 Metagrounding metaeval/hamilton.lp contains an answer set program with variables and metaeval/metaground.lp contains a metagrounder implementation. 0. Combine the rules with data: cat metaeval/hamilton_data1.lp metaeval/hamilton.lp > metaeval/a.lp (note, that we could also use just the rules in hamilton.lp, but grounding would not produce any results). 1. Reify the program: ./aspreify metaeval/a.lp to produce metaeval/a.lp.reified 2. Combine the metagrounder with the reified program: cat metaeval/metaground.lp metaeval/a.lp.reified > metaeval/b.lp 3. Calculate the variable assignments: gringo metaeval/b.lp | clasp -n 0 with 63 answer sets, mkassign/3 contains the variable assignments. Each answer set pertains to variable assignment to a single rule. 4. Produce the ground program, postprocess the answer sets gringo metaeval/b.lp | clasp -n 0 | python smodelsres.py will produce the answer sets to separate files named smres1.lp, smres2.lp, ..., smres63.lp Each answer set pertains to a particular variable assignment for a particular rule and nothing else. 5. Produce ground rules: ./aspreify -g metaeval/smres*.lp will produce files smres1.lp.ground, smres2.lp.ground,... which can then be catenated to one file which corresponds to the ground program and can be handled by clasp, smodels or similar. cat *.lp.ground > res.lp 5. Other smodelsres.py program reads in the resulting answer set and converts them to facts ands saves individual files with filenames corresponding to the number of the answer set. The toviz.py program reads in the reified program and generates a graphviz graph out of it. 6. TODO TODO - List the produced factnames and the documentation for them - add full rendering of all directives of the lparse/gringo language - have a look at quickcheck #EOF
About
aspreify - reify answer set programs, produces facts or RDF
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published