1

I am new to rdf and triples and I am looking for a way to load some triples in a triple store. I have a dataframe with following columns.

    mesh_code                               skos_rel                                       MDR_code
0   <http://id.nlm.nih.gov/mesh/D000012>    <http://www.w3.org/2004/02/skos/core#exactMatch>    <https://identifiers.org/meddra:10083851>
1   <http://id.nlm.nih.gov/mesh/D000026>    <http://www.w3.org/2004/02/skos/core#exactMatch>    <https://identifiers.org/meddra:10062935>
2   <http://id.nlm.nih.gov/mesh/D000030>    <http://www.w3.org/2004/02/skos/core#exactMatch>    <https://identifiers.org/meddra:10000230>
3   <http://id.nlm.nih.gov/mesh/D000038>    <http://www.w3.org/2004/02/skos/core#exactMatch>    <https://identifiers.org/meddra:10000269>
4   <http://id.nlm.nih.gov/mesh/D015823>    <http://www.w3.org/2004/02/skos/core#exactMatch>    <https://identifiers.org/meddra:10069408>

Is there a way to convert this dataframe to a turtle format, that can be loaded into a triple store like Blazegraph.

Any help is highly appreciated.

rshar
  • 1,381
  • 10
  • 28

1 Answers1

0

Try this library:

pip install rdfpandas

Then run:

from rdfpandas.graph import to_graph
import pandas as pd
import rdflib

df = pd.read_csv('to_graph_test.csv', index_col = '@id', keep_default_na = False)
namespace_manager = NamespaceManager(Graph())
namespace_manager.bind('skos', SKOS)
namespace_manager.bind('rdfpandas', Namespace('http://github.com/cadmiumkitty/rdfpandas/'))

g = to_graph(df, namespace_manager)
s = g.serialize(format = 'turtle')

See the docs here: https://github.com/cadmiumkitty/rdfpandas

Amrit Baveja
  • 528
  • 7
  • 13