lexpr


Namelexpr JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/ggonnella/lexpr
SummaryA parser for simple logical expressions of identifiers
upload_time2023-03-15 08:45:54
maintainer
docs_urlNone
authorGiorgio Gonnella
requires_python
licenseISC
keywords bioinformatics sequence features
VCS
bugtrack_url
requirements lark
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Lexpr: A simple logical expressions parser

Lexpr is a simple package containing a
logical expressions parser developed using a Lark grammar.

The expressions may contain:
- entity identifiers
- the binary operators ``|`` (or), ``&`` (and)
- the unary operator ``!`` (not).
- balanced pairs of round parentheses

## Installation

The package can be installed using ``pip install lexpr``.

## Usage

A parser is created and used for parsing the text, as in the
following example:
```
import lexpr
lp = lexpr.Parser()
lp.parse("(G1 & G2) | !G3")
#
# output:
#
#  Tree(
#    Token('RULE', 'start'),
#    [Tree(Token('RULE', 'entity'),
#      [Tree(Token('RULE', 'or_expr'),
#        [Tree(Token('RULE', 'entity'),
#          [Tree(Token('RULE', 'enclosed_expr'),
#            [Tree(Token('RULE', 'entity'),
#              [Tree(Token('RULE', 'and_expr'),
#                [Tree(Token('RULE', 'entity'), [Token('IDENTIFIER', 'G1')]),
#                 Tree(Token('RULE', 'entity'), [Token('IDENTIFIER', 'G2')])])]
#            )]
#          )]
#        ), Tree(Token('RULE', 'entity'),
#             [Tree(Token('RULE', 'not_expr'),
#               [Tree(Token('RULE', 'entity'), [Token('IDENTIFIER', 'G3')])]
#             )]
#           )]
#      )]
#    )]
#  )

```

In case of an invalid string is passed to the parser, an
exception is raised:
```
import lexpr
lp = lexpr.Parser()
lp.parse("G1 &")
# raises LexprParserError, unbalanced expression
lp.parse("G1 & G$")
# raises LexprParserError, invalid character in identifier
```

## Implementation

The grammar is contained in the file ``lexpr/data/lexpr.g``.
The parser is in the module ``lexpr/parser.py``.
Errors raised by the module are defined in ``lexpr/error.py``
and are instances of the class ``LexprError`` or its
subclasses.

## History

The package has been developed to support the parsing of the EGC format, for
expressing expectations about the contents of prokaryotic genomes. In this
format, groups of organisms can be combined using logical expressions of the
form parsed by this package. The main implementation of the format is based on
TextFormats, which, however does not support non-regular, indefinetly nested
expressions, such as the logical expressions parsed here. Thus the parsing of
this expressions has been developed separately in this package.

## Acknowledgements

