我目前正在尝试使用变量来创建N个三元组的图形,分配变量没有任何麻烦,但是我一直收到错误消息。这是代码:
from rdflib import Namespace, URIRef, Graph
from StringIO import StringIO
xmlns = "http://www.example.org/lexicon#"
rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
lemon = "http://www.monnetproject.eu/lemon#"
graph = Graph()
F = open("new_2.txt", "r")
for line in F:
这是我分配变量的部分。这是很长的时间,我知道它可以正常工作,所以我将不包括在内。以下代码仍是for line in F:
line1 = ''+synset_offset+'\rdf.lex_filenum\ '+lex_filenum+''
line2 = ''+synset_offset+'\lemon.ss_type\ '+ss_type+''
line3 = ''
for item in word:
line3 +=''+synset_offset+'\lemon.lexical_entry\ '+iw.next()+'/n'
line4 = ''+synset_offset+'\lemon.gloss\ '+gloss+''
line5 = ''
line6 = ''
line7 = ''
for item in S:
pointer = ip.next()
pos = iss.next()
source_target = ist.next()
line5 += ''+synset_offset+'\lemon.has_ptr\ '+pointer+'/n'
line6 += ''+pointer+'\lemon.pos\ '+pos+'/n'
line7 += ''+pointer+'\lemon.source_target\ '+source_target+'/n'
contents = '''\
'''+line1+'''
'''+line2+'''
'''+line3+'''
'''+line4+'''
'''+line5+'''
'''+line6+'''
'''+line7+''''''
tabfile = StringIO(contents)
for line in tabfile:
triple = line.split() # triple is now a list of 3 strings
triple = (URIRef(t) for t in triple) # we have to wrap them in URIRef
graph.add(triple)
print graph.serialize(format='nt')
慕村225694
相关分类