Skip to main content

pyDBpedia is a simple python wrapper for querying dbpedia

Project description

pyDBpedia

Installation

Can easily install using pip

pip install pydbpedia

Usage

A simple python package to query dbpedia without the need to use sparql query language.

You will need add the endpoint as an argument when initiating the class PyDBpedia.

from pydbpedia import PyDBpedia, namespace

dbpedia_uris = ["http://dbpedia.org/resource/Manchester_United_F.C.", "http://dbpedia.org/resource/Albert_Einstein"]

dbpedia_wrapper = PyDBpedia(endpoint="http://dbpedia.org/sparql")
objects = dbpedia_wrapper.get_objects(subjects=dbpedia_uris, predicates=[namespace.RDF_TYPE])

Currently there are only two main functions which both take the same input parameters:

  • subjects: list of DBpedia URIs
  • predicates: list of predicates

Both Functions query DBpedia and return the results of the query given the subjects and predicates:

  • get_objects(subjects, predicates, **kwarg): Returns a list of simplified (without the DBpedia URI) DBpedia entities, for example [Norway, Sweden].
  • get_subject_object_tuples(subjects, predicates, **kwarg): Returns a list of format [(subject, object),...] where subject and object are simplified DBpedia entities, for example [(Sweden, Stockholm), (Norway, Oslo)].

Additionally there is a possibilty to input filters to the two functions. The filters are set by sending them as additional input parameters. Currently there are three filters:

  • redirect: Not really a filter but it will get the objects of the redirected resource. This is good to use when the resource is redirected and you still want to get the objects. For example: get_objeccts(subjects=[http://dbpedia.org/resource/Man_U], predicate=[predicate], redirect=True) will return the objects for the resource http://dbpedia.org/resource/Manchester_United_F.C. since it will be redirected to that.
  • contains: Used to filter the objects of the query if they contain the inputed string. For example: get_objects(subjects=[uri],predicates=[predicate],contains='http://dbpedia.org/Ontology/')' will only return objects which are part of the dbpedia ontology (meaning that they contain http://dbpedia.org/Ontology/.
  • in_list: To filter the objects of the query if they match any items in a list. For example: get_subject_object_tuples(subjects=[uri],predicates=[predicate],in_list=['London'])' will only return all the cases where the objects are London.

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

pydbpedia-0.0.3.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file pydbpedia-0.0.3.tar.gz.

File metadata

  • Download URL: pydbpedia-0.0.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.6

File hashes

Hashes for pydbpedia-0.0.3.tar.gz
Algorithm Hash digest
SHA256 95019b44a5a8d95d50b79cb03104ebe9a178ede040a14785cf78b8ba07144fbb
MD5 6ac163bd079deb37c870ece658bf7a9e
BLAKE2b-256 c874ac8ee348c5710cea0228d1672c2e604e5baee78d48188710be89833a1bdc

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