Skip to main content

A knowledge integration framework based on Wikidata

Project description

Supported Python Versions PyPI version Downloads

Knowledge Integration Framework

KIF is a knowledge integration framework from IBM Research.

It is based on Wikidata and licensed under the Apache-2.0 license.

First time here? Check out the quickstart guide.

Highlights

  • KIF is an interface to query knowledge sources as if they were Wikidata.

  • KIF queries are written as simple, high-level filters using entities of the Wikidata data model.

  • KIF can be used to query Wikidata itself or other knowledge sources, provided proper mappings are given.

  • KIF comes with built-in mappings for DBpedia and PubChem RDF. Other mappings can be added programmatically.

  • KIF has full support for asyncio. KIF async API can be used run queries asynchronously, without blocking waiting on their results.

Installation

Latest release:

$ pip install kif-lib

Development version:

$ pip install kif-lib@git+https://github.com/IBM/kif.git

Documentation

See documentation.

Examples

Click on the headings for details.

Gets from Wikidata all statements with property shares border with (P47) and value Brazil (Q155).

Using the kif command-line utility:

kif filter -s wdqs --property=wd.shares_border_with --value='wd.Q(155)'

(Statement (Item Argentina) (ValueSnak (Property shares border with) (Item Brazil)))
(Statement (Item Peru) (ValueSnak (Property shares border with) (Item Brazil)))
(Statement (Item Paraguay) (ValueSnak (Property shares border with) (Item Brazil)))

Using the KIF API:

from kif_lib import *               # import the KIF namespace
from kif_lib.vocabulary import wd   # import the Wikidata vocabulary module

# Create a SPARQL store loaded with Wikidata mappings and optimized for WDQS.
kb = Store('wdqs', 'https://query.wikidata.org/sparql')

# Filter all statements with the given property and value.
for stmt in kb.filter(property=wd.shares_border_with, value=wd.Q(155)):
    print(stmt)
Gets from Wikidata and PubChem the IRI and molecular mass of all chemicals whose formula is H₂O.

Using the kif command-line utility:

$ kif filter -s wdqs -s pubchem-sparql --select sv --subject='wd.chemical_formula("H₂O")' --property=wd.mass

(Item hydrogen tritium oxide) 20.01878893 dalton
(Item oxygen-15 atom) 17.0187 dalton
(Item diprotium oxide) 18.010564684 dalton

Using the KIF API:

# Create a mixer store combining:
# • wdqs: A SPARQL store loaded with Wikidata mappings optimized for WDQS.
# • pubchem-sparql: A SPARQL store loaded with PubChem RDF mappings.

kb = Store('mixer', [
    Store('wdqs', 'https://query.wikidata.org/sparql'),
    Store('pubchem-sparql', 'https://qlever.cs.uni-freiburg.de/api/pubchem')])

# Filter the subject and value (sv) of all statements where:
# • subject has chemical formula (P274) H₂O.
# • property is mass (P2067).

it = kb.filter_sv(subject=wd.chemical_formula('H₂O'), property=wd.mass)
for chem, mass in it:
    print(chem, mass)

See examples for more examples.

Citation

Guilherme Lima, João M. B. Rodrigues, Marcelo Machado, Elton Soares, Sandro R. Fiorini, Raphael Thiago, Leonardo G. Azevedo, Viviane T. da Silva, Renato Cerqueira. "KIF: A Wikidata-Based Framework for Integrating Heterogeneous Knowledge Sources", arXiv:2403.10304, 2024.

License

Released under the Apache-2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kif_lib-0.12.0.tar.gz (497.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kif_lib-0.12.0-py3-none-any.whl (566.1 kB view details)

Uploaded Python 3

File details

Details for the file kif_lib-0.12.0.tar.gz.

File metadata

  • Download URL: kif_lib-0.12.0.tar.gz
  • Upload date:
  • Size: 497.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for kif_lib-0.12.0.tar.gz
Algorithm Hash digest
SHA256 20b1d64a8fa26ff89701de440b9d39e869af8360f483a89269826b4f381c49ac
MD5 ed999ffcc51aef166850a41f1559d8fb
BLAKE2b-256 116a8d29ee1f7d1cb1b99b82c861c9b66fe0cee9260d05d28601969381be5a00

See more details on using hashes here.

File details

Details for the file kif_lib-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: kif_lib-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 566.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for kif_lib-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43fcdc2c67bf95c28dd82d312eb1fb76099d8248ccf10b02978ea10889eb1930
MD5 484cef45a6665d7c3d3a6e04b4f76a3c
BLAKE2b-256 3b98c9f7a1f18c869ff83332e602ea70a696374de35c2a6a968a47bf16315837

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page