Skip to content

IBM/kif

Repository files navigation

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, FactGrid, PubChem, and UniProt, among others. New 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).

KIF CLI

kif filter -s wikidata --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)))

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('wikidata', '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)
Counts the number of species (Q7432) in UniProt.

KIF CLI

$ kif count -s uniprot --select s --property=wd.taxon_rank --value=wd.species

2182677

KIF API

# Create a SPARQL store loaded with UniProt mappings.
kb = Store('uniprot', 'https://sparql.uniprot.org/sparql')

# Count the number of distinct subjects of statements with the given property and value.
n = kb.count_s(property=wd.taxon_rank, value=wd.species)
print(n)
Gets from Wikidata and PubChem the IRI and molecular mass of all chemicals whose formula is H₂O.

KIF CLI

$ kif filter -s wikidata -s pubchem --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

KIF API

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

kb = Store('mixer', [
    Store('wikidata', 'https://query.wikidata.org/sparql'),
    Store('pubchem', '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. 2024. "KIF: A Wikidata-Based Framework for Integrating Heterogeneous Knowledge Sources", arXiv:2403.10304, 2024.

Related Papers

Marcelo Machado, João P. P. Campos, Guilherme Lima, Viviane T. da Silva. 2025. "KIF-QA: Using Off-the-shelf LLMs to Answer Simple Questions over Heterogeneous Knowledge Bases". In Proc. 5th Wikidata Workshop co-located with the 24th Semantic Web Conference (ISWC 2025), Nara, Japan, November 2-6, 2025. (To be published)

Marcelo Machado, João M. B. Rodrigues, Guilherme Lima, Sandro R. Fiorini, Viviane T. da Silva. 2024. "LLM Store: Leveraging Large Language Models as Sources of Wikidata-Structured Knowledge". In Joint Proc. 2nd Workshop on Knowledge Base Construction from Pre-Trained Language Models (KBC-LM 2024) and the 3rd Challenge on Language Models for Knowledge Base Construction (LM-KBC 2024) co-located with the 23nd International Semantic Web Conference (ISWC 2024), Baltimore, USA, November 12, 2024. (Best paper)

License

Released under the Apache-2.0 license.

About

A knowledge integration framework based on Wikidata

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages