Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer Set Formatting #265

Open
madmike200590 opened this issue Aug 6, 2020 · 4 comments
Open

Answer Set Formatting #265

madmike200590 opened this issue Aug 6, 2020 · 4 comments

Comments

@madmike200590
Copy link
Collaborator

madmike200590 commented Aug 6, 2020

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

@lorenzleutgeb
Copy link
Member

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
Copy link
Member

@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
Copy link
Collaborator Author

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

@rtaupe
Copy link
Collaborator

rtaupe commented Dec 1, 2021

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 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants