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

Setup

Start by installing the package

pip install -i https://test.pypi.org/simple/ clgc==0.0.1

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-1.0.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

clgc-1.0.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for clgc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e9a764bb0fa71762d21982149b59504e10ed47cca064bc5d0329825ff99387a9
MD5 c6fbef64109716fd413d253d09588ca5
BLAKE2b-256 fe8b2fdfc7bc6e811c3a0c0c0b2316fd726dc9c5e3fd98bc3d0f663282926e61

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for clgc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 734282a8a95c183b023ace7198631445eac339e9329b6df196138ebf176feac3
MD5 eb552921e5948b1fea97893e8c2c18fa
BLAKE2b-256 19597f3af7ada447b8523faedccbff2f1395b0fcb1f561e85b247f52f75fa17e

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