alpha-asp / Alpha

A lazy-grounding Answer-Set Programming system
BSD 2-Clause "Simplified" License
58 stars 10 forks source link

Answer Set Formatting #265

Open madmike200590 opened 4 years ago

madmike200590 commented 4 years ago

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

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

lorenzleutgeb commented 4 years ago

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 commented 4 years ago

@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.

madmike200590 commented 4 years ago

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

rtaupe commented 2 years ago

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 }