【发布时间】:2026-02-16 08:20:10
【问题描述】:
我有一个 Tera Byte 大文件。我想将它从nt转换为n3。这样做的原因是,我有一个大文件,由于附加的命名空间而占用了大量空间:
# <1>
<file:///home//uniprot/uniprot.rdf> <http://www.w3.org/2002/07/owl#imports> <http://purl.uniprot.org/core/> .
# <2>
<http://purl.uniprot.org/uniprot/Q6GZX4> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.uniprot.org/core/Protein> .
# <3>
<http://purl.uniprot.org/uniprot/Q6GZX4> <http://purl.uniprot.org/core/reviewed> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
现在我想以压缩形式有效地存储这个文件:
@fileuniprot: <file:///home//uniprot/>.
@owl: <http://www.w3.org/2002/07/owl#>.
@purlUniprot: <http://purl.uniprot.org/>.
@rdfs: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@xsd: <http://www.w3.org/2001/XMLSchema#>.
@xsd:
# <1>
fileuniprot:uniprot.rdf owl:imports purlUniprot:core .
# <2>
purlUniprot:uniprot/Q6GZX4 rdfs:type purlUniprot:core/Protein .
# <3>
purlUniprot:Q6GZX4 purlUniprot:core/reviewed "true"^^ xsd:boolean .
即我不希望命名空间附加相应的三元组。虽然我想保留cmets。有没有可能这样做。如果是,那么有人可以建议一个有效的工具来做同样的事情。
如果我能在 python 或 java 中找到一些适用于 linux 的工具,那就太好了? 以上都是手动完成的,如果能自动转换就好了。
【问题讨论】:
-
你真的只是一个字符串 => 字符串映射。其实很简单的东西。由于您将
<http://www.w3.org/2002/07/owl#imports>映射到<imports>和<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>到<type> -
如果 xml 中除了简单的字符串转换之外还有其他更改,您可以使用
XSLT transformer和SAX parser。也看看这个问题:*.com/questions/2773733/… -
@Cruncher 实际上我必须找到常见的模式然后替换它们。有什么方法可以让我找到常见的模式并以编程方式替换它们
-
这似乎是文本压缩通常可以很好地处理的那种转换。您可以根据需要使用 gzip 和 zcat 吗?
-
@loopasam,是的,但我回答了下面的问题;)
标签: java python linux semantics semantic-web