-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdf_void_annotation.pl
43 lines (34 loc) · 2.27 KB
/
rdf_void_annotation.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!usr/bin/perl
# Perl script to annotate a RDF/TTL dataset using VoID, the W3C Vocabulary of Interlinked Datasets (https://www.w3.org/TR/void/)
# Requires following libraries:
# Log:Log4perl https://metacpan.org/pod/RDF::Log4perl (might require --force for installation)
# RDF::Trine https://metacpan.org/pod/RDF::Trine
# RDF::Generator::Void https://metacpan.org/pod/RDF::Generator::Void
# Run script in shell / command line as follows:
# perl rdf_void_annotation.pl <input file> <output file>
# where
# <input file> = the RDF file that should be annotated using VoID
# <output file> = file where the RDF VoID dataset should be saved. Script output is in RDF/Turtle syntax.
# e.g.
# perl rdf_void_annotation.pl data.ttl data_void.ttl
# imports
use RDF::Generator::Void;
use RDF::Trine;
use FileHandle;
# variables
my ($filename, $void_filename) = @ARGV;
my $base_uri = "https://w3id.org/idsa/core/"; # Prefix of IDS Information Model.
# read rdf data
my $model = RDF::Trine::Model->new(); # Generate empty RDF::Trine "model" object.
RDF::Trine::Parser->parse_file_into_model($base_uri, $filename, $model ); # Instantiate parser and parse InfoModel from file (auto-detects serialization).
print $model->size . " RDF statements parsed\n"; # Count and print parsed RDF statements.
# transform
my $generator = RDF::Generator::Void->new(inmodel => $model); # Instantiate VoID Generator and read Information Model.
$generator->urispace($base_uri); # Set URI Space.
my $voidmodel = $generator->generate; # Generate VoID model.
print $voidmodel->size . " RDF statements parsed\n"; # Count VoID statements.
# save
my $serializer = RDF::Trine::Serializer::Turtle->new(); # Instantiate Turtle Serializer.
open($fh, '>', $void_filename) or die $!; # Open filename to save results.
$serializer->serialize_model_to_file($fh, $voidmodel); # Write VoID results to file.
close($fh); # Close file.