Catman...er::RDF(3pm)

πŸ“¦
version 0.32 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

πŸ’– Catmandu::Importer::RDF πŸ’–

okay bestie, listen up, because this one is genuinely iconic. we're talking about Catmandu::Importer::RDF, a Perl module that lives in the User Contributed Perl Documentation (that's the 3pm section, iykyk) and its whole entire job is parsing RDF data. yes. RDF data. she's a whole vibe and she knows it. πŸ¦‹


✨ NAME ✨

Catmandu::Importer::RDF β€” parse RDF data. that's it, that's the name, no notes. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

so there's a command line client called catmandu and honestly? she eats. here's how you'd use her:

catmandu convert RDF --url http://d-nb.info/gnd/4151473-7 to YAML

catmandu convert RDF --file rdfdump.ttl to JSON

# Parse the input into on JSON document per triplet. This is the
# most memory efficient (and fastest) way to parse RDF input.
catmandu convert RDF --triples 1 --file rdfdump.ttl to JSON

# Transform back into NTriples (conversions to and from triples is the
# most efficient way to process RDF)
catmandu convert RDF --triples 1 --file rdfdump.ttl to RDF --type NTriples

# Query a SPARQL endpoint
catmandu convert RDF --url http://dbpedia.org/sparql
                     --sparql "SELECT ?film WHERE { ?film dct:subject <http://dbpedia.org/resource/Category:French_films> }"

catmandu convert RDF --url http://example.org/sparql --sparql query.rq

# Query a Linked Data Fragment endpoint
catmandu convert RDF --url http://fragments.dbpedia.org/2014/en
                     --sparql "SELECT ?film WHERE { ?film dct:subject <http://dbpedia.org/resource/Category:French_films> }"

and if you're doing it in Perl code, because you're a main character who writes actual code:

use Catmandu::Importer::RDF;
my $url = "http://dx.doi.org/10.2474/trol.7.147";
my $rdf = Catmandu::Importer::RDF->new( url => $url )->first;

periodt. πŸ’…


🌸 DESCRIPTION 🌸

the way that this Catmandu::Importer can just... import RDF data from literally everywhere? URLs, files, input streams, SPARQL endpoints, AND Linked Data Fragment endpoints. she contains multitudes fr fr. 🫢

and by default, an RDF graph gets imported as a single item in aREF format (go look at RDF::aREF if you wanna know more, bestie, I'm not gonna gatekeep).


πŸ‘‘ CONFIGURATION πŸ‘‘

here's every single knob you can turn. all of them. no skips, no skimming, we respect the config here. ⭐

  • url β€” the URL you're retrieving your RDF from. simple as that.
  • type β€” the RDF serialization type (so like, ttl for RDF/Turtle, that kinda thing).
  • base β€” the base URL. if you don't set it, she derives it from the URL or the file name all by herself. independent queen.
  • ns β€” uses the default namespace prefixes that RDF::NS provides to abbreviate predicate and datatype URIs. set it to 0 to turn off URI abbreviating entirely. set it to a specific date if you want stable namespace prefix mappings. iykyk.
  • triples β€” imports each RDF triple as one aREF subject map (that's the default) or a predicate map (if you turn on the predicate_map option). this is THE most efficient way to process big input files, because all the processing can be streamed. slay.
  • predicate_map β€” imports RDF as an aREF predicate map, if possible. if possible!! 🫠
  • file, fh, encoding, fix β€” the default configuration options of Catmandu::Importer. the classics.
  • sparql β€” the SPARQL query to run against the URL endpoint (as of right now, only SELECT is supported, okay?). you can hand her the query as a string OR as a filename. she also tries to automatically add any missing PREFIX statements using the default namespace prefixes, which is very generous of her honestly. πŸ‘‘
  • sparql_result β€” the encoding of SPARQL result values. with aref, query results get encoded in aREF format, with URIs wrapped in < and > (no qNames) and literal nodes appended with @ plus an optional language code. by default (that's the value simple), all RDF nodes get simplfied down to their literal form.
  • cache β€” set this to a true value and she'll cache repeated URL responses in a CHI based backend. obsessed.
  • cache_options β€” gives you the CHI based options for caching result sets. by default a memory store of 1MB size is used, which is exactly equal to this:
Catamandu::Importer::RDF->new( ...,
    cache => 1,
    cache_options => {
        driver => 'Memory',
        global => 1,
        max_size => 1024*1024
    });
  • speed β€” set this to a true value and she writes the RDF file processing speed to the STDERR as the number of triples parsed per second. little performance report, as a treat. πŸ”₯

⭐ METHODS ⭐

go look at Catmandu::Importer. that's the whole thing. I said what I said. πŸ’œ


🌈 SEE ALSO 🌈

  • RDF::Trine::Store
  • RDF::Trine::Parser

okay that's the whole page bestie, you made it, I'm so proud of you. πŸŽ€ this beauty ships as perl v5.36.0, dated 2022-12-06 β€” and yeah, the header up top calls her Catman...er::RDF(3pm) because apparently we ran out of room, but you and me both know her full government name. go parse some RDF. slay πŸ’–βœ¨

πŸ“¦ where this page comes from