<jupyter_start><jupyter_text>Quick Start of Logica on PostgresUse this CoLab to quickly try Logica on Postgres.Copy this and other examples to your drive to modify and save them as your own CoLabs.**Postgres engine is not fully supported** and some functionality can be missing.Most importantly record composite type and concequently usage of `ArgMax` is limited. However `ArgMax` aggregation should work for predicates defined witha single rule because Logica in this case gets rid of the record at compile time.You can also implement `ArgMax` with two steps: picking `Max` value and then joining the argument which produced this value, see example below.<jupyter_code># Install Logica.
!pip install logica

# Install postgresql server.
!sudo apt-get -y -qq update
!sudo apt-get -y -qq install postgresql
!sudo service postgresql start

# Prepare database for Logica.
!sudo -u postgres psql -c "CREATE USER logica WITH SUPERUSER"
!sudo -u postgres psql -c "ALTER USER logica PASSWORD '<PASSWORD>';"
!sudo -u postgres psql -U postgres -c 'CREATE DATABASE logica;'

# Connect to the database.
from logica import colab_logica
from sqlalchemy import create_engine
import pandas
engine = create_engine('postgresql+psycopg2://logica:logica@127.0.0.1', pool_recycle=3600);
connection = engine.connect();
colab_logica.SetDbConnection(connection)
%%logica MyFirstProgram

@Engine("psql");

MyFirstProgram("Hello world!");
%%logica PhilosopherCount

@Engine("psql");

Human(name: "Socrates", iq: 250, year_of_birth: -470, location: "Athens");
Human(name: "Aristotle", iq: 240, year_of_birth: -384, location: "Athens");
Human(name: "Archimedes", iq: 245, year_of_birth: -287, location: "Syracuse");
Human(name: "Themistocles", iq: 130, year_of_birth: -524, location: "Athens");

PhilosopherCount(city:, count? += 1) distinct :-
  Human(location: city, iq:), iq > 200;
%%logica HighestIqHuman1,HighestIqHuman2

@Engine("psql");

Human(name: "Socrates", iq: 250, year_of_birth: -470, location: "Athens");
Human(name: "Aristotle", iq: 240, year_of_birth: -384, location: "Athens");
Human(name: "Archimedes", iq: 245, year_of_birth: -287, location: "Syracuse");
Human(name: "Themistocles", iq: 130, year_of_birth: -524, location: "Athens");

# Finding highest iq person with ArgMax.
HighestIqHuman1(
    location:, highest_iq_person? ArgMax= name -> iq) distinct :-
  Human(name:, location:, iq:);

# Finding highest iq person with Max and a lookup.
HighestIq(location) Max= iq :- Human(iq:, location:);
HighestIqHuman2(location:, highest_iq_person:) distinct :-
  Human(name: highest_iq_person, location:, iq: HighestIq(location));<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.118202416918429, 'fraction_numerical': 0.02530211480362538, 'mean_word_length': 6.007936507936508, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '551000', 'license': 'Apache-2.0', 'n_tokens_mistral': 971, 'n_tokens_neox': 871, 'n_words': 297, 'path': 'examples/Logica_example_Postgres_Quick_Start.ipynb', 'repo_name': 'CyberFlameGO/logica', 'size': '2644'}