Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DKE_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc Feger
DKE_project
Commits
7cb94194
Commit
7cb94194
authored
6 years ago
by
Marc Feger
Browse files
Options
Downloads
Patches
Plain Diff
Add Triple Writer; Add Triple-Representation for Wikidata data
parent
30552af0
No related branches found
No related tags found
No related merge requests found
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
app.py
+7
-2
7 additions, 2 deletions
app.py
src/main.py
+67
-1
67 additions, 1 deletion
src/main.py
static/wikidata_groundtruth.txt
+1
-1
1 addition, 1 deletion
static/wikidata_groundtruth.txt
with
75 additions
and
5 deletions
.gitignore
+
0
−
1
View file @
7cb94194
...
@@ -61,7 +61,6 @@ dist/
...
@@ -61,7 +61,6 @@ dist/
downloads/
downloads/
eggs/
eggs/
.eggs/
.eggs/
lib/
lib64/
lib64/
parts/
parts/
sdist/
sdist/
...
...
This diff is collapsed.
Click to expand it.
app.py
+
7
−
2
View file @
7cb94194
from
flask
import
Flask
from
flask
import
Flask
,
Response
from
flask.json
import
jsonify
from
flask.json
import
jsonify
from
src.main
import
assemble_wikidata_groundtruth
,
assemble_dbpedia_groundtruth
from
src.main
import
assemble_wikidata_groundtruth
,
assemble_dbpedia_groundtruth
,
assemble_wikidata_triples
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
@app.route
(
'
/wikidata/n3
'
)
def
wikidata_n3
():
return
jsonify
(
assemble_wikidata_triples
())
@app.route
(
'
/wikidata/groundtruth
'
)
@app.route
(
'
/wikidata/groundtruth
'
)
def
wikidata_groundtruth
():
def
wikidata_groundtruth
():
return
jsonify
(
assemble_wikidata_groundtruth
())
return
jsonify
(
assemble_wikidata_groundtruth
())
...
...
This diff is collapsed.
Click to expand it.
src/main.py
+
67
−
1
View file @
7cb94194
from
typing
import
Dict
from
tokenize
import
String
from
typing
import
Dict
,
List
from
src
import
WIKIDATA_ENTRYPOINT
,
DBPEDIA_ENTRYPOINT
from
src
import
WIKIDATA_ENTRYPOINT
,
DBPEDIA_ENTRYPOINT
from
src.lib.decapper
import
Decapper
from
src.lib.engine
import
SPARQLEngine
from
src.lib.engine
import
SPARQLEngine
from
src.lib.reader
import
FileReader
from
src.lib.ntriple
import
NTriple
from
src.lib.writer
import
FileWriter
from
src.lib.writer
import
FileWriter
from
src.wikidata.keys
import
ResultKeys
def
assemble_wikidata_groundtruth
()
->
Dict
:
def
assemble_wikidata_groundtruth
()
->
Dict
:
...
@@ -31,3 +36,64 @@ def assemble_dbpedia_groundtruth() -> Dict:
...
@@ -31,3 +36,64 @@ def assemble_dbpedia_groundtruth() -> Dict:
writer
=
FileWriter
(
destination
=
'
static/dbpedia_groundtruth.txt
'
,
data
=
data
)
writer
=
FileWriter
(
destination
=
'
static/dbpedia_groundtruth.txt
'
,
data
=
data
)
writer
.
as_json
()
writer
.
as_json
()
return
data
return
data
def
assemble_wikidata_triples
()
->
List
:
"""
This method assembles the N-Triples of wikidata.
:return:
"""
data
=
FileReader
(
source
=
'
static/wikidata_groundtruth.txt
'
).
as_json
()
wdt
=
'
http://www.wikidata.org/prop/direct/
'
schema
=
'
http://schema.org/
'
triples
:
List
[
String
]
=
[]
for
result
in
data
:
movie
=
Decapper
(
result
[
ResultKeys
.
movie
.
value
]).
unpack
()
if
ResultKeys
.
title
.
value
in
result
.
keys
():
for
title
in
Decapper
(
result
[
ResultKeys
.
title
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
title
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P1476
'
,
value
=
title
).
as_string
()]
if
ResultKeys
.
director
.
value
in
result
.
keys
():
for
director
in
Decapper
(
result
[
ResultKeys
.
director
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
director
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P57
'
,
value
=
director
).
as_string
()]
if
ResultKeys
.
author
.
value
in
result
.
keys
():
for
author
in
Decapper
(
result
[
ResultKeys
.
author
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
author
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P58
'
,
value
=
author
).
as_string
()]
if
ResultKeys
.
cast
.
value
in
result
.
keys
():
for
cast
in
Decapper
(
result
[
ResultKeys
.
cast
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
cast
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P161
'
,
value
=
cast
).
as_string
()]
if
ResultKeys
.
published
.
value
in
result
.
keys
():
for
published
in
Decapper
(
result
[
ResultKeys
.
published
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
published
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P577
'
,
value
=
published
).
as_string
()]
if
ResultKeys
.
genre
.
value
in
result
.
keys
():
for
genre
in
Decapper
(
result
[
ResultKeys
.
genre
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
genre
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P136
'
,
value
=
genre
).
as_string
()]
if
ResultKeys
.
duration
.
value
in
result
.
keys
():
for
duration
in
Decapper
(
result
[
ResultKeys
.
duration
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
duration
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P2047
'
,
value
=
duration
).
as_string
()]
if
ResultKeys
.
description
.
value
in
result
.
keys
():
for
description
in
Decapper
(
result
[
ResultKeys
.
description
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
description
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
schema
+
'
description
'
,
value
=
description
).
as_string
()]
if
ResultKeys
.
production_company
.
value
in
result
.
keys
():
for
production_company
in
Decapper
(
result
[
ResultKeys
.
production_company
.
value
]).
unpack
().
split
(
ResultKeys
.
line_separator
.
value
):
if
production_company
:
triples
+=
[
NTriple
(
subject
=
movie
,
predicate
=
wdt
+
'
P272
'
,
value
=
production_company
).
as_string
()]
return
triples
This diff is collapsed.
Click to expand it.
static/wikidata_groundtruth.txt
+
1
−
1
View file @
7cb94194
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