Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into bump-python-image
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelheaven committed Jul 10, 2023
2 parents 20ac830 + c4c1dab commit 041bfde
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 121 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ARCHIVED: VocPrez is now incorporated into [Prez!](https://github.com/RDFLib/Prez)

![](vocprez/view/style/VocPrez.300.png)

VocPrez is a read-only web delivery system - web pages and API - for Simple Knowledge Organization System (SKOS)-formulated RDF vocabularies. It complies with [Content Negotiation by Profile](https://w3c.github.io/dx-connegp/connegp/).
Expand Down
158 changes: 57 additions & 101 deletions vocprez/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,114 +322,70 @@ def search():
if request.values.get("search"):
last_search = request.values.get("search")
if request.values.get("from") and request.values.get("from") != "all":
q = """
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?uri ?pl (SUM(?w) AS ?weight)
WHERE {{
GRAPH <{grf}> {{
{{ # exact match on a prefLabel always wins
?uri a skos:Concept ;
skos:prefLabel ?pl .
BIND (50 AS ?w)
FILTER REGEX(?pl, "^{input}$", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:prefLabel ?pl .
BIND (10 AS ?w)
FILTER REGEX(?pl, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:altLabel ?al ;
skos:prefLabel ?pl .
BIND (5 AS ?w)
FILTER REGEX(?al, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:hiddenLabel ?hl ;
skos:prefLabel ?pl .
BIND (5 AS ?w)
FILTER REGEX(?hl, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:definition ?d ;
skos:prefLabel ?pl .
BIND (1 AS ?w)
FILTER REGEX(?d, "{input}", "i")
}}
}}
}}
GROUP BY ?uri ?pl
ORDER BY DESC(?weight)
""".format(**{"grf": request.values.get("from"), "input": request.values.get("search")})
results = []
grf = '<' + request.values.get("from") + '>'
bind = f"BIND ({grf} AS ?g)"
else:
q = """
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?g ?uri ?pl (SUM(?w) AS ?weight)
WHERE {{
GRAPH ?g {{
{{ # exact match on a prefLabel always wins
?uri a skos:Concept ;
skos:prefLabel ?pl .
BIND (50 AS ?w)
FILTER REGEX(?pl, "^{input}$", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:prefLabel ?pl .
BIND (10 AS ?w)
FILTER REGEX(?pl, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:altLabel ?al ;
skos:prefLabel ?pl .
BIND (5 AS ?w)
FILTER REGEX(?al, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:hiddenLabel ?hl ;
skos:prefLabel ?pl .
BIND (5 AS ?w)
FILTER REGEX(?hl, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:definition ?d ;
skos:prefLabel ?pl .
BIND (1 AS ?w)
FILTER REGEX(?d, "{input}", "i")
}}
grf = "?g"
bind = ""
q = """
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?g ?uri ?pl (SUM(?w) AS ?weight)
WHERE {{
GRAPH {grf} {{
{{ # exact match on a prefLabel always wins
?uri a skos:Concept ;
skos:prefLabel ?pl .
BIND (50 AS ?w)
FILTER REGEX(?pl, "^{input}$", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:prefLabel ?pl .
BIND (10 AS ?w)
FILTER REGEX(?pl, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:altLabel ?al ;
skos:prefLabel ?pl .
BIND (5 AS ?w)
FILTER REGEX(?al, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:hiddenLabel ?hl ;
skos:prefLabel ?pl .
BIND (5 AS ?w)
FILTER REGEX(?hl, "{input}", "i")
}}
UNION
{{
?uri a skos:Concept ;
skos:definition ?d ;
skos:prefLabel ?pl .
BIND (1 AS ?w)
FILTER REGEX(?d, "{input}", "i")
}}
}}
GROUP BY ?g ?uri ?pl
ORDER BY DESC(?weight)
""".format(**{"input": request.values.get("search")})
results = {}
{bind}
}}
GROUP BY ?g ?uri ?pl
ORDER BY DESC(?weight)
""".format(**{"grf": grf, "input": request.values.get("search"), "bind": bind})
results = {}

for r in u.sparql_query(q):
if r.get("uri") is None:
break # must do this check as r["weight"] will appear at least once with value 0 for no results
if request.values.get("from") and request.values.get("from") != "all":
results.append((r["uri"]["value"], r["pl"]["value"]))
else:
if r["g"]["value"] not in results.keys():
results[r["g"]["value"]] = []
results[r["g"]["value"]].append((r["uri"]["value"], r["pl"]["value"]))

if r["g"]["value"] not in results.keys():
results[r["g"]["value"]] = []
results[r["g"]["value"]].append((r["uri"]["value"], r["pl"]["value"]))

return render_template(
"search.html",
Expand Down
8 changes: 4 additions & 4 deletions vocprez/source/_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,19 @@ def get_concept(self, vocab_uri, uri):
property_label = related_instance_types.get(prop)

if property_label is not None:
related_instances[prop] = (Property(prop, property_label, val, object_label))
related_instances.setdefault(prop, []).append((Property(prop, property_label, val, object_label)))
# related_instances[prop] = (Property(prop, property_label, val, object_label))

else: # other properties
if val != "http://www.w3.org/2004/02/skos/core#Concept" and prop not in suppressed_properties():
if property_label is None:
property_label = other_property_types.get(prop)

if property_label is not None:
if not prop in other_properties :
if not prop in other_properties:
other_properties[prop] = []
other_properties[prop] = (Property(prop, property_label, val, object_label))


if not found:
return None

Expand All @@ -418,7 +418,7 @@ def get_concept(self, vocab_uri, uri):
uri,
pl,
d,
related_instances.values(),
related_instances,
annotations.values(),
other_properties=other_properties.values()
)
Expand Down
31 changes: 17 additions & 14 deletions vocprez/view/templates/concept.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@ <h1>{{ label }}</h1>
<td>{{ concept.definition|safe }}</td>
</tr>
{% if concept.related_instances is not none %}
{% for prop in concept.related_instances %}
{% for k, v in concept.related_instances.items() %}
<tr>
<th><span class="tooltip">{{ prop.label }}<span class="tooltiptext"><a href="{{ prop.uri }}">{{ prop.uri.split('#')[-1].split('/')[-1] }}</a></span></span></th>
<td>
{% if prop.value.startswith('http') %}
{% if prop.value_label is not none %}
<a href="{{ utils.get_content_uri(prop.value) }}">{{ prop.value_label }}</a>
{% else %}
<a href="{{ prop.value }}">{{ prop.value }}</a>
{% endif %}
{% else %}
{{ prop.value }}
{% endif %}
</td>
<th><span class="tooltip">{{ v[0].label }}<span class="tooltiptext"><a href="{{ v[0].uri }}">{{ v[0].uri.split('#')[-1].split('/')[-1] }}</a></span></span></th>
<td>
{% for prop in v %}
{% if prop.value.startswith('http') %}
{% if prop.value_label is not none %}
<a href="{{ utils.get_content_uri(prop.value) }}">{{ prop.value_label }}</a>
{% else %}
<a href="{{ prop.value }}">{{ prop.value }}</a>
{% endif %}
{% else %}
{{ prop.value }}
{% endif %}
<br/>
{% endfor %}
</td>
</tr>
{% endfor %}
{% endfor %}
{% endif %}
{% if concept.annotations is not none %}
{% for prop in concept.annotations %}
Expand Down
4 changes: 2 additions & 2 deletions vocprez/view/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ <h1>Search</h1>
:
</dt>
<dd>
{% for result in results %}
<a href="{{ utils.get_content_uri(result[0]) }}">{{ result[1] }}</a><br />
{% for k, v in results.items() %}
<a href="{{ utils.get_content_uri(v[1][0]) }}">{{ v[1][1] }}</a><br />
{% endfor %}
</dd>
</dl>
Expand Down

0 comments on commit 041bfde

Please sign in to comment.