amr-logic-converter

Convert Abstract Meaning Representation (AMR) into first-order logic

https://github.com/chanind/amr-logic-converter

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary

Keywords

abstract-meaning-representation amr first-order-logic logic

Keywords from Contributors

spacy-extension
Last synced: 6 months ago · JSON representation ·

Repository

Convert Abstract Meaning Representation (AMR) into first-order logic

Basic Info
  • Host: GitHub
  • Owner: chanind
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 95.7 KB
Statistics
  • Stars: 16
  • Watchers: 4
  • Forks: 1
  • Open Issues: 1
  • Releases: 21
Topics
abstract-meaning-representation amr first-order-logic logic
Created over 3 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License Citation

README.md

AMR Logic Converter

ci Codecov PyPI

Convert Abstract Meaning Representation (AMR) to first-order logic statements.

This library is based on the ideas in the paper "Expressive Power of Abstract Meaning Representations", J. Bos, Computational Linguistics 42(3), 2016. Thank you to @jobos for the paper!

Installation

pip install amr-logic-converter

Usage

This library parses an AMR tree into first-order logic statements. An example of this is shown below:

```python from amrlogicconverter import AmrLogicConverter

converter = AmrLogicConverter()

AMR = """ (x / boy :ARG0-of (e / giggle-01 :polarity -)) """

logic = converter.convert(AMR) print(logic)

boy(x) ^ ¬(:ARG0(e, x) ^ giggle-01(e))

```

Programmatic logic manipulation

The output from the convert method can be displayed as a string, but it can also be manipulated in Python. For instance, in the example above, we could also write:

```python converter = AmrLogicConverter()

AMR = """ (x / boy :ARG0-of (e / giggle-01 :polarity -)) """

expr = converter.convert(AMR) type(expr) # expr.args[0] # Atom(predicate=Predicate(symbol='boy', alignment=None), terms=(Constant(value='x', type='instance', alignment=None),)) ```

Working with alignment markers

This library will parse alignment markers from AMR using the penman library, and will include Alignment objects from penman in Predicate and Const objects when available. For example, we can access alignment markers like below:

```python converter = AmrLogicConverter()

AMR = """ (x / boy~1 :ARG0-of (e / giggle-01~3 :polarity -)) """

expr = converter.convert(AMR) expr.args[0].alignment # Alignment((1,)) expr.args[1].body.args[1].alignment # Alignment((3,)) ```

Existentially Quantifying all Instances

In "Expressive Power of Abstract Meaning Representations", all instances are wrapped by an existence quantifier. By default AmrLogicConverter does not include these as it's likely not useful, but if you'd like to include them as in the paper you can pass the option existentially_quantify_instances=True when constructing the AmrLogicConverter as below:

```python converter = AmrLogicConverter(existentiallyquantifyinstances=True)

AMR = """ (x / boy :ARG0-of (e / giggle-01 :polarity -)) """

logic = converter.convert(AMR) print(logic)

∃X(boy(X) ^ ¬∃E(:ARG0(E, X) ^ giggle-01(E)))

```

Coreference Hoisting

When an instance is coreferenced in multiple places in the AMR, it's necessary to hoisting the existential quantification of that variable high enough that it can still wrap all instances of that variable. By default, the existential quantifier will be hoisted to the level of the lowest common ancestor of all nodes in the AMR tree where an instance is coreferenced. However, in "Expressive Power of Abstract Meaning Representations", these coreferences are instead hoisted to the maximal possible scope, wrapping the entire formula. If you want this behavior, you can specify the option maximally_hoist_coreferences=True when creating the AmrLogicConverter instance. This is illustrated below:

