gpt4 book ai didi

python - 在 python 中将 Notation3 文件序列化为 RDFXML 格式时出错

转载 作者:行者123 更新时间:2023-11-28 22:54:48 25 4
gpt4 key购买 nike

所以我有一个如下所示的 Notation3 文件:

@prefix wn: <http://www.w3.org/2006/03/wn/wn20/instances/> .
@prefix lemon: <http://www.monnet-project.eu/#> .
@prefix lexinfo: <http://www.lexinfo.net/ontology#> .

:lexicon a lemon:Lexicon ;
lemon:language "it" ;
lemon:entry :fifa.

:fifa a lemon:LexicalEntry ;
lemon:canonicalForm [ lemon:writtenRep "fifa"@it ] ;
lemon:sense [ lemon:reference wn:synset-fear-noun-1 ];
lexinfo:partOfSpeech lexinfo:noun .

我正在尝试将其输入 RDFlib Graph 并使用以下代码将其序列化为 RDFxml 文件:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import rdflib
from rdflib import URIRef, Graph, Namespace
from rdflib.plugins.parsers.notation3 import N3Parser

g = Graph()
result = g.parse(file=open("lemon_example_fear.txt", "r"), format="text/n3")
print (g.serialize(format='xml'))

但目前我收到此错误:

rdflib.plugins.parsers.notation3.BadSyntax: at line 5 of <>:
Bad syntax (Prefix ":" not bound) at ^ in:
"... lexinfo: <http://www.lexinfo.net/ontology/2.0/lexinfo#> .

^:lexicon a lemon:Lexicon ;
lemon:language "it" ;
lem..."

这是我尝试序列化的文件或我用来执行此操作的代码的问题吗?

最佳答案

补充一下@jsalonen 所说的,未绑定(bind)前缀不是留给解析器的,而是specification。陈述如下:

The empty prefix "" is by default , bound to "#" -- the local namespace of the file. The parser behaves as though there were a

@prefix : <#>.

因此,未绑定(bind)前缀的确切解析将取决于解析器认为文件的本地 namespace 的内容,因此解析器之间的行为不同。

请注意,在更标准的格式中,如 Turtle这不适用,未绑定(bind)的前缀将始终导致错误。

一般来说,不定义所有前缀或使用任何 RDF 格式的相对 URI 是一个坏主意,因为您将受制于特定实现的 URI 解析行为,如前所述,不同序列化可能会有所不同。

关于python - 在 python 中将 Notation3 文件序列化为 RDFXML 格式时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17616463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com