File: aat_match.pm

package info (click to toggle)
libcatmandu-aat-perl 0.03-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: perl: 245; makefile: 10
file content (120 lines) | stat: -rw-r--r-- 2,259 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package Catmandu::Fix::aat_match;

use strict;
use warnings;

use Catmandu::Sane;
use Moo;

use Catmandu::Fix::Has;
use Catmandu::Fix::Datahub::Util qw(declare_source);

with 'Catmandu::Fix::Base';

has path    => (fix_arg => 1);
has lang    => (fix_opt => 1, default => sub { 'nl' });

sub emit {
    my ($self, $fixer) = @_;
    my $perl = '';

    $perl .= 'use Catmandu::AAT::API;';
    
    my $term = $fixer->generate_var();
    my $aat = $fixer->generate_var();

    $perl .= "my ${term};";
    $perl .= declare_source($fixer, $self->path, $term);

    $perl .= "my ${aat} = Catmandu::AAT::API->new(term => ${term}, language => '".$self->lang."');";

    $perl .= $fixer->emit_create_path(
        $fixer->var,
        $fixer->split_path($self->path),
        sub {
            my $root = shift;
            my $code = '';

            $code .= "${root} = ${aat}->match();";

            return $code;
        }
    );

    return $perl;
}

1;
__END__

=encoding utf-8

=head1 NAME

Catmandu::Fix::aat_match - Perform a direct match between a term and a Subject in the AAT

=head1 SYNOPSIS

  aat_match(
      path,
      -lang: nl
  )

=head1 DESCRIPTION

Perform a direct match between a term and the L<SPARQL endpoint|http://vocab.getty.edu/sparql> of the AAT.
This fix will attempt to find a I<Subject> for which the I<prefLabel> in I<lang> (optional, default C<nl>)
equals the term. Will return a single item if one is found, or an empty hash if none was found.

Returns the following data:

  {
    'id'        => 'The dc:identifier of the Subject',
    'prefLabel' => 'The prefLabel in the provided language',
    'uri'       => 'The URI of the Subject'
  }

=head2 PARAMETERS

=head3 Required parameters

=over

=item C<path>

Path to the term.

=back

=head3 Optional parameters

=over

=item C<lang>

Language of both the I<prefLabel> that is matched and the I<prefLabel> that is returned.

=back

=head1 AUTHOR

Pieter De Praetere E<lt>pieter at packed.be E<gt>

=head1 COPYRIGHT

Copyright 2017- PACKED vzw

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<Catmandu>
L<Catmandu::AAT>
L<Catmandu::Store::AAT>
L<Catmandu::Fix::aat_search>

=cut