Skip to main content

A knowledge integration framework based on Wikidata

Project description

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 for 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 and examples.

Hello world!


(1)

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)

(2)

Gets from Wikidata and PubChem RDF 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) (Quantity 20.01878893 (Item dalton))
(Item oxygen-15 atom) (Quantity 17.0187 (Item dalton))
(Item diprotium oxide) (Quantity 18.010564684 (Item 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)

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.10.0.tar.gz (403.1 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.10.0-py3-none-any.whl (456.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kif_lib-0.10.0.tar.gz
Algorithm Hash digest
SHA256 77d0ff51421149e289c461a6c1e475f4d07e325fe5820bcb7cfcc340dc31f7b8
MD5 853dab952e20fbd2c9dd560cca218edd
BLAKE2b-256 cc9814a064e8f0657ab7caa963fe1290f717b1668c1ebfbed900bf9b8a135562

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kif_lib-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98fb8116c939912ea5e5807eda3ea25e265c71e2edb51c2466fa4c3ea7a177c7
MD5 ed184fbc2ec6fa0c0a3d68c663a191ca
BLAKE2b-256 1c1e23f51fe278d6b4e289d6ae6193d8817c001e5c751a08c705958c361b4c91

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