Skip to content

Instantly share code, notes, and snippets.

@hammedb197
Last active August 10, 2020 14:00
Show Gist options
  • Select an option

  • Save hammedb197/9c8dded49ceba2ce30b9f3f6edebc739 to your computer and use it in GitHub Desktop.

Select an option

Save hammedb197/9c8dded49ceba2ce30b9f3f6edebc739 to your computer and use it in GitHub Desktop.
query = """
with $files as rows
unwind rows as row
unwind row.authors as authors
unwind row.Entity as entities
unwind row.sent_tag as sent
unwind keys(sent) as sent_key
unwind keys(entities) as entity_label
unwind entities[entity_label] as entities_value
unwind sent[sent_key] as tags
with entities_value, entities, authors, row, entity_label, sent, sent_key, tags
with sent_key, entities, authors, row, entities_value, entity_label, entities_value.meaning as means, tags
unwind tags as tag
call apoc.merge.node([entity_label], {text:entities_value.label}, {}) YIELD node
merge (paper:Paper {paper:row['url']})
merge (paper)-[:PAPER_SOURCE]->(source:SOURCE {site:row.site})
merge (title:Title {title:row.title})
merge (alias:ALIAS {alias: entities_value.alias})
merge (meaning:Meaning {meaning:coalesce(means[0], "none"), score:coalesce(means[2], "none"), concept_id:coalesce(means[1], "none")})
merge (abstract:ABSTRACT {abstract:row.abstract})
merge (author:AUTHOR {author_name: authors.author_name, author_institution: authors.author_inst })
merge (publish_date:PUBLISH_DATE {publication_date:row.publication_date})
merge (abstract)<-[:SENTENCE_FROM]-(sentence:Sentences {sentence: sent_key})
with row, author, authors, paper, title, abstract, publish_date, entities_value, entity_label, node, alias, meaning
call apoc.merge.relationship(paper, "ENTITY_"+ entity_label, {}, {}, node) YIELD rel as relx
call apoc.merge.relationship(alias, entities_value.label + "_ALIAS", {}, {}, node) YIELD rel as rely
call apoc.merge.relationship(meaning, "MEANS", {}, {}, node) YIELD rel as relz
call (paper)-[:PAPER_TITLE]->(title)
call (paper)-[:ABSTRACT]->(abstract)
call (paper)-[:AUTHOR]->(author)
call (paper)-[:PUBLISH_DATE]->(publish_date)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment