Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DBRepo
Manage
Activity
Members
Labels
Plan
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
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
FAIR Data Austria DB Repository
DBRepo
Commits
39245ac3
Unverified
Commit
39245ac3
authored
Jan 3, 2023
by
Martin Weise
Browse files
Options
Downloads
Patches
Plain Diff
Fixed the concepts
parent
f73d1b8c
No related branches found
No related tags found
3 merge requests
!129
New module for citation as they occur multiple
,
!123
Resolve "Concepts for columns, Units for values of columns"
,
!121
Modified logging, modified logging level, modified flasgger endpoint
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
fda-semantics-service/list.py
+18
-22
18 additions, 22 deletions
fda-semantics-service/list.py
fda-semantics-service/test/test_list.py
+8
-8
8 additions, 8 deletions
fda-semantics-service/test/test_list.py
with
26 additions
and
30 deletions
fda-semantics-service/list.py
+
18
−
22
View file @
39245ac3
...
...
@@ -61,15 +61,13 @@ class List:
l_query
=
"""
SELECT DISTINCT ?item ?name ?comment
WHERE {
SERVICE <https://query.wikidata.org/sparql> {
SELECT
DISTINCT
?item ?name ?comment
SELECT ?item ?name ?comment
WHERE {
?item wdt:P31 wd:Q4406616.
OPTIONAL {
?item wdt:P279* wd:Q1183543 .
?item rdfs:label ?name .
?item schema:description ?comment .
FILTER(LANG(?comment) =
"
en
"
) .
FILTER(LANG(?name) =
"
en
"
) .
}
FILTER(CONTAINS(LCASE(?name),
\"
"""
+
name
+
"""
\"
@en)) .
}
}
...
...
@@ -87,7 +85,7 @@ class List:
uri_query
=
"""
SELECT ?uri
WHERE {
?uri rdfs:label ?o .
FILTER regex(str(?o),
\"
^
"""
+
name
+
"""
$
\"
,
"
i
"
)
FILTER regex(str(?o),
\"
^
"""
+
name
+
"""
$
\"
,
"
i
"
)
.
} LIMIT 1
"""
qres
=
self
.
g
.
query
(
uri_query
)
...
...
@@ -101,17 +99,15 @@ class List:
uri_query
=
"""
SELECT DISTINCT ?item ?name ?comment
WHERE {
SERVICE <https://query.wikidata.org/sparql> {
SELECT
DISTINCT
?item ?name ?comment
SELECT ?item ?name ?comment
WHERE {
?item wdt:P31 wd:Q4406616.
OPTIONAL {
?item wdt:P279* wd:Q1183543 .
?item rdfs:label ?name .
?item schema:description ?comment .
}
FILTER(LANG(?comment) =
"
en
"
) .
FILTER(LANG(?name) =
"
en
"
) .
FILTER
(CONTAINS(LCASE
(?name
)
,
\"
"""
+
name
+
"""
\"
@en)).
}
LIMIT 1
FILTER
regex
(?name,
\"
^
"""
+
name
+
"""
$
\"
,
"
i
"
) .
}
}
}
"""
qres
=
self
.
g
.
query
(
uri_query
)
...
...
This diff is collapsed.
Click to expand it.
fda-semantics-service/test/test_list.py
+
8
−
8
View file @
39245ac3
...
...
@@ -17,19 +17,19 @@ list = List(offline=True)
class
ListUnitTest
(
unittest
.
TestCase
):
def
test_list_units_succeeds
(
self
):
exp
=
[
'
metre
'
,
'
metre of mercury
'
]
exp
=
[
'
metre
'
,
'
metre of mercury
'
]
.
sort
()
# test
response
=
list
.
list_units
(
'
metre
'
)
body
=
[
unit
[
"
name
"
]
for
unit
in
response
]
body
=
[
unit
[
"
name
"
]
for
unit
in
response
]
.
sort
()
self
.
assertEqual
(
exp
,
body
)
def
test_list_concepts_succeeds
(
self
):
exp
=
[
'
Flask in the Form of a Leather Bag
'
,
'
Lentoid Flask (Pilgrim Flask)
'
]
exp
=
[
'
volumetric flask
'
,
'
vacuum flask cooker
'
].
sort
()
# test
response
=
list
.
list_concepts
(
'
flask
'
)
body
=
[
unit
[
"
name
"
]
for
unit
in
response
]
body
=
[
unit
[
"
name
"
]
for
unit
in
response
]
.
sort
()
self
.
assertEqual
(
exp
,
body
)
def
test_list_units_fails
(
self
):
...
...
@@ -55,17 +55,17 @@ class ListUnitTest(unittest.TestCase):
self
.
assertEqual
(
exp
,
response
)
def
test_get_concept_uri_hasSpaces_succeeds
(
self
):
exp
=
{
"
uri
"
:
"
http://www.wikidata.org/entity/Q
60779664
"
}
exp
=
{
"
uri
"
:
"
http://www.wikidata.org/entity/Q
998319
"
}
# test
response
=
list
.
get_concept_uri
(
"
Box (Pyxis) in the Form of a Composite Capital
"
)
response
=
list
.
get_concept_uri
(
"
flight recorder
"
)
self
.
assertEqual
(
exp
,
response
)
def
test_get_concept_uri_succeeds
(
self
):
exp
=
{
"
uri
"
:
"
http://www.wikidata.org/entity/Q2
16425
"
}
exp
=
{
"
uri
"
:
"
http://www.wikidata.org/entity/Q2
35783
"
}
# test
response
=
list
.
get_concept_uri
(
"
teaspoon
"
)
response
=
list
.
get_concept_uri
(
"
flashlight
"
)
self
.
assertEqual
(
exp
,
response
)
...
...
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