```python AMR = """ (b / bad-07 :polarity - :ARG1 (e / dry-01 :ARG0 (x / person :named "Mr Krupp") :ARG1 x)) """

default behavior, hoist only to the lowest common ancestor

converter = AmrLogicConverter( existentiallyquantifyinstances=True, ) logic = converter.convert(AMR) print(logic)

¬∃B(bad-07(B) ∧ ∃E(∃X(:ARG1(B, E) ∧ person(X) ∧ :named(X, "Mr Krupp") ∧ dry-01(E) ∧ :ARG0(E, X) ∧ :ARG1(E, X))))

maximally hoist coferences

converter = AmrLogicConverter( existentiallyquantifyinstances=True, maximallyhoistcoreferences=True, ) logic = converter.convert(AMR) print(logic)

∃X(¬∃B(bad-07(B) ∧ ∃E(:ARG1(B, E) ∧ dry-01(E) ∧ :ARG0(E, X) ∧ :ARG1(E, X))) ∧ person(X) ∧ :named(X, "Mr Krupp"))

```

Using Variables for Instances

If you want to use variables for each AMR instance instead of constants, you can pass the option use_variables_for_instances=True when creating the AmrLogicConverter instance. When existentially_quantify_instances is set, variable will always be used for instances regardless of this setting.

Misc Options

  • By default variables names are capitalized, but you can change this by setting capitalize_variables=False.
  • By default, relations like :ARG0-of(X, Y) have their arguments flipped in logic and turned into :ARG0(Y, X). If you don't want this normalization to occur, you can disable this by setting invert_relations=False.

Contributing

Contributions are welcome! Please leave an issue in the Github repo if you find any bugs, and open a pull request with and fixes or improvements that you'd like to contribute. Ideally please include new test cases to verify any changes or bugfixes if appropriate.

This project uses poetry for dependency management and packaging, black for code formatting, flake8 for linting, and mypy for type checking.

License

This project is licenced under a MIT license.

Citation

If you use this software in your work, please cite the following:

bibtex @article{chanin2023neuro, title={Neuro-symbolic Commonsense Social Reasoning}, author={Chanin, David and Hunter, Anthony}, journal={arXiv preprint arXiv:2303.08264}, year={2023} }

Owner

  • Name: David Chanin
  • Login: chanind
  • Kind: user
  • Location: London, UK
  • Company: UCL

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Chanin"
  given-names: "David"
- family-names: "Hunter"
  given-names: "Anthony"
title: "Neuro-symbolic Commonsense Social Reasoning"
doi: 10.48550/arXiv.2303.08264
date-released: 2023-03-14
url: "https://arxiv.org/abs/2303.08264"

GitHub Events

Total
  • Issues event: 1
  • Watch event: 4
  • Fork event: 1
Last Year
  • Issues event: 1
  • Watch event: 4
  • Fork event: 1

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 73
  • Total Committers: 3
  • Avg Commits per committer: 24.333
  • Development Distribution Score (DDS): 0.288
Past Year
  • Commits: 9
  • Committers: 2
  • Avg Commits per committer: 4.5
  • Development Distribution Score (DDS): 0.444
Top Committers
Name Email Commits
David Chanin c****v@g****m 52
github-actions a****n@g****m 17
github-actions g****s@g****m 4
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 8
  • Average time to close issues: N/A
  • Average time to close pull requests: 2 minutes
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.25
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • thomasdavis (1)
Pull Request Authors
  • chanind (9)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 154 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 19
  • Total maintainers: 1
pypi.org: amr-logic-converter

Convert Abstract Meaning Representation (AMR) into first-order logic

  • Versions: 19
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 154 Last month
Rankings
Dependent packages count: 10.0%
Average: 17.7%
Downloads: 21.5%
Dependent repos count: 21.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

pyproject.toml pypi
  • black ^22.10.0 develop
  • flake8 ^5.0.4 develop
  • mypy ^0.982 develop
  • pytest ^7.1.3 develop
  • pytest-cov ^4.0.0 develop
  • syrupy ^3.0.2 develop
  • Penman ^1.2.2
  • nltk ^3.7
  • python >=3.7, <4.0
  • typing-extensions ^4.4.0
.github/workflows/ci.yaml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • chanind/python-semantic-release 7-28-1-packaging-fix composite
  • codecov/codecov-action v2 composite
  • snok/install-poetry v1 composite