Skip to main content

ASPars allows to parse Answer Sets into python structures

Project description

ASPars

Quick and easy parsing of Answer Sets into friendly python structures.

Specification

ASPars allows the user to parse answer sets represented in the following formats:

  • wasp format, e.g., {a, b(x), c(y,...,z), ...},
  • clasp format, e.g., a b(x) c(y,...,z) ....

An answer set is parsed into a list of predicates. A predicate is represented as a dictionary with the following keys:

  • name: name of the predicate,
  • ext: a list of the (heterogeneous) values of the predicate,
  • arity: arity of the predicate (e.g., length of the extension).

If the predicate is an atom, then only name is defined.

Example

{a, foo(x), bar(42,"42")} is parsed into the following singleton:

[
    {'name': 'a'},
    {'name': 'foo', 'ext': ['x'], 'arity': 1},
    {'name': 'bar', 'ext': [42, '"42"'], 'arity': 2}
]

Usage

ASPars can be used by simply importing it or as a standalone module.

Importing ASPars in a python program

from aspars import ASPars

answer_sets_waspf = [
    '{a, foo(x), bar(-1,1), fizz("42")}',
    '{b, foo(y), bar(-2,2)}',
    '{c, foo(z), fizz("24")}',
]

# parses only the first answer set, returns a singleton
single = ASPars(syntax='wasp').parse(answer_sets_waspf[0])
# parse all the answer sets, returns an iterable (map)
multi = ASPars(syntax='wasp').parse(answer_sets_waspf)

# example in clasp syntax
single = ASPars(syntax='clasp').parse('b foo(y) bar(-2,2)')

Using ASPars as a standalone module

$ cat my_answer_sets | python -m aspars

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aspars-0.1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

aspars-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file aspars-0.1.0.tar.gz.

File metadata

  • Download URL: aspars-0.1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for aspars-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d4d1dd716c8627b34a402d07d66615c9c1843ce46d036f348830727bdfb4414
MD5 3e7cf1ca5179156d3db012211d113ecf
BLAKE2b-256 a2f1fd2006bb582f999318243e7869e267e9eb3aa08c140b321eb699a1cf3581

See more details on using hashes here.

File details

Details for the file aspars-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aspars-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for aspars-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74dbc97a41804c2c7219e2bc2a23127829b47cecaf0d9df217547009620ecfd4
MD5 855106dfa40e5f757850db6cdf9e2923
BLAKE2b-256 729bc83554a5e5378994853afd88ea42ce7cb3c9de0920977586f539f3db8c46

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page