我有一行我想要製作成N3格式的文本,因此我最終可以將它們更改爲RDF。文本文件的每一行都有這樣的條目:爲RDF中的WordNet數據選擇命名空間前綴
09827177 18 N 03貴族0 blue_blood 0 0貴族@ 013ñ09646208 0000#M 08404938ň0000 + 01594891一0306 + 01594891 0102一〜09860027ň0000〜 09892248 n 0000〜10103592 n 0000〜10194721 n 0000〜10304832 n 0000〜10492384 n 0000〜10493649 n 0000〜10525325 n 0000〜10526235 n 0000 |貴族的成員
我想使上述語句變成三元組,以便它們看起來像下表。
Subject Predicate Object
(synset_offset)
09807754 lex_filenum 18
09807754 ss_type n
09807754 lexical_entry aristocrat
09807754 lexical_entry blue_blood
09807754 lexical_entry patrician
09807754 has_pointer 09623038
09623038 ss_type n
09623038 source_target 0000
09807754 description a member of aristocracy
我已經能夠使用從每行文本讀取大多數的變量是:
f = open("wordnetSample.txt", "r")
for line in f:
L = line.split()
L2 = line.split('|')
synset_offset = L[0]
lex_filenum = L[1]
ss_type = L[2]
word = (L[4:4 + 2 * int(L[3]):2])
gloss = (L2[1].split('\n')[0])
我遇到的問題是,我不知道什麼名稱空間使用或類似的東西。我對這種格式化和一般的python很陌生。我一直在研究,覺得它應該是這樣的:
'''<http://example.org/#'''+synset_offset+'''> <http://xmlns.com/foaf/0.1/lex_filenum> '''+lex_filenum+''' .
我也被告知,烏龜符號可能是一個更好的選擇,但我不能讓我的頭周圍。
您的問題的第一行,「我有一行文本,我想成爲N3格式,所以我最終可以將它們更改爲RDF,」對我來說沒有意義。 N3是一種RDF序列化格式。一個N3文檔_is_ RDF。 –