Dive into APOC NLP

April 07, 2022

APOC NLP


準備


以下の材料を用意します。

なお、今回の作業はmacOS/Intelで行っています。

  1. PC
    • ターミナル (Terminal)
    • Webブラウザー
  2. インターネット回線
    • 設定するだけなので繋がればOK
  3. アカウント作成に必要なもの
    • 下記のうち1つ
      • Googleのアカウント
      • メールアドレス

データ作成


データを作成する

CREATE (:Article {
  uri: "https://en.wikipedia.org/wiki/Demon_Slayer:_Kimetsu_no_Yaiba",
  body: "Tanjiro Kamado is a kind-hearted and intelligent boy who lives with his family in the mountains. Tanjiro and his sister Nezuko were the sole survivors of the incident, with Nezuko being transformed into a demon, but still surprisingly showing signs of human emotion and thought."
});

CREATE (:Article {
  uri: "https://en.wikipedia.org/wiki/Tanjiro_Kamado",
  body: "Tanjiro Kamado is a fictional character and the main protagonist in Koyoharu Gotouge's manga Demon Slayer: Kimetsu no Yaiba. Tanjiro is a teenager who goes on a quest to restore the humanity of his sister, Nezuko, who was turned into a demon after his family was killed by Muzan Kibutsuji following an attack that resulted in the death of his other relatives."
});
MATCH (a:Article {uri: "https://en.wikipedia.org/wiki/Demon_Slayer:_Kimetsu_no_Yaiba"})
CALL apoc.nlp.gcp.entities.stream(a, {
  key: $apiKey,
  nodeProperty: "body"
})
YIELD value
UNWIND value.entities AS entity
RETURN entity;
MATCH (a:Article {uri: "https://neo4j.com/blog/pokegraph-gotta-graph-em-all/"})
CALL apoc.nlp.gcp.entities.stream(a, {
  key: $apiKey,
  nodeProperty: "body"
})
YIELD value
UNWIND value.entities AS entity
MERGE (e:Entity {name: entity.name})
SET e.type = entity.type
MERGE (a)-[:ENTITY]->(e)
MATCH (a:Article)
WITH collect(a) AS articles
CALL apoc.nlp.gcp.entities.graph(articles, {
  key: $apiKey,
  nodeProperty: "body",
  writeRelationshipType: "ENTITY",
  scoreCutoff: 0.01
})
YIELD graph AS g
RETURN g;

Profile picture

Written by Koji Annoura who lives and works in Fukuoka Japan. You should follow them on Twitter