Skip to content

Commit

Permalink
Fix issue with duplicate authors when multiple countries found
Browse files Browse the repository at this point in the history
  • Loading branch information
willu47 committed Apr 4, 2024
1 parent 0e2fcb8 commit b3f22f9
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions app/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get(self, db):
RETURN a
ORDER BY b.rank
}
RETURN o as outputs, collect(DISTINCT c) as countries, collect(a) as authors;
RETURN o as outputs, collect(DISTINCT c) as countries, collect(DISTINCT a) as authors;
"""
records, summary, keys = db.execute_query(query)
articles = [x.data() for x in records]
Expand Down Expand Up @@ -71,7 +71,7 @@ def filter_type(self, db: Driver, result_type: str):
}
RETURN o as outputs,
collect(DISTINCT c) as countries,
collect(a) as authors;
collect(DISTINCT a) as authors;
"""
records, summary, keys = db.execute_query(query,
result_type=result_type)
Expand Down Expand Up @@ -148,7 +148,7 @@ def get(self, id, db, type=None):
OPTIONAL MATCH (p)-[:REFERS_TO]->(c:Country)
RETURN p as outputs,
collect(DISTINCT c) as countries,
collect(b) as authors
collect(DISTINCT b) as authors
ORDER BY outputs.publication_year DESCENDING;"""
else:
publications_query = """MATCH (a:Author)-[:author_of]->(p:Output)
Expand All @@ -162,7 +162,7 @@ def get(self, id, db, type=None):
OPTIONAL MATCH (p)-[:REFERS_TO]->(c:Country)
RETURN p as outputs,
collect(DISTINCT c) as countries,
collect(b) as authors
collect(DISTINCT b) as authors
ORDER BY outputs.publication_year DESCENDING;"""
result, summary, keys = db.execute_query(publications_query,
uuid=id,
Expand All @@ -181,7 +181,7 @@ def get(self, id: str, db):
query = """MATCH (p:Article)
WHERE p.uuid = $uuid
OPTIONAL MATCH (p)-[:REFERS_TO]->(c:Country)
RETURN DISTINCT p as output, collect(c) as countries;"""
RETURN DISTINCT p as output, collect(DISTINCT c) as countries;"""
records, summary, keys = db.execute_query(query, uuid=id)
print(records[0].data())
results = dict()
Expand Down Expand Up @@ -244,19 +244,29 @@ def get(self, id: str, db: Driver, result_type=None):

if result_type:
query = """
MATCH (o:Output)-[r:REFERS_TO]->(c:Country)
MATCH (a:Author)-[:author_of]->(o:Output)
MATCH (o:Output)-[:REFERS_TO]->(c:Country)
WHERE c.id = $id AND (o.result_type = $result_type)
RETURN o as outputs, collect(a) as authors;
CALL {
WITH o
MATCH (a:Author)-[r:author_of]->(o)
RETURN a
ORDER BY r.rank
}
RETURN o as outputs, collect(DISTINCT a) as authors;
"""
results, _, _ = db.execute_query(query, id=id,
result_type=result_type)
else:
query = """
MATCH (o:Output)-[r:REFERS_TO]->(c:Country)
MATCH (a:Author)-[:author_of]->(o:Output)
MATCH (o:Output)-[:REFERS_TO]->(c:Country)
WHERE c.id = $id
RETURN o as outputs, collect(a) as authors;
CALL {
WITH o
MATCH (a:Author)-[r:author_of]->(o)
RETURN a
ORDER BY r.rank
}
RETURN o as outputs, collect(DISTINCT a) as authors;
"""
results, _, _ = db.execute_query(query, id=id,
result_type=result_type)
Expand Down

0 comments on commit b3f22f9

Please sign in to comment.