Skip to content
Snippets Groups Projects
Unverified Commit 39245ac3 authored by Martin Weise's avatar Martin Weise
Browse files

Fixed the concepts

parent f73d1b8c
No related branches found
No related tags found
3 merge requests!129New module for citation as they occur multiple,!123Resolve "Concepts for columns, Units for values of columns",!121Modified logging, modified logging level, modified flasgger endpoint
......@@ -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)
......
......@@ -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/Q60779664"}
exp = {"uri": "http://www.wikidata.org/entity/Q998319"}
# 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/Q216425"}
exp = {"uri": "http://www.wikidata.org/entity/Q235783"}
# test
response = list.get_concept_uri("teaspoon")
response = list.get_concept_uri("flashlight")
self.assertEqual(exp, response)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment