PySwip enables querying SWI-Prolog in your Python programs.
Project description
PySwip
What's New?
See the CHANGELOG.
Install
If you have SWI-Prolog installed, it's just:
pip install pyswip
See INSTALL for detailed instructions.
Introduction
PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
Since PySwip uses SWI-Prolog as a shared library and ctypes to access it, it doesn't require compilation to be installed.
PySwip was brought to you by the PySwip community. Thanks to all contributors.
Examples
Using Prolog
from pyswip import Prolog
prolog = Prolog()
prolog.assertz("father(michael,john)")
prolog.assertz("father(michael,gina)")
list(prolog.query("father(michael,X)")) == [{'X': 'john'}, {'X': 'gina'}]
for soln in prolog.query("father(X,Y)"):
print(soln["X"], "is the father of", soln["Y"])
# michael is the father of john
# michael is the father of gina
An existing knowledge base stored in a Prolog file can also be consulted, and queried. Assuming the filename "knowledge_base.pl" and the Python is being run in the same working directory, it is consulted like so:
>>> from pyswip import Prolog
>>> prolog = Prolog()
>>> prolog.consult("knowledge_base.pl")
Foreign Functions
from __future__ import print_function
from pyswip import Prolog, registerForeign
def hello(t):
print("Hello,", t)
hello.arity = 1
registerForeign(hello)
prolog = Prolog()
prolog.assertz("father(michael,john)")
prolog.assertz("father(michael,gina)")
print(list(prolog.query("father(michael,X), hello(X)")))
Pythonic interface (Experimental)
from __future__ import print_function
from pyswip import Functor, Variable, Query, call
assertz = Functor("assertz", 1)
father = Functor("father", 2)
call(assertz(father("michael","john")))
call(assertz(father("michael","gina")))
X = Variable()
q = Query(father("michael",X))
while q.nextSolution():
print("Hello,", X.value)
q.closeQuery()
# Outputs:
# Hello, john
# Hello, gina
The core functionality of Prolog.query
is based on Nathan Denny's public domain prolog.py.
Help!
Projects/Publications that Use or Reference PySwip
Do you have a project, video or publication that uses/mentions PySwip? file an issue or send a pull request.
If you would like to reference PySwip in a LaTeX document, you can use the provided BibTeX file.
Books
Publications
- Assessment of Graph Databases as a Viable Materiel Solution for the Army's Dynamic Force Structure (DFS) Portal Implementation: Part 3, Risks, Mitigation Approach, and Roadmap
- Tackling Complexity in High Performance Computing Applications
- Social Human-Robot Interaction: A New Cognitive and Affective Interaction-Oriented Architecture
- A Planning Module for a ROS-Based Ubiquitous Robot Control System (PDF)
- A pilot framework developed as a common platform integrating diverse elements of computer aided fixture design
- Integration von Prolog und ClioPatria in Python (PDF, German)
- SELECTSCRIPT: A Query Language for Robotic World Models and Simulations
- A Concept for Declarative Information Acquisition in Smart Environments (PDF)
- Implementation on ADHD Diagnostic Expert System based on DSM Diagnostic Criteria (PDF, Korean)
- Wie sehen Krebsmolekule aus? Vergleich der Gute der Klassifizierung potenziell krebserregender Molekule durch induktiv logische und merkmalsbasierte Lernverfahren (PDF, German)
- Companion Robots Behaving with Style: Towards Plasticity in Social Human-Robot Interaction (PDF)
- Semi-automatically Augmenting Attack Trees using an Annotated Attack Tree Library
- A Learning Framework for Tool Creation by a Robot (PDF)
- Conceptual Maps as the First Step in an Ontology Construction Method
- Fact-Based Expert System for Supplier Selection with ERP Data
- Interactive Text Graph Mining with a Prolog-based Dialog Engine
- The Detection Of Conflicts In The Requirements Specification Based On An Ontological Model And A Production Rule System
- Dependency-based Text Graphs for Keyphrase and Summary Extraction with Applications to Interactive Content Retrieval (PDF)
- Information Retrieval Based on Knowledge-Enhanced Word Embedding Through Dialog: A Case Study
- Exploring the world of declarative programming
- Development of a Prototype of a Medical Application Using a Type-2 Fuzzy Inference System
- Learning Where and When to Reason in Neuro-Symbolic Inference (PDF)
- MMDect: Metamorphic Malware Detection Using Logic Programming (PDF)
- Continuous QoS-compliant orchestration in the Cloud-Edge continuum (Code)
Videos
- AI - Blocks world solver interactive planner
- PySwip, Prolog, Javascript and HTML (Spanish)
- Get out of the maze with Prolog and Python (Spanish)
- Les robots deviennent (vraiment) intelligents ! (NAO discute avec Kylo Ren)
- Connect Python and Prolog | Using Pyswip Module | Using Prolog as Backend
- How to connect Prolog and Python Using Pyswip Module
- Praktikum Sistem Pakar 01 - Pengenalan Prolog, SWI-Prolog, PySwip (Indonesian)
- Curso Básico de Prolog: 4 - Interconectando Python con Prolog a través de PySwip (Spanish)
Projects
- noworkflow Supporting infrastructure to run scientific experiments without a scientific workflow management system. http://gems-uff.github.io/noworkflow
- Super Pacman
- Pokemon Weak Detector
- Food Recommendations in Hyderabad, India Food Recommendation AI Expert System using a GUI hosted on Flask and a backend developed with PYSWIP and native Prolog.
- pyswip_envctrl An environment control module expert system written in PySwip.
- tic-tac-toe Tic-tac-toe game with AI in Prolog and GUI in Python (kivy framework + pyswip).
- TBM1 - "Getting to Know My Home"
- Prolog natural language parsing component to control a Scribbler II robot over bluetooth
- Cosmos A new logic programming language.
- lib-annotated-attack-trees Scripts and resources for creating a library of annotated attack trees and using it to refine an annotated attack tree.
- ClIDE Command-line Intelligent Development Environment
- Artificial Intelligence INF1771 @ PUC-Rio Projects for the Artificial Intelligence class @ PUC-Rio
- AutomobileAdvisor Projekt na systemy ekspertowe pomagający wybrać odpowiedni samochód dla danego klienta na podstawie preferencji (Polish)
- Prolog Tetris AI
- Jupyter SWI Prolog A Jupyter Kernel for SWI-Prolog.
- Blocks World Planner A program that allows users to solve the blocks world problem interacting only using the natural language.
- DeepTalk A Python+Prolog based Dialog Engine using the Python package text_graph_crafts that extracts the highest ranked sentences answering a query.
- DeepRank The system uses dependency links for building Text Graphs, that with help of a centrality algorithm like PageRank, extract relevant keyphrases, summaries and relations from text documents.
- Prolog Tic-tac-toe A full-stack tic-tac-toe game with AI in Prolog, backend in Python3 (+Flask) and frontend in Vue.js 3.
- MIDSI Project Solution for data discovery in projects applicable to the Semantic Web, enabling the loading of ontologies and inference of results using the WSML language.
- Popper An inductive logic programming system.
- Trabajo Final Ingeniería para Sistemas de Información (Spanish)
- norms-games Integration of normative systems and game theory
Blog Posts
- Calling Prolog from Python
- Python v. Prolog: Round 1: Fight!
- Path Follower: Arduino+Rasp on ROS and its Project code
- 10 minutes to make a GUI for your SWI-Prolog App via Python
- Playing with Prolog – Prolog’s Role in the LLM Era, Part 3
- Prolog - Gateway to Logic Programming
Companies using PySwip
- Magazino GmbH Magazino develops and builds intelligent, mobile robots for intralogistics.
License
Copyright (c) 2007-2024 Yüce Tekol and PySwip contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.