#!/usr/local/bin/perl -w
use
lib
"/home/markw/CODE/DataFairPort/Libraries/Perl/FAIR/lib/"
;
my
$config
= {
title
=>
'Semantic PHI Base Metadata Server'
,
serviceTextualDescription
=>
'Provides a mechanical landing page for the Semantic PHI Base (Plant Division), repository-level metadata, and access points to individual records, following the W3C Linked Data Platform specification'
,
textualAccessibilityInfo
=>
"The information from this server requries no authentication; HTTP GET is sufficient"
,
mechanizedAccessibilityInfo
=>
""
,
textualLicenseInfo
=>
"CC-BY-ND 4.0"
,
ETAG_Base
=>
"TopLevelMetadata_Accessor_For_SemanticPHIBase"
,
localNamespaces
=> {
},
localMetadataElements
=> [
qw(hw:Greeting hw2:grusse)
],
basePATH
=>
'SemanticPHIBase/Metadata'
,
};
my
$service
= Metadata->new(
%$config
);
$service
->handle_requests;
sub
MetaContainer {
my
(
$self
,
%ARGS
) =
@_
;
my
$metadata
=
$self
->getRepositoryMetadata();
my
$BASE_URL
=
"http://"
.
$ENV
{
'SERVER_NAME'
} .
$ENV
{
'REQUEST_URI'
};
my
$query
= RDF::Query::Client
->new('
SELECT DISTINCT ?s
WHERE {
?s a PHIO:PHIBO_00022
}'
);
my
@known_records
;
while
(
my
$row
=
$iterator
->
next
) {
my
$URL
=
$row
->{s}->as_string;
$URL
=~ m
'/(INT_\d+)'
;
my
$ID
= $1;
push
@known_records
,
"$BASE_URL/$ID"
;
}
$metadata
->{
'void:entities'
} =
scalar
(
@known_records
);
$metadata
->{
'ldp:contains'
} = \
@known_records
;
return
encode_json(
$metadata
);
}
sub
Distributions {
my
(
$self
,
%ARGS
) =
@_
;
my
$ID
=
$ARGS
{
'ID'
};
my
%response
;
my
%formats
;
my
$query
= "
WHERE {
phi:
$ID
phio:has_unique_identifier ?o .
?o phio:has_value ?val }";
$query
= RDF::Query::Client->new(
$query
);
my
$row
=
$iterator
->
next
;
my
$accnumber
=
$row
->{val}->literal_value
if
$row
->{val};
$accnumber
=~ s/PHI\://;
return
encode_json(
%response
)
unless
$accnumber
;
my
$metadata
=
$self
->getDistributionMetadata(
$accnumber
);
my
$projections
;
my
$formats
;
(
$projections
,
$formats
) =
$self
->createTPFDistributions(\
%formats
,
$ID
)
if
$self
->can(
'createTPFDistributions'
);
$response
{distributions} =
$formats
;
$response
{metadata} =
$metadata
if
(
keys
%$metadata
);
my
$response
= encode_json(\
%response
);
return
(
$response
,
$projections
);
}
sub
getRepositoryMetadata {
my
%metadata
= (
'dc:title'
=>
"Semantic PHI Base Accessor"
,
'dcat:description'
=>
"FAIR Accessor server for the Semantic PHI Base. This server exposes the plant portion of the Pathogen Host Interaction database as Linked Data, following the FAIR Data Principles. This interface (the one you are reading) follows the W3C Linked Data Platform behaviors. The data provided here is an RDF transformation of data kindly provided by the researchers at PHI Base (doi:10.1093/nar/gku1165)"
,
'dcat:keyword'
=> [
"pathogenesis"
,
"plant/pathogen interactions"
,
"PHI Base"
,
"Semantic Web"
,
"Linked Data"
,
"FAIR Data"
,
"genetic database"
,
"phytopathology"
],
'daml:has-Technical-Lead'
=> [
"Dr. Alejandro Rodriguez Gonzalez"
,
"Alejandro Rodriguez Iglesias"
],
'daml:has-Principle-Investigator'
=> [
"Dr. Mark Wilkinson"
,
"Dr. Kim Hammond-Kosack"
],
'dc:issued'
=>
"2015-11-17"
,
'rdf:type'
=> [
'prov:Collection'
,
'dctypes:Dataset'
],
);
return
\
%metadata
;
}
sub
getDistributionMetadata {
my
(
$self
,
$ID
) =
@_
;
my
%metadata
= (
'dcat:description'
=>
"RDF representation of PHI Base Interaction Record PHI:$ID"
,
'dc:title'
=>
"PHI-Base Interaction PHI:$ID"
,
'dcat:modified'
=>
"2015-11-17"
,
'dc:issued'
=>
"2015-11-17"
,
'dcat:keyword'
=> [
"pathogenesis"
,
"host/pathogen interaction"
,
"PHI Base"
],
'daml:has-Technical-Lead'
=> [
"Dr. Alejandro Rodriguez Gonzalez"
,
"Alejandro Rodriguez Iglesias"
],
'daml:has-Principle-Investigator'
=> [
"Dr. Mark Wilkinson"
,
"Dr. Kim Hammond-Kosack"
],
);
return
\
%metadata
;
}
sub
createTPFDistributions {
my
(
$self
,
$formats
,
$ID
) =
@_
;
my
$query
= "
WHERE {
phi:
$ID
?p ?o .
optional{?o a ?type}
}";
$query
= RDF::Query::Client->new(
$query
);
my
$projections
= FAIR::ProjectorMetadata->new(
NS
=>
$self
->Configuration->Namespaces);
while
(
my
$row
=
$iterator
->
next
){
my
$predicate
=
$row
->{p}->value;
my
$otype
;
if
(
$row
->{type}) {
$otype
=
$row
->{type}->value;
}
my
$encodedpredicate
= urlencode(
$predicate
);
(
$formats
) =
$projections
->createProjection(
$formats
,
$TPF
,
$predicate
,
$otype
);
}
return
(
$projections
->model,
$formats
);
}
sub
urlencode {
my
$s
=
shift
;
$s
=~ s/ /+/g;
$s
=~ s/([^A-Za-z0-9\+-])/
sprintf
(
"%%%02X"
,
ord
($1))/seg;
return
$s
;
}