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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
backend
scripts
SQL2Linked
Commits
96cd4fa4
Commit
96cd4fa4
authored
Aug 8, 2022
by
Hanna Führ
Browse files
Options
Downloads
Patches
Plain Diff
Update: Migrate project structured data to linked data (coscine/issues#2085)
parent
f1f3840d
Branches
Branches containing commit
No related tags found
1 merge request
!10
New: Migrate project structured data to linked data
Pipeline
#777035
skipped
Stage: commands
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/SQL2Linked/Implementations/ProjectStructuralData.cs
+94
-2
94 additions, 2 deletions
src/SQL2Linked/Implementations/ProjectStructuralData.cs
src/SQL2Linked/StructuralData.cs
+36
-0
36 additions, 0 deletions
src/SQL2Linked/StructuralData.cs
with
130 additions
and
2 deletions
src/SQL2Linked/Implementations/ProjectStructuralData.cs
+
94
−
2
View file @
96cd4fa4
using
Coscine.Database.DataModel
;
using
Coscine.Database.Models
;
using
VDS.RDF
;
using
VDS.RDF.Query
;
namespace
SQL2Linked.Implementations
{
public
class
ProjectStructuralData
:
StructuralData
<
Project
,
ProjectModel
>
{
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
foaf
=
new
(
"http://xmlns.com/foaf/0.1/"
);
public
readonly
Uri
vcard
=
new
(
"http://www.w3.org/2006/vcard/ns#"
);
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
RoleModel
RoleModel
=
new
RoleModel
();
public
override
IEnumerable
<
IGraph
>
ConvertToLinkedData
(
IEnumerable
<
Project
>
entries
)
{
// ToDo: Implement
throw
new
NotImplementedException
();
IEnumerable
<
Visibility
>
visibilities
=
VisibilityModel
.
GetAll
();
IEnumerable
<
Role
>
roles
=
RoleModel
.
GetAll
();
var
graphs
=
new
List
<
IGraph
>();
string
resourceUrlPrefix
=
"https://hdl.handle.net/"
+
Prefix
;
foreach
(
var
entry
in
entries
)
{
var
projectGraphName
=
$"
{
resourceUrlPrefix
}
/
{
entry
.
Id
}
"
;
var
graph
=
new
Graph
();
graph
.
BaseUri
=
new
Uri
(
projectGraphName
);
AssertToGraphUriNode
(
graph
,
projectGraphName
,
rdf
+
"type"
,
dcat
+
"Catalog"
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
rdf
}
type
{
dcat
}
Catalog'. "
);
AssertToGraphUriNode
(
graph
,
projectGraphName
,
rdf
+
"type"
,
org
+
"OrganizationalCollaboration"
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
rdf
}
type
{
org
}
OrganizationalCollaboration'. "
);
AssertToGraphUriNode
(
graph
,
projectGraphName
,
rdf
+
"type"
,
vcard
+
"Group"
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
rdf
}
type
{
vcard
}
Group'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcterms
+
"title"
,
entry
.
ProjectName
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcterms
}
title
{
entry
.
ProjectName
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcterms
+
"description"
,
entry
.
Description
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcterms
}
description
{
entry
.
Description
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcat
+
"startDate"
,
entry
.
StartDate
.
ToString
());
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcat
}
startDate
{
entry
.
StartDate
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcat
+
"endDate"
,
entry
.
EndDate
.
ToString
());
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcat
}
endDate
{
entry
.
EndDate
}
'. "
);
if
(
entry
.
Keywords
.
Any
())
{
var
listKeywords
=
entry
.
Keywords
.
Split
(
';'
).
ToList
();
foreach
(
var
keyword
in
listKeywords
)
{
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcterms
+
"subject"
,
keyword
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcterms
}
subject
{
keyword
}
'. "
);
}
}
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcterms
+
"alternative"
,
entry
.
DisplayName
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcterms
}
alternative
{
entry
.
DisplayName
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
dcterms
+
"rightsHolder"
,
entry
.
PrincipleInvestigators
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
dcterms
}
rightsHolder
{
entry
.
PrincipleInvestigators
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
"https://schema.org/funding"
,
entry
.
GrantId
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
https://schema.org/funding
{
entry
.
GrantId
}
'. "
);
foreach
(
var
visibility
in
visibilities
)
{
if
(
entry
.
VisibilityId
==
visibility
.
Id
&&
visibility
.
DisplayName
.
Contains
(
"Public"
))
{
AssertToGraphUriNode
(
graph
,
projectGraphName
,
cosc
+
"terms/project#visibility"
,
cosc
+
$"terms/visibility#public"
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
cosc
}
terms/project#visibility
{
cosc
}
terms/visibility#public'. "
);
break
;
}
else
if
(
entry
.
VisibilityId
==
visibility
.
Id
&&
visibility
.
DisplayName
.
Contains
(
"Project Members"
))
{
AssertToGraphUriNode
(
graph
,
projectGraphName
,
cosc
+
"terms/project#visibility"
,
cosc
+
$"terms/visibility#projectMember"
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
cosc
}
terms/project#visibility
{
cosc
}
terms/visibility#projectMember'. "
);
break
;
}
}
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
cosc
+
"terms/project#deleted"
,
entry
.
Deleted
.
ToString
());
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
cosc
}
terms/project#deleted
{
entry
.
Deleted
}
'. "
);
AssertToGraphLiteralNode
(
graph
,
projectGraphName
,
cosc
+
"terms/project#slug"
,
entry
.
Slug
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
cosc
}
terms/project#slug
{
entry
.
Slug
}
'. "
);
AssertToGraphUriNode
(
graph
,
projectGraphName
,
foaf
+
"homepage"
,
projectGraphName
);
Console
.
WriteLine
(
$"For project '
{
entry
.
DisplayName
}
' will migrate triple '
{
projectGraphName
}
{
foaf
}
homepage
{
projectGraphName
}
'. "
);
}
return
graphs
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/SQL2Linked/StructuralData.cs
+
36
−
0
View file @
96cd4fa4
...
...
@@ -2,6 +2,7 @@
using
Coscine.Database.Models
;
using
Coscine.Metadata
;
using
VDS.RDF
;
using
VDS.RDF.Query
;
namespace
SQL2Linked
{
...
...
@@ -10,12 +11,16 @@ namespace SQL2Linked
public
T
Model
{
get
;
init
;
}
public
ConsulConfiguration
Configuration
{
get
;
init
;
}
public
RdfStoreConnector
RdfStoreConnector
{
get
;
init
;
}
public
static
string
Prefix
{
get
;
set
;
}
public
readonly
SparqlRemoteEndpoint
QueryEndpoint
;
public
StructuralData
()
{
Configuration
=
new
ConsulConfiguration
();
RdfStoreConnector
=
new
RdfStoreConnector
(
Configuration
.
GetStringAndWait
(
"coscine/local/virtuoso/additional/url"
));
Model
=
new
T
();
Prefix
=
Configuration
.
GetStringAndWait
(
"coscine/global/epic/prefix"
);
QueryEndpoint
=
new
SparqlRemoteEndpoint
(
new
Uri
(
string
.
Format
(
"http://localhost:8890/sparql"
)));
}
public
abstract
IEnumerable
<
IGraph
>
ConvertToLinkedData
(
IEnumerable
<
S
>
entries
);
...
...
@@ -51,5 +56,36 @@ namespace SQL2Linked
Console
.
WriteLine
();
}
}
public
void
AssertToGraphUriNode
(
IGraph
graph
,
string
graphSubject
,
string
graphPredicate
,
string
graphObject
)
{
graph
.
Assert
(
new
Triple
(
graph
.
CreateUriNode
(
new
Uri
(
graphSubject
)),
graph
.
CreateUriNode
(
new
Uri
(
graphPredicate
)),
graph
.
CreateUriNode
(
new
Uri
(
graphObject
))
)
);
}
public
void
AssertToGraphLiteralNode
(
IGraph
graph
,
string
graphSubject
,
string
graphPredicate
,
string
graphObject
,
Uri
?
objectType
=
null
)
{
graph
.
Assert
(
new
Triple
(
graph
.
CreateUriNode
(
new
Uri
(
graphSubject
)),
graph
.
CreateUriNode
(
new
Uri
(
graphPredicate
)),
graph
.
CreateLiteralNode
(
graphObject
,
objectType
)
)
);
}
public
void
AssertToGraphBlankAndUriNode
(
IGraph
graph
,
IBlankNode
graphSubject
,
string
graphPredicate
,
string
graphObject
)
{
graph
.
Assert
(
new
Triple
(
graphSubject
,
graph
.
CreateUriNode
(
new
Uri
(
graphPredicate
)),
graph
.
CreateUriNode
(
new
Uri
(
graphObject
))
)
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment