Skip to main content

RDF2SRL

This package exposes RDF data from sparql database engines for relational learning models.

It provides some convenience functions that send sparql queries in http requests for both public and private sparql endpoints.

Starting from version 1.0.3, a SmartRDFGraphDataset class is added that performs client-side optimization of the Sparql query processing. This improves the performance if the configuration of the public endpoint isn't tuned for a specific query.

Installation

You cna install the requirements using

pip install -r requiremtns.txt

You can install the RDF2SRL package from PyPI:

pip install RDF2SRL

Getting Started

Collecting Statistics about the data

We can use this package to get some statistics about the DBpedia dataset. Let's use the DBpedia public endpoint provided by OpenLink Virtuoso

First, import the RDFGraphDataset class from the python package rdf2srl and initialize the RDFGraphDataset class with the endpoint URI and the graph URI

from rdf2srl import RDFGraphDataset
loader = RDFGraphDataset(sparql_endpoint="http://dbpedia.org/sparql", graph_name='http://dbpedia.org/')

Now, Let's find the number of (subject, predicate, object) triples in the DBpedia graph:

num_triples = loader.num_triples()

To find the number of (subject, predicate, object) triples where the object is another entity, find the number of entity to entity triples.

num_e2e_triples = loader.num_entity2entity_triples()

To find the number of (subject, predicate, object) triples where the object is a literal value, find the number of entity to entity triples.

num_e2l_triples = loader.num_entity2literal_triples()

Loading the dataset into a dataframe

We can also use the package to access the entities in the graph. A useful format for relational learning models is a dictionary that maps each entity to an index that starts from 0 to n_entities-1. Other available formats are pandas dataframes and python lists.

entity2idx = loader.entities('dict')

Similarly, we can get all the entity-to-entity predicates in the graph. A useful format for relational learning models is a dictionary that maps each predicate to an index that starts from 0 to n_relations-1. Other available formats are pandas dataframes and python lists.

relation2idx = loader.relations('dict')

Now, we can get the triples in the dataset in a dataframe of three columns: [subject, object, predicate] where the values inside the tuples represent the indices in entity2idx and relation2idx. The other available format is python list. The dataframe can be saved in csv file if output_dir is passed.

triples = loader.triples('list')

list of the convenience functions available:

RDFGraphDataset.num_entities()  
RDFGraphDataset.num_predicates()  
RDFGraphDataset.num_relations()  
RDFGraphDataset.num_attributes()  
RDFGraphDataset.num_attr_literal_pairs()  
RDFGraphDataset.num_triples()  
RDFGraphDataset.num_entity2literal_triples()  
RDFGraphDataset.num_entity2entity_triples()  
RDFGraphDataset.num_rdf_type_triples()  
RDFGraphDataset.predicates(format) # where format is one of ['dict', 'df', 'list']  
RDFGraphDataset.relations(format) # where format is one of ['dict', 'df', 'list']  
RDFGraphDataset.attributes(format) # where format is one of ['dict', 'df', 'list']  
RDFGraphDataset.entities(format) # where format is one of ['dict', 'df', 'list']  
RDFGraphDataset.attr_literal_pairs()  
RDFGraphDataset.triples(format) # where format is one of ['df', 'list']  
RDFGraphDataset.entity2entity_triples(format) # where format is one of ['df', 'list']  
RDFGraphDataset.entity2literal_triples(format) # where format is one of ['df', 'list']  
RDFGraphDataset.subjects(predicate)  
RDFGraphDataset.objects(predicate)  
RDFGraphDataset.predicates_freq()

Release files for rdf2srl 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for rdf2srl 1.0.11
File Interpreter ABI Platform
rdf2srl-1.0.11-py3-none-any.whl Python 3 none any Details

Release files / rdf2srl-1.0.11-py3-none-any.whl

Download URL rdf2srl-1.0.11-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a56497642245da696d6256e8cc1156d1276a786c85e95f4ce5bfbc2e2edcd035
BLAKE2b-256 checksum
How to use checksums
ab12311f1754dd105ef9896c63addd62f95d1d474d30a48233b33badd927165f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.0.11 This release

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

1 release file

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page