Zhou Zhi
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Neo4j Doc === :::info We can test on Ken's demo @ http://35.187.240.245:2251/ [Set-Up](#Set-Up) [Creation](#Creation) [Update] [Fundamental Query](#Fundamental-Query) [Composite Query](#Composite-Query) [Sample Queries and Translation](#Sample-Queries-and-Translation) ::: ### Set Up #### DB visualisations [Arcade Analytics](https://arcadeanalytics.com/) [neo4j like querying](https://github.com/AdrianInsua/neo4j-dashboard) [JQA](https://github.com/softvis-research/jqa-dashboard) with [demo]() #### Start VM and Neo4j Server Ensure Capstone ASKIE project GCP -> VM instance -> start VM GCP -> Depolyment Manager -> get address and password Either: Connect via web/local neo4j app using the address and password Or: ``` pip install neo4j ``` ```python= from neo4j import GraphDatabase driver = GraphDatabase.driver("bolt://address:7687", auth=("username", "password"), encrypted=False) with driver.session() as session: result = session.run(query) for record in result: print(record.values()[0]) driver.close() ``` Result are returned as a BoltQuery Object Detailed break down of this data structure is [here](https://neo4j.com/docs/api/python-driver/current/types/graph.html) Useful package [py2neo](https://py2neo.org/) ``` pip install py2neo pip install neomodel ``` ### Creation Create Node with its property Then Create relationship ``` load csv with headers from "file:///val.csv" AS row MERGE (p1:Node {name: row.head}) MERGE (p2:Node {name: row.tail}) WITH p1, p2, row CALL apoc.create.relationship(p1, row.relation, {}, p2) YIELD rel RETURN rel ``` ### Fundamental Query #### 1st Degree by name Return 1st degree link of a particular node by name Output JSON, ```Return x``` for nodes instead ``` MATCH (n)-[r]-(x) WHERE (n.name = 'U.S.') RETURN COLLECT({head:n.name ,tail:x.name,relation:type(r)}) AS jsonOutput ``` #### by relationship Return node-node link with particular relationship Output JSON ``` MATCH (n)-[r:conflict]-(x) RETURN COLLECT({head:n.name ,tail:x.name,relation:type(r)}) AS jsonOutput ``` #### Multiple options for properties ``` MATCH (n)-[r]-(x) WHERE (n.name in ['U.S.','California']) RETURN COLLECT({head:n.name ,tail:x.name,relation:type(r)}) AS jsonOutput ``` ### Composite Query #### 2nd degree ``` match (x)-[r]-(y) where (x.name = "United States") with y Match (y)-[r]-(z) return COLLECT(distinct {head:y.name ,tail:z.name,relation:type(r)}) AS jsonOutput ``` ### Ideas https://github.com/FerreroJeremy/ln2sql ### UI Ideas Left panel are the tools (collapsable) (create,delete,amend,search) Middle panel for Main Graph(or largest cluster) - On create,delete,amend -> Zoom into appropriate nodes Right panel for information Display(by default close) - onclick node in mid graph,open right panel and open new tab Scrub CSS, pending massive improvement ![](https://i.imgur.com/aoNJl4g.png) ![](https://i.imgur.com/IKvL9FO.png) ## Sample Queries and Translation Zhou Zhi & Qing Ze: Familiarize with current knowledge graph and work with Sam/Martin to educate/discover examples of queries useful to them Eg 5 queries/questions for “Startup News” and “E-Commerce” respectively Eg “How many entities invested in company X?” Eg “For X brand, what is their cheapest product?” Resources: “GraphPage” on streamlit demo (http://35.187.240.245:2251/) It shows what relation types there are, eg Investor, FoundedBy, Price etc It shows what attributes each node and each edge has (click “Schema”) These are useful for what kind of queries are possible Click “CustomQuery”: This allows to enter any cypher query and see result Another option: Build docker system locally and use Neo4j browser to try queries https://git.reddragon.ai/RedDragonAI/ASKIE/src/master/ent_link_flask_api/wikidata 1. Popularity of X item. Search for all instances X item appears ``` Match (n) Where n.label ="Google" Return * Limit 5 Or MATCH (n)-[r]-(x) WHERE (n.label = 'Google') Return n,type(r),x ``` 2. Aggregation of X items' entity/relations across multiple entities. ``` MATCH (n)-[r]-(x) WHERE (n.label = 'Google') Return n,type(r),x,count(*) ``` 3. Importance of X items, counting in-degrees and out-degrees ``` in-degree MATCH (n)-[r]->() WHERE n.label = 'Google' RETURN COUNT(r) out-degree MATCH (n)<-[r]-() WHERE n.label = 'Google' RETURN COUNT(r) ``` 4. Given a list of items, what is the most popular/important/best funded ``` MATCH(n) With max(n.someproperty) as p1 //Where n.label in [] MATCH (b) WHERE b.someproperty = p1 //AND b.label in [] RETURN b ``` 5. Relative importance of X items, comparing aggregated in-degree and out-degrees ``` repeat qn3,i.e MATCH (n)-[r]->() WHERE n.label = 'Google' with count(r) as r1 MATCH (x)-[r]->() WHERE x.label = 'business' return r1, count(r) as r2 ``` 6. Items most seen together, comparing the times items have the same entity/relation. Aids in clustering ``` // cluster CALL gds.alpha.scc.stream({ nodeProjection: 'Entity', relationshipProjection: 'InstanceOf' }) YIELD nodeId, componentId RETURN gds.util.asNode(nodeId).label AS Name, componentId AS Component ORDER BY Component DESC // return largest cluster MATCH (u:Entity) RETURN u.componentId AS Component, count(*) AS ComponentSize ORDER BY ComponentSize DESC LIMIT 1 ``` 7. Given list of items, compare based on a specific entity/relation ``` Match n Where n.label in ["a","b"] ``` 8. Comparing similarity of entities. Checking which entities have the most similar kind of relations to other entities. ``` ``` 9. Reconstructing a site from sitelinks/data etc ``` ``` 10. Temporal comparison of relation/entity across past data ``` ``` Goal is to have a generic plug-and-play set of queries [CB Insights report: Venture Capital Funding Report Q2 2020 ](https://www.cbinsights.com/research/report/venture-capital-q2-2020/) **Types of queries** - deal activity per quarter - deals by geography, then compared - number of IPO exits, compared QoQ - highest quarter historically [CB Insights report: 50 Future Unicorns](https://www.cbinsights.com/research/report/future-unicorn-startups-billion-dollar-companies/) ![](https://i.imgur.com/XWIss9h.png) **Types of queries** - company's financial health - company product type (enterprise tools, search, customer protection etc) - company by country - type of industry (fintech, digital, security) - type of market in country (emerging market, developed market) - company by funding - company by state [CB Insights report: Here Are The Top AI Unicorns In Asia](https://www.cbinsights.com/research/asia-ai-unicorns-q1-20/) **Types of queries** - location of unicorns - investor in unicorns - type of product (computer vision for retail etc) [CB Insights report: AI In Asia: The Impact Of Covid-19 On Funding, Exits, Valuations, And R&D](https://www.cbinsights.com/research/report/artificial-intelligence-asia/) **Types of queries** - acquisitions of specific companies (Intel spent X on Y) - capital flows (companies from X country invested in Y country) Arena - founded, last funded Uber - what articles its taken from, then give the answer. or provide half answers/ that make up the eventual answer how to add relationships that are needed, need to automatically add new relationships?

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully