开发者

SWI-Prolog: how to load rdf triples using semweb/rdf_db library?

开发者 https://www.devze.com 2022-12-30 23:42 出处:网络
I have a rdf file (file.trp) in n-triples format, where each line is a well-formed triple: \"subject predicate obj开发者_运维问答ect .\"

I have a rdf file (file.trp) in n-triples format, where each line is a well-formed triple:

"subject predicate obj开发者_运维问答ect ."

I tried to use rdf_load in semweb/rdf_db to load it into memory, but failed. Here is what I tried:

?- rdf_load('file.trp').

?- rdf_load('file.trp', [format(triples)]).

The trace shows that the goal fails at:

rdf_db:rdf_load_stream/3

which calls

rdf_load_db_/3

which is probably defined in a foreign library.

the manual says it supports xml and triples. But it only loads rdf xml files. How can I load such rdf triple file?

Thanks, Li


The library(semweb/rdf_db) can be extended with several plugins to support additional inputs (URLs, compressed, different triple formats). Notably:

  • Loading library(semweb/rdf_turtle) makes it read .ttl (Turtle)
  • Loading library(semweb/rdf_zlib_plugin) makes it process .gz files (compressed)
  • Loading library(semweb/rdf_http_plugin) makes it load from http:// URLs
  • Loading library(semweb/rdf_ntriples) makes it load the ntriples format (this is only provided with the latest development version; 6.3.8).


The manual suggests that the predicate rdf_load/2 supports either the RDF/XML or, it's 'internal quick load and cache format', which is probably not the n-triples format.

Firstly, you'll need to import the following to make use of this predicate anyhow:

:- use_module(library(semweb/rdf_db)).

Secondly, I think you'll need to convert your triples into an appropriate format which is readable by this predicate, such as RDF/XML, and use the call like this:

 rdf_load('file.xml', [format(xml)]).

You can use this online converter for converting between n-triples and RDF/XML format (amongst others).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号