Neo4j Okonomiyaki Workshop

September 29, 2024

お好み焼きのデータ


okonomiyaki.csv

"closed","name","kana","address","phone","open"
,"みっちゃん総本店 八丁堀本店",,"広島市中区八丁堀6-7 チュリス八丁堀1F","082-221-5438","11:30-14:30 / 17:30-21:00"
,"五エ門 胡町本店",,"広島市中区胡町3-14 アーバン胡館1F","082-249-8089","11:30-14:00 / 17:00-24:00"
,"電光石火 駅前ひろば店",,"広島市南区松原町10-1 フルフォーカスビル6F","082-568-7851","10:00-22:30"
,"長田屋",,"広島市中区大手町1-7-19","082-247-0787","10:00-20:00"
,"薬研堀 八昌","やげんぼりはっしょう","広島市中区薬研堀10-6","082-248-1776","11:00-22:00"
,"お好み焼き一銭 天満店",,"広島市西区天満町16-9-1F 平馬ビル","082-532-7355","11:00-22:00"
,"あとむ(お好み村)",,"広島市中区新天地5-13 お好み村4階","082-240-1639","11:00-24:00"
,"かずちゃん(お好み村)",,"広島市中区新天地5-13 お好み村3階","082-541-0009","11:00-23:00"
,"たけのこ(お好み村)",,"広島市中区新天地5-13 お好み村3階","082-248-1768","11:00-21:00"
,"山ちゃん(お好み村)",,"広島市中区新天地5-13 お好み村2階","082-248-3424","11:00-22:00"
,"元祖八昌","がんそはっしょう","広島県広島市中区竹屋町5-21","082-243-8776","10:30-14:30"
,"ロペズ",,"広島県広島市西区楠木町1-7-13","082-232-5277","16:30-23:00"
,"Masaru",,"広島県広島市東区光町2-14-24","050-5890-8116","11:30-14:00 / 17:30-23:00"
2024-05-24,"やまさ家",,"広島県広島市安佐南区高取北1-4-30 サンビル1F",,"11:30-13:30 / 17:30-21:00"
,"お好み焼きテツジロウ",,"広島県廿日市市大東1-7","0829-32-5518","11:30-14:00 / 17:00-22:30"

Neo4j Home/importに入れます。

LOAD CSV WITH HEADERS FROM 'file:///csv/okonomiyaki.csv' AS line
INSERT (n:Shop {
  closed: trim(line.closed),
  name: trim(line.name),
  kana: trim(line.kana),
  address: trim(line.address),
  phone: trim(line.phone),
  open: trim(line.open)
  });

検索


名前に「お好み村」が含まれているもの

MATCH (n:Shop)
WHERE n.name CONTAINS 'お好み村'
RETURN n;

住所に「お好み村」が含まれているもの

MATCH (n:Shop)
WHERE n.address CONTAINS 'お好み村'
RETURN n;

お好み村の場所を追加

INSERT (n:Place {name: 'お好み村'});

お好み村にリレーション

MATCH (s:Shop) WHERE s.address CONTAINS 'お好み村'
MATCH (p:Place {name: 'お好み村'})
INSERT (s)-[:PLACE]->(p);

「のれん」の追加


元祖八昌

MATCH (ganso:Shop {name: '元祖八昌'})
MATCH (yagen:Shop {name: '薬研堀 八昌'})
MATCH (lopez:Shop {name: 'ロペズ'})
INSERT (ganso)-[:NOREN]->(yagen)
INSERT (ganso)-[:NOREN]->(lopez);

元祖八昌

MATCH (lopez:Shop {name: 'ロペズ'})
MATCH (noren:Shop)
WHERE noren.name IN ['Masaru', 'やまさ家', 'お好み焼きテツジロウ']
INSERT (lopez)-[:NOREN]->(noren);

「のれん」の検索


のれんを分けたところは?

MATCH (n:Shop)-[:NOREN]->(:Shop)
RETURN n;

のれんを分けてもらったところは?

MATCH (:Shop)-[:NOREN]->(n:Shop)
RETURN n;

のれんを分けてもらって、そこからさらにのれんを分けたところは?

MATCH (:Shop)-[:NOREN]->(n:Shop)-[:NOREN]->(:Shop)
RETURN n;

のれんを分けてもらって、そこからのれんをしてないところは?

MATCH (:Shop)-[:NOREN]->(n:Shop)
WHERE NOT (n)-[:NOREN]->(:Shop)
RETURN n;

のれん分けの元祖は?

MATCH (tetsu:Shop {name: 'お好み焼きテツジロウ'})
MATCH (tetsu)<-[:NOREN]-{1,10}(n:Shop)
WHERE NOT (n)<-[:NOREN]-(:Shop)
RETURN n;

Profile picture

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