Fetch Japan Airports and create nodes in neo4j
出版:2022-08-22
I would like to know more about Japan, such as visualizing the relationship and nodes of the First-Class
Airports in Japan, and the city it located and the prefecture.
With the following cypher query, my curiosity can be fulfilled.
MATCH (p:Prefecture)<-[:IN]-(c1:City)-[:HAS]->(a:Airport)-[:IS]->(c2:Classification)
WHERE c2.name = 'First-class'
RETURN p, c1, a, c2
Convert the table in the List of airports in Japan in Wikipedia to json, and import them to the neo4j database.
The airport node should contain the name
, ICAO
, IATA
, node
properties and link to the municipality
(city), a new node with the label Classification
(First-class
, Second-class
, Third-class
, Other
, Military
).
So we use axios
to fetch the data, and the code should be like this:
const createAirports = async (ctx) => {
const url = `https://www.wikitable2json.com/api/List_of_airports_in_Japan?table=0&keyRows=1`
const { data } = await axios.get(url)
const airports = data[0].map((airport) => {
const object = airport;
object.cities = object.Municipality.split(' / ')
object.name = object['Airport name']
object.classification = object['Classification']
object.prefecture = object['Prefecture'].split(' / ')
return object;
})
const result = await ctx.session.run(geography.createAirports, { airports })
logger.info(`Airports created`)
return data
}
And we can use the following cypher to create the airport node, relate the airport to the city:
UNWIND $airports as airport
MERGE (a:Airport{name: airport.name})
SET a.ICAO = airport.ICAO,
a.IATA = airport.IATA
WITH a, airport
MERGE (c1:Classification{name: airport.classification})
MERGE (a)-[:IS]->(c1)
WITH a, airport
UNWIND airport.cities as city
UNWIND airport.prefecture as prefecture
MATCH (c2:City{en: city})-[:IN]->(p:Prefecture)
WHERE p.en = toLower(prefecture)
MERGE (c2)-[:HAS]->(a)
The source code is available in calpa - japan - Github.
Calpa 是一個四天工作的系統架構師,日常幫助客戶構建一站式網站應用,手機應用,雲端架構。
2023 年 9 月,Calpa 收到來自國內外不同 Web3 團隊的邀請,參加韓國的 KBW 2023 和新加坡的 TOKEN 2049 活動。十二月份,Calpa 將參加台北區塊鏈週的 Hackathon 比賽。
Calpa 擅長運用各種前沿技術,包括 TypeScript、React.js 和 Vue.js,開發具有 Responsive Web Design 的網站。另外,他透過運用 aws-cdk 和 TypeScript 技術的融合,實現了基於雲端的「基礎即代碼」(Infrastructure as Code)部署策略,建立了多套高效且具有可伸縮性的全端架構。
同時,Calpa 積極參與各個社群,活躍於香港和台灣的開源社區,分享前沿知識。他曾在 2019 年的香港開源大會中擔任重要講者,為聽眾提供寶貴的工作經驗和深刻見解。此外,Calpa 在 GitHub 上公開分享了個人博客程式碼,已獲得超過 300 顆星星和 60 個分支。
如果您對系統架構有任何問題,或需要進一步交流,請隨時聯絡 Calpa,他非常歡迎討論。