我是 rdf 和三元组的新手,我正在寻找一种在三元组存储中加载一些三元组的方法。我有一个包含以下列的数据框。
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>
有没有办法将此数据框转换为海龟格式,可以将其加载到像 Blazegraph 这样的三元组存储中。
非常感谢任何帮助。
试试这个库:
pip install rdfpandas
然后运行:
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')