Skip to content

Commit f0cdd36

Browse files
committed
Enhance get_templates function: aggregate datasets and licenses for improved query results
1 parent fab46e9 commit f0cdd36

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/vfbquery/vfb_queries.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,15 +1504,17 @@ def get_templates(limit: int = -1, return_dataframe: bool = False):
15041504

15051505
# Define the main Cypher query
15061506
# Match full pattern to exclude template channel nodes
1507+
# Use COLLECT to aggregate multiple datasets/licenses into single row per template
15071508
query = f"""
15081509
MATCH (p:Class)<-[:INSTANCEOF]-(t:Template)<-[:depicts]-(tc:Template)-[r:in_register_with]->(tc)
15091510
OPTIONAL MATCH (t)-[:has_source]->(ds:DataSet)
15101511
OPTIONAL MATCH (ds)-[:has_license|license]->(lic:License)
1511-
RETURN t.short_form as id,
1512+
WITH t, r, COLLECT(DISTINCT ds) as datasets, COLLECT(DISTINCT lic) as licenses
1513+
RETURN DISTINCT t.short_form as id,
15121514
apoc.text.format("[%s](%s)",[COALESCE(t.symbol[0],t.label),t.short_form]) AS name,
15131515
apoc.text.join(t.uniqueFacets, '|') AS tags,
1514-
COALESCE(apoc.text.format("[%s](%s)",[COALESCE(ds.symbol[0],ds.label),ds.short_form]), '') AS dataset,
1515-
COALESCE(REPLACE(apoc.text.format("[%s](%s)",[COALESCE(lic.symbol[0],lic.label),lic.short_form]), '[null](null)', ''), '') AS license,
1516+
apoc.text.join([ds IN datasets | apoc.text.format("[%s](%s)",[COALESCE(ds.symbol[0],ds.label),ds.short_form])], ', ') AS dataset,
1517+
apoc.text.join([lic IN licenses | REPLACE(apoc.text.format("[%s](%s)",[COALESCE(lic.symbol[0],lic.label),lic.short_form]), '[null](null)', '')], ', ') AS license,
15161518
COALESCE(REPLACE(apoc.text.format("[![%s](%s '%s')](%s)",[COALESCE(t.symbol[0],t.label), REPLACE(COALESCE(r.thumbnail[0],""),"thumbnailT.png","thumbnail.png"), COALESCE(t.symbol[0],t.label), t.short_form]), "[![null]( 'null')](null)", ""), "") as thumbnail,
15171519
99 as order
15181520
ORDER BY id DESC

0 commit comments

Comments
 (0)