This package has been created in context of the DFG project GO 3192/1-1
“Automated characterization of microbial genomes and metagenomes by collection
and verification of association rules”. The funders had no role in study
design, data collection and analysis.




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ggonnella/lexpr",
    "name": "lexpr",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "bioinformatics sequence features",
    "author": "Giorgio Gonnella",
    "author_email": "gonnella@zbh.uni-hamburg.de",
    "download_url": "https://files.pythonhosted.org/packages/e1/70/34a6a0736d5233b164922f8e9f78d11d8b4f433e30c4124bfd849e0dedd7/lexpr-0.1.tar.gz",
    "platform": null,
    "description": "# Lexpr: A simple logical expressions parser\n\nLexpr is a simple package containing a\nlogical expressions parser developed using a Lark grammar.\n\nThe expressions may contain:\n- entity identifiers\n- the binary operators ``|`` (or), ``&`` (and)\n- the unary operator ``!`` (not).\n- balanced pairs of round parentheses\n\n## Installation\n\nThe package can be installed using ``pip install lexpr``.\n\n## Usage\n\nA parser is created and used for parsing the text, as in the\nfollowing example:\n```\nimport lexpr\nlp = lexpr.Parser()\nlp.parse(\"(G1 & G2) | !G3\")\n#\n# output:\n#\n#  Tree(\n#    Token('RULE', 'start'),\n#    [Tree(Token('RULE', 'entity'),\n#      [Tree(Token('RULE', 'or_expr'),\n#        [Tree(Token('RULE', 'entity'),\n#          [Tree(Token('RULE', 'enclosed_expr'),\n#            [Tree(Token('RULE', 'entity'),\n#              [Tree(Token('RULE', 'and_expr'),\n#                [Tree(Token('RULE', 'entity'), [Token('IDENTIFIER', 'G1')]),\n#                 Tree(Token('RULE', 'entity'), [Token('IDENTIFIER', 'G2')])])]\n#            )]\n#          )]\n#        ), Tree(Token('RULE', 'entity'),\n#             [Tree(Token('RULE', 'not_expr'),\n#               [Tree(Token('RULE', 'entity'), [Token('IDENTIFIER', 'G3')])]\n#             )]\n#           )]\n#      )]\n#    )]\n#  )\n\n```\n\nIn case of an invalid string is passed to the parser, an\nexception is raised:\n```\nimport lexpr\nlp = lexpr.Parser()\nlp.parse(\"G1 &\")\n# raises LexprParserError, unbalanced expression\nlp.parse(\"G1 & G$\")\n# raises LexprParserError, invalid character in identifier\n```\n\n## Implementation\n\nThe grammar is contained in the file ``lexpr/data/lexpr.g``.\nThe parser is in the module ``lexpr/parser.py``.\nErrors raised by the module are defined in ``lexpr/error.py``\nand are instances of the class ``LexprError`` or its\nsubclasses.\n\n## History\n\nThe package has been developed to support the parsing of the EGC format, for\nexpressing expectations about the contents of prokaryotic genomes. In this\nformat, groups of organisms can be combined using logical expressions of the\nform parsed by this package. The main implementation of the format is based on\nTextFormats, which, however does not support non-regular, indefinetly nested\nexpressions, such as the logical expressions parsed here. Thus the parsing of\nthis expressions has been developed separately in this package.\n\n## Acknowledgements\n\nThis package has been created in context of the DFG project GO 3192/1-1\n\u201cAutomated characterization of microbial genomes and metagenomes by collection\nand verification of association rules\u201d. The funders had no role in study\ndesign, data collection and analysis.\n\n\n\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "A parser for simple logical expressions of identifiers",
    "version": "0.1",
    "split_keywords": [
        "bioinformatics",
        "sequence",
        "features"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d72c90dc3c45c423a20f5af3f6b3415b0d1b087bfc00698c82a96f605ad2754c",
                "md5": "dd23f2e0c603799767a188be2c911501",
                "sha256": "0941a73301fb808b3b41718b4ecd4a9cd258e36766795a26f831e869a189157b"
            },
            "downloads": -1,
            "filename": "lexpr-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dd23f2e0c603799767a188be2c911501",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4349,
            "upload_time": "2023-03-15T08:45:53",
            "upload_time_iso_8601": "2023-03-15T08:45:53.525736Z",
            "url": "https://files.pythonhosted.org/packages/d7/2c/90dc3c45c423a20f5af3f6b3415b0d1b087bfc00698c82a96f605ad2754c/lexpr-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e17034a6a0736d5233b164922f8e9f78d11d8b4f433e30c4124bfd849e0dedd7",
                "md5": "dbc5ff383f2b6fa7be83aabba9cdb50d",
                "sha256": "4a2cf447634bd9f27c03b0c45352d132a020854ffa481d3a465f36cfae0717d3"
            },
            "downloads": -1,
            "filename": "lexpr-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "dbc5ff383f2b6fa7be83aabba9cdb50d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4050,
            "upload_time": "2023-03-15T08:45:54",
            "upload_time_iso_8601": "2023-03-15T08:45:54.888893Z",
            "url": "https://files.pythonhosted.org/packages/e1/70/34a6a0736d5233b164922f8e9f78d11d8b4f433e30c4124bfd849e0dedd7/lexpr-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-15 08:45:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ggonnella",
    "github_project": "lexpr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "lark",
            "specs": []
        }
    ],
    "lcname": "lexpr"
}
        
Elapsed time: 0.05737s