| 1 | # Python bindings for FaCT++ reasoner |
| 2 | |
| 3 | [](https://doi.org/10.5281/zenodo.7693502) |
| 4 | [](https://pypi.org/project/pyfactxx) |
| 5 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Ftilde-lab%2Fpyfactxx?ref=badge_shield) |
| 6 | |
| 7 | FaCT++ is a well-optimized [open-source](https://bitbucket.org/dtsarkov/factplusplus) reasoner for **_SROIQ(D)_** description logic with simple datatypes (OWL 2), written in C++. FaCT++ was created in 2003-2015 by [Dmitry Tsarkov](https://scholar.google.com/citations?user=jDcQ7vQAAAAJ) and [Ian Horrocks](https://scholar.google.com/citations?user=0ypdmcYAAAAJ) in the University of Manchester, UK. |
| 8 | |
| 9 | The `pyfactxx` links the FaCT++ reasoner to the Python's [RDFLib](https://rdflib.dev) package. The code is based on the works of Artur Wroblewski: [factpp](https://bitbucket.org/wrobell/factplusplus/src/factpp/factpp) and [coras](https://bitbucket.org/wrobell/coras) interfaces. |
| 10 | |
| 11 | |
| 12 | ## Reasoner details |
| 13 | |
| 14 | The FaCT++ implements the [atomic decomposition algorithms](http://ceur-ws.org/Vol-1080/owled2013_13.pdf) (_i.e._ represents the ontologies as terse directed acyclic graphs). A [tableaux decision procedure](http://www.cs.ox.ac.uk/ian.horrocks/Publications/download/2007/HoSa07a.pdf) is applied for **_SROIQ(D)_** together with the set of [optimisation heuristics](https://doi.org/10.1007/11814771_26), such as: |
| 15 | |
| 16 | - lexical normalisation and simplification, |
| 17 | - synonym replacement, |
| 18 | - rewriting absorption, |
| 19 | - told cycle elimination, |
| 20 | - dependency-directed backtracking (backjumping), |
| 21 | - boolean constant propagation, |
| 22 | - semantic branching, |
| 23 | - ordering heuristics, |
| 24 | - model merging, |
| 25 | - completely defined concepts, |
| 26 | - clustering for wide and shallow taxonomies. |
| 27 | |
| 28 | To tackle the OWL 2 computational complexity (double exponential in time for the worst case), the FaCT++ presents [persistent and incremental reasoning](http://ceur-ws.org/Vol-1207/paper_7.pdf). In the persistent mode, FaCT++ saves the inferred information together with its internal state into a file, which can be reloaded later with much less computational effort than reasoning would require. In the incremental mode, FaCT++ determines which parts of the precomputed inferences may be affected by an incoming change and only recomputes a subset of the inferences. |
| 29 | |
| 30 | The mentioned above allows to achieve a very good performance on such known ontologies as **FHKB**, **SNOMED CT**, and **Thesaurus**. |
| 31 | |
| 32 | Apart of our present work, the FaCT++ supports [Java OWL-API](https://github.com/owlcs/owlapi), Lisp API, and [DIG interface](http://dl.kr.org/dig/interface.html). It can also be [used in C](https://bitbucket.org/dtsarkov/factplusplus/src/master/FaCT++.C/test.c). There is also a [work of Levin and Cowell](https://doi.org/10.1186/s13326-015-0035-z) on C++ usage (unmaintained). |
| 33 | |
| 34 | |
| 35 | ## Reasoner optimizations for RDFLib |
| 36 | |
| 37 | The `pyfactxx` presents the following updates to FaCT++: |
| 38 | |
| 39 | - drastically improved individuals support (`precacheIndividuals`) |
| 40 | - unified access point allowing arbitrary SPARQL queries |
| 41 | - exposing all the required C++ interfaces to RDFLib via the `coras` interface |
| 42 | |
| 43 | |
| 44 | ## Installation |
| 45 | |
| 46 | `pip install pyfactxx` |
| 47 | |
| 48 | NB the PyPI releases plus wheels are done via GitHub action. |
| 49 | |
| 50 | |
| 51 | ## Usage |
| 52 | |
| 53 | See `examples` folder. In essense: |
| 54 | |
| 55 | ``` |
| 56 | from pyfactxx import coras |
| 57 | |
| 58 | crs = coras.Coras() |
| 59 | crs.load(ontology_file, format='turtle') |
| 60 | |
| 61 | crs.parse() |
| 62 | crs.realise() |
| 63 | |
| 64 | result = crs.query('SELECT ?a ?b ?c WHERE {?a ?b ?c}') |
| 65 | ``` |
| 66 | |
| 67 | |
| 68 | ## Authors of Python part |
| 69 | |
| 70 | - Artur Wroblewski |
| 71 | - Evgeny Blokhin |
| 72 | - Andrey Sobolev |
| 73 | - Ivan Rygaev |
| 74 | |
| 75 | |
| 76 | ## Authors of C++ part |
| 77 | |
| 78 | - Dmitry Tsarkov |
| 79 | - Ian Horrocks |
| 80 | - Ivan Rygaev |
| 81 | |
| 82 | |
| 83 | ## License |
| 84 | |
| 85 | - Kernel reasoner code: GNU LGPL 2.1 |
| 86 | - Coras Python interface: GNU GPL 3.0 |
| 87 | |
| 88 | |
| 89 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Ftilde-lab%2Fpyfactxx?ref=badge_large) |