Alpha icon indicating copy to clipboard operation
Alpha copied to clipboard

Answer Set Formatting

Open madmike200590 opened this issue 5 years ago • 4 comments

In addition to current answer set printing facilities, the following additional features should be added to Alpha:

  • Write Answer Sets as JSON (see below, we might want to use Yasson for this)
  • Atom formatting using format strings: Format each atom in an answer set using a format string passed via commandline. (Should be easy to do using strintemplate since it's a quite powerful template engine on which Alpha already depends anyway)
  • Print answer sets as sets of facts as outllined by @rtaupe below.

Code-wise, implement each of these as an implementation of the AnswerSetFormatter interface

madmike200590 avatar Aug 06 '20 14:08 madmike200590

For JSON, output, consider what clingo does:

{
  "Solver": "clingo version 5.4.0",
  "Input": [
    "examples/clingo/consequences/example.lp"
  ],
  "Call": [
    {
      "Witnesses": [
        {
          "Value": [
            "atom(q)", "atom(p(1))", "atom(p(2))", "atom(p(3))", "atom(p(4))", "atom(p(5))", "atom(p(6))", "atom(p(7))", "atom(p(8))", "atom(p(9))", "atom(p(10))"
          ]
        }
      ]
    }
  ],
  "Result": "SATISFIABLE",
  "Models": {
    "Number": 1,
    "More": "yes"
  },
  "Calls": 1,
  "Time": {
    "Total": 0.001,
    "Solve": 0.000,
    "Model": 0.000,
    "Unsat": 0.000,
    "CPU": 0.001
  }
}

lorenzleutgeb avatar Aug 10 '20 10:08 lorenzleutgeb

@madmike200590 you mentioned that you might want to use Jackson in order to implement JSON output. I'd like to bring JSR-353 to your attention. There are some words regarding Jackson in this article from 2018:

Many commercial products based on Java EE use either the Glassfish SI (Specification Implementation) directly, because apart from the JSON API itself, it has no dependencies on other parts of Java EE, Jakarta EE or Glassfish. So, it can be easily used on a desktop or in a "serverless" environment. That's why the JSR as an alternative to Jackson is also supported by several popular Java frameworks like Spring. While Jackson itself does not directly implement the JSON-P standard yet, there are both Jackson types for JSR 353, which practically anticipated both JSON standards in Java EE 8, as well as a JSR 353 implementation based on Jackson.

I am using Eclipse Yasson in other projects which is an implementation of JSON-P. It might be worth to consider using this library instead of Jackson.

lorenzleutgeb avatar Aug 14 '20 10:08 lorenzleutgeb

Thanks for looking into this! Will take a look when I get to this issue

madmike200590 avatar Aug 24 '20 14:08 madmike200590

It would also be useful to have an out-of-the-box option that outputs answer sets as facts. Clingo allows this with --outf=1.

For example, the answer set { a, b } would then be printed as a. b. Currently, in Alpha it is only possible to specify the separator between atoms, but you can neither get rid of the curly braces nor output something after the same atom. E.g., when using -sep ". ", the output will be: { a. b }

rtaupe avatar Dec 01 '21 10:12 rtaupe