LibreCat / Catmandu-RDF

Catmandu modules for working with RDF data
https://metacpan.org/release/Catmandu-RDF
Other
5 stars 6 forks source link

CSV export? #36

Open v4ss4llo opened 6 years ago

v4ss4llo commented 6 years ago

Is it possible convert from .nt to .csv? I get a weird result like this

HASH(0x55ee74412b10),HASH(0x55ee740a6c20),HASH(0x55ee743351f8),HASH(0x55ee751b0d18),HASH(0x55ee748990e8),HASH(0x55ee751b4388),HASH(0x55ee74a09d58),HASH(0x55ee752d7230),HASH(0x55ee7532d6c8),HASH(0x55ee74323d90),HASH(0x55ee751b0eb0),HASH(0x55ee741eb220),HASH(0x55ee752be238),HASH(0x55ee74a238e8),HASH(0x55ee7523afb0),HASH(0x55ee7529e570),HASH(0x55ee75153180),HASH(0x55ee752045b0),HASH(0x55ee74fa0f18),HASH(0x55ee7471ea68),HASH(0x55ee75176588),HASH(0x55ee74d83318),HASH(0x55ee752594b0),HASH(0x55ee7518e1b8),HASH(0x55ee748c5ae8),......
phochste commented 6 years ago

This is because you didn't provide any fix file how you would like to see RDF in CSV converted. By default NT files are imported into Catmandu as a deeply nested HASH.

But .nt files are very easy to parse. You could try this:

 $ catmandu convert Text to CSV --fix 'parse_text(text,"(?<s><\S+>)\s+(?<p><\S+>)\s+(?<o>.*)\s+\."); move_field(text,.)'< demo.nt > demo.csv
v4ss4llo commented 6 years ago

Can I suggest that you guys add a simpler command for this? Especially since RDF are easy to parse as you said, using convert Text to CSV --fix 'parse_text(text,"(?<s><\S+>)\s+(?<p><\S+>)\s+(?<o>.*)\s+\."); move_field(text,.)' is not handy at all...

phochste commented 6 years ago

TSV (tab delimited format) should be available by default in RDF::Trine but is not available due to a missing include and a bug in the output. See also:

https://github.com/kasei/perlrdf/issues/155

A pull request for RDF::Trine is on its way and with it you can do:

 $ catmandu convert RDF --type NTriples to RDF --type TSV < data.nt > data.csv
v4ss4llo commented 6 years ago

Looks cool. I'll leave this open until the PR is merged.