Skip to content

IBM/kif

Repository files navigation

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.

About

A Wikidata-based framework for integrating knowledge sources

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages