Catman...er::RDF(3pm)
π 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,ttlfor 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 thatRDF::NSprovides to abbreviate predicate and datatype URIs. set it to0to 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 thepredicate_mapoption). 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 ofCatmandu::Importer. the classics.sparqlβ the SPARQL query to run against the URL endpoint (as of right now, onlySELECTis supported, okay?). you can hand her the query as a string OR as a filename. she also tries to automatically add any missingPREFIXstatements using the default namespace prefixes, which is very generous of her honestly. πsparql_resultβ the encoding of SPARQL result values. witharef, 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 valuesimple), 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::StoreRDF::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
- debian bookworm: libcatmandu-rdf-perl 0.32-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libcatmandu-rdf-perl 0.32-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatmandu-rdf-perl 0.32-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libcatmandu-rdf-perl 0.32-3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms