Home

2P in Kotlin

Some quick links:

Intro

The 2P logo

tuProlog (2P henceforth) is multi-paradigm logic programming framework written in Java.

2P-Kt is a Kotlin-based and multi-platform reboot of 2P. It aims at becoming an open ecosystem for Symbolic Artificial Intelligence (AI). For this reason, 2P-Kt consists of a number of incrementally inter-dependent modules aimed at supporting symbolic manipulation and reasoning in an extensible and flexible way.

Currently, 2P-Kt focuses on supporting knowledge representation and automatic reasoning through logic programming, by featuring:

  • a module for logic terms representation, namely core,

  • a module for logic unification representation, namely unify,

  • a module for in-memory indexing and storing logic theories, namely theory,

  • a module providing ISO Prolog resolution of logic queries, namely solve, coming with two implementations (i.e. solve-classic and solve-streams),

  • a number of modules (i.e., the many dsl-* modules) supporting a Prolog-like, Domain Specific Language (DSL) aimed at bridging the logic programming with the Kotlin object-oriented & functional environment,

  • two parsing modules: one aimed at parsing terms, namely parser-core, and the other aimed at parsing theories, namely parser-theory.

A complete overview about modules and their dependencies is provided by the following diagram:

2P-Kt project map

The modular, unopinionated architecture of 2P-Kt is deliberately aimed at supporting and encouraging extensions towards other sorts of symbolic AI systems than Prolog---such as ASP, tabled-Prolog, Problog, etc.

Furthermore, 2P-Kt is developed as in pure, multi-platform Kotlin project. This brings two immediate advantages:

  1. it virtually supports several platforms, there including JVM, JS, Android, and Native
  2. it consists of a very minimal and lightweight library, only leveraging on the Kotlin common library, as it cannot commit to any particular platform standard library

Users

2P-Kt modules are currently available through an ad-hoc Maven repository for JVM and Kotlin users. NPM modules will be deployed soon, making 2P easily available for JS users as well.

Gradle

To import the 2P-Kt module named 2P_MODULE (version 2P_VERSION) into your Gradle-based project, you must setup your Maven repositories first:

// assumes Gradle's Kotlin DSL
repositories {
    mavenCentral()
    maven("https://dl.bintray.com/pika-lab/tuprolog/")
}

and then declare the desired dependency:

// assumes Gradle's Kotlin DSL
dependencies {
   implementation("it.unibo.tuprolog", "2P_MODULE", "2P_VERSION")
}

Notice that dependencies of 2P_MODULE should be automatically imported.

Maven

To import the 2P-Kt module named 2P_MODULE (version 2P_VERSION) into your Maven-based project, you must setup your Maven repositories first:

<repositories>
    <repository>
        <id>bintray-2p-repo</id>
        <url>https://dl.bintray.com/pika-lab/tuprolog/</url>
    </repository>
</repositories>

and then declare the desired dependency:

<dependency>
   <groupId>it.unibo.tuprolog</groupId>
   <artifactId>2P_MODULE</artifactId>
   <version>2P_VERSION</version>
</dependency>

Notice that dependencies of 2P_MODULE should be automatically imported.

Developers

Working with the 2P-Kt codebase requires a number of tools to be installed and properly configured on your system:

  • JDK 12+ (please ensure the JAVA_HOME environment variable is properly) configured
  • Kotlin 1.3.70+
  • Gradle 6.2+ (please ensure the GRADLE_HOME environment variable is properly configured)
  • Git 2.20+

Develop 2P-Kt with IntelliJ Idea

To participate in the development of 2P-Kt, we suggest the IntelliJ Idea IDE. The free, Community version will be fine.

You will need the Kotlin plugin for IntelliJ Idea. This is usually installed upon Idea's very first setup wizard. However, one may easily late-install such plugin through the IDE's Plugins settings dialog. To open such dialog, use Ctrl+Shift+A, then search for "Plugins"

Importing the project

  1. Clone this repository in a folder of your preference using git clone appropriately

  2. Open IntellJ Idea. If a project opens automatically, select "Close project". You should be on the welcome screen of IntelliJ idea, with an aspect similar to this image: IntelliJ Welcome Screen

  3. Select "Import Project"

  4. Navigate your file system and find the folder where you cloned the repository. Do not select it. Open the folder, and you should find a lowercase 2p-in-kotlin folder. That is the correct project folder, created by git in case you cloned without specifying a different folder name. Once the correct folder has been selected, click Ok

  5. Select "Import Project from external model"

  6. Make sure "Gradle" is selected as external model tool

  7. Click Finish

  8. If prompted to override any .idea file, try to answer No. It's possible that IntelliJ refuses to proceed, in which case click Finish again, then select Yes

  9. A dialog stating that "IntelliJ IDEA found a Gradle build script" may appear, in such case answer Import Gradle Project

  10. Wait for the IDE to import the project from Gradle. The process may take several minutes, due to the amount of dependencies. Should the synchronization fail, make sure that the IDE's Gradle is configured correctly:

  11. In 'Settings -> Build, Execution, Deployment -> Build Tools > Gradle', for the option 'Use Gradle from' select 'gradle-wrapper.properties file'. Enabling auto-import is also recommended

Developing the project

Contributions to this project are welcome. Just some rules:

  • We use git flow, so if you write new features, please do so in a separate feature/ branch

  • We recommend forking the project, developing your stuff, then contributing back via pull request directly from the Web interface

  • Commit often. Do not throw pull requests with a single giant commit adding or changing the whole world. Split it in multiple commits and request a merge to the mainline often

  • Stay in sync with the develop branch: pull often from develop (if the build passes), so that you don't diverge too much from the main development line

  • Do not introduce low quality or untested code. Merge requests will be reviewed before merge.

Building the project

While developing, you can rely on IntelliJ to build the project, it will generally do a very good job. If you want to generate the artifacts, you can rely on Gradle. Just point a terminal on the project's root and issue

./gradlew build

This will trigger the creation of the artifacts the executions of the tests, the generation of the documentation and of the project reports.

Versioning

The 2P project leverages on Semantic Versioning (SemVer, henceforth).

In particular, SemVer is enforced by the current Gradle configuration, which features DanySK's Git sensitive SemVer Gradle Plugin. This implies it is strictly forbidden in this project to create tags whose label is not a valid SemVar string.

Notice that the 2P project is still in its initial development stage---as proven by the major number equal to 0 in its version string. According to SemVer, this implies anything may change at any time, as the public API should not be considered stable.

Issue tracking

If you meet some problem in using or developing 2P, you are encouraged to signal it through the project "Issues" section on GitLab.