Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SQL2Linked
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
backend
scripts
SQL2Linked
Merge requests
!9
New: Migrate resource structured data to linked data
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
New: Migrate resource structured data to linked data
Issue/2084-migrateResourceStructuralData
into
dev
Overview
6
Commits
12
Pipelines
25
Changes
5
All threads resolved!
Show all comments
Merged
Hanna Führ
requested to merge
Issue/2084-migrateResourceStructuralData
into
dev
2 years ago
Overview
6
Commits
12
Pipelines
25
Changes
5
All threads resolved!
Show all comments
Expand
coscine/issues#2084
Edited
2 years ago
by
Benedikt Heinrichs
0
0
Merge request reports
Compare
dev
version 11
ff44aefc
2 years ago
version 10
108c0d28
2 years ago
version 9
db5050c6
2 years ago
version 8
be5306a9
2 years ago
version 7
fd412533
2 years ago
version 6
4595a6a6
2 years ago
version 5
56e62027
2 years ago
version 4
b883b2a9
2 years ago
version 3
b0e9ca54
2 years ago
version 2
22d4fdeb
2 years ago
version 1
667e0540
2 years ago
dev (base)
and
latest version
latest version
36413cc7
12 commits,
2 years ago
version 11
ff44aefc
11 commits,
2 years ago
version 10
108c0d28
10 commits,
2 years ago
version 9
db5050c6
9 commits,
2 years ago
version 8
be5306a9
8 commits,
2 years ago
version 7
fd412533
7 commits,
2 years ago
version 6
4595a6a6
6 commits,
2 years ago
version 5
56e62027
5 commits,
2 years ago
version 4
b883b2a9
4 commits,
2 years ago
version 3
b0e9ca54
3 commits,
2 years ago
version 2
22d4fdeb
2 commits,
2 years ago
version 1
667e0540
1 commit,
2 years ago
5 files
+
211
−
66
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
src/SQL2Linked/Implementations/ResourceStructuralData.cs
+
141
−
3
Options
using
Coscine.Database.DataModel
;
using
Coscine.Database.Models
;
using
VDS.RDF
;
using
VDS.RDF.Query
;
namespace
SQL2Linked.Implementations
{
public
class
ResourceStructuralData
:
StructuralData
<
Resource
,
ResourceModel
>
{
public
readonly
Uri
org
=
new
(
"http://www.w3.org/ns/org#"
);
public
readonly
Uri
dcat
=
new
(
"http://www.w3.org/ns/dcat#"
);
public
readonly
Uri
dcterms
=
new
(
"http://purl.org/dc/terms/"
);
public
readonly
Uri
acl
=
new
(
"http://www.w3.org/ns/auth/acl#"
);
public
readonly
Uri
foaf
=
new
(
"http://xmlns.com/foaf/0.1/"
);
public
readonly
Uri
pim
=
new
(
"http://www.w3.org/ns/pim/space#"
);
public
readonly
Uri
rdf
=
new
(
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
);
public
readonly
Uri
cosc
=
new
(
"https://purl.org/coscine/"
);
private
VisibilityModel
VisibilityModel
=
new
VisibilityModel
();
private
ProjectResourceModel
ProjectResourceModel
=
new
ProjectResourceModel
();
private
LicenseModel
LicenseModel
=
new
LicenseModel
();
public
override
IEnumerable
<
IGraph
>
ConvertToLinkedData
(
IEnumerable
<
Resource
>
entries
)
{
// ToDo: Implement
throw
new
NotImplementedException
();
IEnumerable
<
Visibility
>
visibilities
=
VisibilityModel
.
GetAll
();
IEnumerable
<
ProjectResource
>
projectResources
=
ProjectResourceModel
.
GetAll
();
IEnumerable
<
License
>
licenses
=
LicenseModel
.
GetAll
();
var
graphs
=
new
List
<
IGraph
>();
string
resourceUrlPrefix
=
"https://hdl.handle.net/"
+
Prefix
;
foreach
(
var
entry
in
entries
)
{
var
resourceGraphName
=
$"
{
resourceUrlPrefix
}
/
{
entry
.
Id
}
"
;
var
graph
=
new
Graph
();
graph
.
BaseUri
=
new
Uri
(
resourceGraphName
);
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
rdf
+
"type"
,
dcat
+
"Catalog"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
rdf
}
type
{
dcat
}
Catalog'. "
);
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
rdf
+
"type"
,
pim
+
"Storage"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
rdf
}
type
{
pim
}
Storage'. "
);
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
dcat
+
"service"
,
cosc
+
$"resourcetype/
{
entry
.
TypeId
}
"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcat
}
service
{
cosc
}
resourcetype/
{
entry
.
TypeId
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
dcterms
+
"title"
,
entry
.
ResourceName
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
title
{
entry
.
ResourceName
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
dcterms
+
"alternative"
,
entry
.
DisplayName
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
alternative
{
entry
.
DisplayName
}
'. "
);
foreach
(
var
visibility
in
visibilities
)
{
if
(
entry
.
VisibilityId
==
visibility
.
Id
&&
visibility
.
DisplayName
.
Contains
(
"Public"
))
{
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
cosc
+
"terms/resource#visibility"
,
cosc
+
$"terms/visibility#public"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
cosc
}
terms/resource#visibility
{
cosc
}
terms/visibility#public'. "
);
break
;
}
else
if
(
entry
.
VisibilityId
==
visibility
.
Id
&&
visibility
.
DisplayName
.
Contains
(
"Project Members"
))
{
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
cosc
+
"terms/resource#visibility"
,
cosc
+
$"terms/visibility#projectMember"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
cosc
}
terms/resource#visibility
{
cosc
}
terms/visibility#projectMember'. "
);
break
;
}
}
foreach
(
var
license
in
licenses
)
{
if
(
entry
.
LicenseId
==
license
.
Id
)
{
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
dcterms
+
"license"
,
license
.
DisplayName
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
license
{
license
.
DisplayName
}
'. "
);
break
;
}
}
if
(!
string
.
IsNullOrWhiteSpace
(
entry
.
Keywords
))
{
var
listKeywords
=
entry
.
Keywords
.
Split
(
';'
).
ToList
();
foreach
(
var
keyword
in
listKeywords
)
{
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
dcterms
+
"subject"
,
keyword
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
subject
{
keyword
}
'. "
);
}
}
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
dcterms
+
"rights"
,
entry
.
UsageRights
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
rights
{
entry
.
UsageRights
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
dcterms
+
"description"
,
entry
.
Description
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
description
{
entry
.
Description
}
'. "
);
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
dcterms
+
"conformsTo"
,
entry
.
ApplicationProfile
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
conformsTo
{
entry
.
ApplicationProfile
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
cosc
+
"terms/resource#fixedValues"
,
entry
.
FixedValues
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
cosc
}
terms/resource#fixedValues
{
entry
.
FixedValues
}
'. "
);
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
dcterms
+
"creator"
,
cosc
+
$"users/
{
entry
.
Creator
}
"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcterms
}
creator
{
cosc
}
users/
{
entry
.
Creator
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
resourceGraphName
,
cosc
+
"terms/resource#archived"
,
entry
.
Archived
.
ToString
(),
new
Uri
(
"http://www.w3.org/2001/XMLSchema#boolean"
));
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
cosc
}
terms/resource#archived
{
entry
.
Archived
}
'. "
);
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
foaf
+
"homepage"
,
resourceGraphName
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
foaf
}
homepage
{
resourceGraphName
}
'. "
);
SparqlParameterizedString
cmdString
=
new
SparqlParameterizedString
{
CommandText
=
"SELECT DISTINCT ?g "
+
"WHERE {"
+
"GRAPH ?g { ?s ?p ?o } . "
+
"FILTER(STRSTARTS(STR(?s), \""
+
resourceGraphName
+
"@\"))"
+
"}"
};
var
resultSet
=
QueryEndpoint
.
QueryWithResultSet
(
cmdString
.
ToString
());
foreach
(
var
result
in
resultSet
)
{
AssertToGraphUriNode
(
graph
,
resourceGraphName
,
dcat
+
"catalog"
,
result
[
0
].
ToString
());
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
resourceGraphName
}
{
dcat
}
catalog
{
result
[
0
].
ToString
()}
'. "
);
}
foreach
(
var
projectResource
in
projectResources
)
{
if
(
entry
.
Id
==
projectResource
.
ResourceId
)
{
var
blankNode
=
graph
.
CreateBlankNode
();
AssertToGraphBlankAndUriNode
(
graph
,
blankNode
,
rdf
+
"type"
,
acl
+
"Authorization"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
blankNode
}
{
rdf
}
type
{
acl
}
Authorization'. "
);
AssertToGraphBlankAndUriNode
(
graph
,
blankNode
,
acl
+
"agentGroup"
,
$"
{
resourceUrlPrefix
}
/
{
projectResource
.
ProjectId
}
"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
blankNode
}
{
acl
}
agentGroup
{
resourceUrlPrefix
}
/
{
projectResource
.
ProjectId
}
'. "
);
AssertToGraphBlankAndUriNode
(
graph
,
blankNode
,
acl
+
"accessTo"
,
resourceGraphName
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
blankNode
}
{
acl
}
accessTo
{
resourceGraphName
}
'. "
);
AssertToGraphBlankAndUriNode
(
graph
,
blankNode
,
acl
+
"mode"
,
acl
+
"Control"
);
Console
.
WriteLine
(
$"For resource '
{
entry
.
DisplayName
}
' will migrate triple '
{
blankNode
}
{
acl
}
accessTo
{
acl
}
Control'. "
);
}
}
graphs
.
Add
(
graph
);
}
return
graphs
;
}
}
}
\ No newline at end of file
}
Loading