pystc: A simple but extensible Python module for sentences
Introduction
A sentence is an atomic sentence or a (compound) sentence. An atomic sentence consists of a predicate and constants the predicate has as its arguments. There is no variable, no function. The number of arguments of a predicate is called the arity of the predicate. A compound sentence can be obtained by joining sentences with connectives.
pystc is a simple but extensible Python module for sentences. It provides functionality to define sentences as you like by adding constants, predicates, and connectives, whether logical or non-logical. Constants, predicates, and connectives can be introduced by specifying their names and how they are associated with other well-defined objects or functions.
Installation
$ pip install pystc
Usage
Let us first create atomic sentences that can be built from a predicate = and constants T, F,
from pystc import AtomicSentence
# Let us add predicate "=" so that the arity for it is 2.
AtomicSentence.add_predicate("=",2)
AtomicSentence.add_constant("T")
AtomicSentence.add_constant("F")
# Now, sentences are ready to create.
s1 = AtomicSentence("=","T","T")
s2 = AtomicSentence("=","T","F")
s3 = AtomicSentence("=","F","T")
assert str(s2) == "=(T,F)"
assert AtomicSentence.read("=(T,F)") == s2
Let us next construct compound sentences. A Sentence in pystc module is simply a recursive type defined to be:
Sentence = Union[str, AtomicSentence, Tuple["Sentence"]]
Although it is loosely defined for simplicity, sentences are implicitly expected to fall into one of the following cases:
1. An AtomicSentence object, say s2. 1. The string representation of an AtomicSentence object, say "=(T,F)". 1. A tuple such that the initial entry is a connective name and the other entries are Sentence objects, say ("&", s2, ("!", s2)).
As the connective names "&" and "!" appears just above, let us introduce these connectives in the following codeblock and inteprete sentences.
from pystc import SentenceConverter
# Let us set an atomic sentence type and how each symbol is interpreted.
SentenceConverter.set_atom_type(AtomicSentence)
SentenceConverter.set_constant_destination("T", True)
SentenceConverter.set_constant_destination("F", False)
SentenceConverter.set_predicate_destination("=", lambda li,w: li[0]==li[1])
SentenceConverter.set_connective_destination("&",lambda li,w: not False in li)
SentenceConverter.set_connective_destination("|",lambda li,w: True in li)
SentenceConverter.set_connective_destination("!",lambda li,w: not li[0])
assert SentenceConverter.convert(s2) == False
assert SentenceConverter.convert("=(T,F)") == False
assert SentenceConverter.convert(("&", s2, ("!", s2))) == False
assert SentenceConverter.convert(("&", "=(T,F)", ("!", s2))) == False
For another example of usage, let us convert sentences into strings in infix notation.
# Clear all class variables
SentenceConverter.clear()
SentenceConverter.set_atom_type(AtomicSentence)
SentenceConverter.set_constant_destination("T", "T")
SentenceConverter.set_constant_destination("F", "F")
SentenceConverter.set_predicate_destination("=", lambda li,w: f"{li[0]}={li[1]}")
SentenceConverter.set_connective_destination("&",lambda li,w: "("+" & ".join(li)+")")
SentenceConverter.set_connective_destination("|",lambda li,w: "("+" | ".join(li)+")")
SentenceConverter.set_connective_destination("!",lambda li,w: "!"+li[0])
assert SentenceConverter.convert("=(T,F)") == "T=F"
assert SentenceConverter.convert(("&", s2, ("!", s2))) == "(T=F & !T=F)"
Let us not forget to clear class variables after everything is finished.
SentenceConverter.clear()
AtomicSentence.clear()
Bugs/Requests/Discussions
Please report bugs and requests from GitHub Issues , and ask questions from GitHub Discussions .
License
Please see LICENSE .
Metadata
Release files for pystc 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pystc-2.0.0.tar.gz | 5.9 kB | Without provenance | Details for pystc-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pystc-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for pystc-2.0.0-py3-none-any.whl |
Total release size: 12.4 kB
Release files / pystc-2.0.0.tar.gz
| Download URL | pystc-2.0.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8303eba5b2058ee666c1c65cacf124c0c441c209d1ebcd3db66361f4cc0eb3e
|
|
BLAKE2b-256 checksum How to use checksums |
21db940b6e86e9d3c6f7de1355a19a834e4d1705711ddbbcca95f3e45a914e12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / pystc-2.0.0-py3-none-any.whl
| Download URL | pystc-2.0.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dec1011da7299b17b162ead59fa096e80f9c361fddcf99b150c943f9f135a783
|
|
BLAKE2b-256 checksum How to use checksums |
7f5cc98b04feb4c7dd749e7fa3804cf95d06fc9141d889b2f25b8b502a48ebb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Security for pystc 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.