RSSAmplifier

Blog

Paul Brown

Recent content on Paul Brown

pbrown.meRSS feed ↗31 posts

Latest posts

Help! My boss wants AI!

Is your boss telling you that you need to add AI but not telling you what for, why or how? Don’t worry, you’re not alone and you’re not the only one. Let’s see what AI can do for you.

CLP(fd): Introduction to Solving Problems with Resource Constraints

You’ve only got so many resources and you want to maximise your profit or minimise your costs. How are you going to figure out what to do? Prolog with CLP(fd) of course!

Pattern for smooth SPA development with SWI-Prolog

When developing SPA applications using SWI-Prolog on the backend, Cross-Origin Resource Serving (CORS) can cause you all kinds of bother. In this post we look at how to develop your SPA on a single Origin, like how you’ll serve it in production, so all that bother vanishes away.

A Tau-Prolog Application

Using Tau-Prolog to generate chord inversions for 3 and 4 string fretted instruments: an application.

Failing a Generator on First Failure

There are occasions when working with some generative predicate where you don't know when you need to quit the generation until some condition fails. Trouble is, you'll fail with no chance of future success but you're now lost in an infinite loop as the generator keeps on trying. In this post we'll work through a blog pagination example and show how to use a dirty little trick with a cut.

Emacs X Window Manager On Raspberry Pi

Emacs was a great operating system, it just lacked a good text editor like Vim. Well times have moved on, now you can use Emacs as your window manager with Vim text editing. Let's try it out on a Raspberry Pi.

Basic Idea Of Recursion

Want to do something a bunch of times in Prolog? Recursion is how we do it. In this post we'll look at the most basic ideas of recursion and talk through a couple of examples.

"Hello, Tau Prolog!"

Imagine an internet where you didn't need to write JavaScript… Imagine an internet where you could write Prolog… Imagine no more, write Tau Prolog!

Predicates vs Functions

People from other languages often get a little confused with these predicate things, especially as their syntax looks similar to functions in other languages. In this post we contrast predicates and functions and demonstrate the advantage of using predicates over functions.

Prolog Partial Predicates

Did you know you can call partial predicates with arguments added later on? This is how many of the higher order predicates like `maplist` work. But you can take advantage of this too! Let's take a look at `call`.

Prolog: Forwards and Backwards

A key idiom in Prolog is the idea that it runs both forwards and backwards. If you've never programmed in Prolog before, this can be mind-blowing! You can write one 'function' and get many different uses out of it. In this post we'll take a look at what this means as a teaser that might tempt you into giving Prolog a go.

Homoiconic Prolog: Explain yourself!

Prolog is rather popular for Expert Systems. Why? Well because it's homoiconic and because we have DCG's, we can reify a query to make it explain itself. That's a lot of jargon, in this post we'll break it down and make some explanations.

Difference Lists Explored

In Prolog, Difference Lists are a very powerful and useful tool. They're also difficult to understand and can result in difficult to read code. In this post we'll address both of these issues.

Functional Prolog: Map, Filter and Reduce

Prolog programs have both logical and procedural meanings. In this post we'll take a look at procedural ideas more commonly associated with functional programming than Prolog, namely: map, filter and reduce (foldl and foldr). We'll code them and then query them.

Transitive Relations, A Deeper Dive

Transitive relations show up a lot in AI code, in this post we look at a couple of ways to code them that depend on what you can assume about your domain and what Prolog you're using.

Reification By Example

Reification is a tool in the bag of tricks that can be quite tricky to understand. Rather than waffle on in the abstract, let's take a look at a few examples.

Opening the World with Three-Valued Logic

Under the open world assumption a fact can be True, False or Unknown. Prolog operates in a closed world where predicates are either True or False. Let's see if we can open Prolog up a little.

Framing Frames

If you've been doing some reading, you may have come across the notion of frames as a data structure, but little available information on what they are and how they work. Implementations of frames are even rarer. In this post we'll examine what they are and consider alternative representations and implementations.

The Golog Elevator

Golog is a logic programming language for dynamic domains based in Situation Calculus with an interpreter written in Prolog. The classic example from the book is that of an elevator. Here we present an interactive version of that program.

Operators For A Controlled Natural Language

Prolog allows us to declare our own operators, this allows us to quickly take a bunch of predicates and query them in a bodge-job controlled 'semi-natural' language.

10 minute GUI for your Prolog app

We exploit the Python eco-system to make a GUI for a Prolog program, run with SWI-Prolog, in under 10 minutes

Reflexive, Symmetric and Transitive Relations in Prolog

When we start doing knowledge representation in Prolog, we start needing to describe the properties of relations so we can infer more than is in our recorded data. Symmetry, reflexivity and transitivity are the three main relationship properties you'll end up using. In this interactive post we take a look at how they can be encoded.

Starting with Knowledge Graphs

Knowledge Graphs are a hot topic, no wonder considering how powerful they can be. However, learning how to create, develop, and use them can be a bit of a minefield. In this post we provide a high-level overview and recommend some learning resources.

Rock, Paper, Scissors, Prolog!

Simple, classic games like Rock, Paper, Scissors are good to code when learning a new language. The lovely thing about making this game in Prolog is you’re just encoding what it is, not how it is. It’s a subtle difference, but I’ll point it out during this explanation.

Getting JSON data from an API in SWI-Prolog

Some folks don’t make their data available through RDF formats, or nice SPARQL endpoints, instead they provide a (REST/RESTFUL) API and will return JSON data for your request. It can be a little tricky figuring out how to get this data into your SWI-Prolog program. So in this post I demonstrate with a simple example.

Setting Up Unit Testing In SWI-Prolog

Reading the docs for plunit, it can be quite tricky to figure out how to setup a nice unit testing environment and actually run those tests. In this post I demonstrate how I do it, keeping my tests separate from my code, and running them with a handy command.

Python Generators, yield and send

Another little known Python feature that deserves more love. This time we’re looking at the send function that lets you input values into your generator as it’s running. It works through yield and is awesome!

The semantic difference between for and for

In Python we have for loops and list comprehension. In this post we’ll examine the semantic difference between the two in order to determine when it is appropriate to use each one.

RDFLib Graph with RDBS

It’s tricky to find out how to set up RDFLib Graph to use a RDBS backend, but it can be done using SQLAlchemy and RDFLib-SQLAlchemy. This means it’ll support all the engines SQLAlchemy does, including MySQL and Postgres. I’ll highlight two gotchas to look out for when using RDFLib-SQLAlchemy and walk you through getting setup using a wrapper class to RDFLIB Graph.

Typing Description Logics Cheat Sheet

Many of the unusual symbols we use when writing Description Logics are sadly not found on the keyboard. I wrote myself a little cheat sheet to remind myself of the correct unicode or LaTeX for the common symbols and added a short description of each symbol as well. It’s very useful to print out and keep near your keyboard so you can type Description Logics quickly and painlessly.

Making Semantic Web Applications With Flask: Starting With FOAF

An introduction to programming the Semantic Web using Python and Flask. We’ll make an RDF file to describe ourselves, serve it via Flask, use data from it in a template, encode it into our HTML, and link to it from our HTML.