Skip to main content

A Python package to translate First-Order Logic (FOL) into different knowledge representation languages

Project description

alt text for screen readers

CLGC

A Python package to translate First-Order Logic (FOL) into different knowledge representation languages

Scope

A package used for handling logic statements and logic analysis using formal knowledge representation languages.

Key Features

  • Translate FOL statements to other formal Knowledge Representation (KR) languages
  • Categorize syllogisms by type

Supported KR Languages

  • Common Logic Interchange Format (CLIF)
  • Conceptual Graph Interchange Format (CGIF)
  • Tensor Function Logic (TFL)
  • Tensor Function Logic Plus (TFL+)
  • CLINGO
  • MINIFOLX
  • PROLOG

Setup

Start by installing the package

pip install clgc

Then install the dependencies

pip install -r requirements.txt

Basic Usage

To load all functionalities

from clgc.__base import *

To create a valid syllogism in FOL, each statement of the syllogism should be followed by the '\n' terminator. The following example creates a syllogism of 2 premises and a conclusion:

syllogism = FOLSyllogism("∀x (Bikes(x) → ¬Calledcars(x))\n ∀x (Bike(x) → Vehicle(x))\n ∃x (Vehicles(x) ∧ Bikes(x))\n")

To categorize syllogisms in natural language or first-order language

syllogism = FOLSyllogism("∀x (Bikes(x) → ¬Calledcars(x))\n ∀x (Bike(x) → Vehicle(x))\n ∃x (Vehicles(x) ∧ Bikes(x))\n")

print
(syllogism.categorize())
# categorical

To translate from first-order language to another language (here, TFL+)

# get syllogism as text
test_syllogism = FOLSyllogism("∀x (Bikes(x) → ¬Calledcars(x))\n ∀x (Bike(x) → Vehicle(x))\n ∃x (Vehicles(x) ∧ Bikes(x))\n").syllogism
# convert to desired logical notation - here TFL+
tfl_plus_syllogism = FOLSyllogism.fol_to_tfl_plus(test_syllogism)

print(tfl_syllogism)
# -(+B0--+C0)-(+B0-+V0)+(+V1++B1)

A list of functions are available to modify a syllogism:

  • add_statements (automatically adds the given statements in that order meaning the last given statement becomes the conclusion of the syllogism)
  • add_premises (automatically keeps the original conclusion and adds everything given as premises)
  • add_conclusion (automatically takes the given statement as the conclusion and renders everything else to premises)

An example of adding new statements

test_syllogism = FOLSyllogism("∃x (Canine(x) ∧ ¬AquaticCreatureKnownAsFish(x))\n")
        test_syllogism.add_statements(["∀x (Fish(x) → ¬MammalThereforeEveryCanineFallUnderTheCategoryOfMammal(x))\n"])   

print(test_syllogism.statements)
# ["∃x (Canine(x) ∧ ¬AquaticCreatureKnownAsFish(x))", "∀x (Fish(x) → ¬MammalThereforeEveryCanineFallUnderTheCategoryOfMammal(x))"])

An example of adding new premises

test_syllogism = FOLSyllogism("∃x (Canine(x) ∧ ¬AquaticCreatureKnownAsFish(x))\n ∀x (Bike(x) → Vehicle(x))\n")
        test_syllogism.add_premises(["∀x (Fish(x) → ¬MammalThereforeEveryCanineFallUnderTheCategoryOfMammal(x))\n"]) 

print(test_syllogism.premises)
# ["∃x (Canine(x) ∧ ¬AquaticCreatureKnownAsFish(x))", "∀x (Fish(x) → ¬MammalThereforeEveryCanineFallUnderTheCategoryOfMammal(x))"]

An example of adding a new conclusion

test_syllogism = FOLSyllogism("∃x (Canine(x) ∧ ¬AquaticCreatureKnownAsFish(x))\n ∀x (Bike(x) → Vehicle(x))\n")
        test_syllogism.add_conclusion("∀x (Fish(x) → ¬MammalThereforeEveryCanineFallUnderTheCategoryOfMammal(x))\n") 

print(test_syllogism.conclusion)
# "∀x (Fish(x) → ¬MammalThereforeEveryCanineFallUnderTheCategoryOfMammal(x))"

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

clgc-2.1.0.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clgc-2.1.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file clgc-2.1.0.tar.gz.

File metadata

  • Download URL: clgc-2.1.0.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for clgc-2.1.0.tar.gz
Algorithm Hash digest
SHA256 f4a7502a0d5e7488fdde1158326c6d7c1ca02aab20aad8438003220ad413718f
MD5 74d09ab344a2f3627170c2af29ccde9a
BLAKE2b-256 53fdf9c0f7276068239208d733c8fe2ebcf27c9c316ac57deeab82ccf5b6a6dc

See more details on using hashes here.

File details

Details for the file clgc-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: clgc-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for clgc-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcae4772debc30e60717f9c7c85602e7f7f10b74739afc0dcc2f5207699c8668
MD5 e9f8968953c57318fb56ef714b1a4ee6
BLAKE2b-256 1e52e220da27c337eec613c133d1352a17a488c362f4b857f9cfe338761d4059

See more details on using hashes here.

Supported by

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