2017-04-20 76 views
1

我需要使用rdflib将csv文件转换为rdf,我已经有了读取csv的代码,但我不知道如何将其转换为rdf。使用csv文件作为输入创建RDF文件

我有以下代码:

import csv 
from rdflib.graph import Graph 

# Open the input file 
with open('data.csv', 'rb') as fcsv: 
    g = Graph() 
    csvreader = csv.reader(fcsv) 
    y = True 
    for row in csvreader: 
     if y: 
      names = row 
      y = False 
     else: 
      for i in range(len(row)): 
       continue 
    print(g.serialize(format='xml')) 
    fcsv.close() 

有人能解释一下,给我一个例子吗?

+0

欢迎SO “为半自动CSV转换成RDF一个命令行工具”!你应该包括你已经有的为他人建立并帮助你 – ted

+0

你知道ref格式吗? – DrBwts

+0

我将使用xml格式 – sanandresm

回答

1

有一个在rdflib/rdflib/tools/csv2rdf.py

csv2rdf.py \ 
-b <instance-base> \ 
-p <property-base> \ 
[-D <default>] \ 
[-c <classname>] \ 
[-i <identity column(s)>] \ 
[-l <label columns>] \ 
[-s <N>] [-o <output>] \ 
[-f configfile] \ 
[--col<N> <colspec>] \ 
[--prop<N> <property>] \ 
<[-d <delim>] \ 
[-C] [files...]"