GraphGists

目标

本GraphGist的目的是整理图书信息。此想法可用于图书管理系统、内容推荐系统等。首先,将展示设计的数据模型。接下来,加载示例数据并运行示例Cypher查询以展示此模型的应用。

数据模型

Book(图书)概念是模型的核心,其他实体和关系共同描述它。模型包含以下域和关系

表1. 域
属性 示例

Book

标题 - 原文

Harry Potter and the Philosopher’s Stone

图书系列

标题

Harry Potter

关键词

名称

magic, students

类型

名称

fantasy, mystery

Person

名,姓

J. K. Rowling

Translation

标题 - 译文)

Harry Potter à l’Ecole des sorciers

Language

名称

English, French

EBook

链接

linkToHarryPotterEBook

Review

链接

linkToReview1, linkToReview2

Movie

标题

Harry Potter and the Philosopher’s Stone

Time

世纪, 年, 季节, 日期

1997,

Place

大陆, 国家, 城市名称, 地址

US, UK

出版社

名称

Bloomsbury Publishing, Arthur A. Levine Books

表2. 关系
起始节点 关系 结束节点 示例

Book

IS_PART_OF

图书系列

Harry Potter and the Philosopher’s Stone IS_PART_OF (order no: 1) Harry Potter

Book

DESCRIBED_BY

关键词

Harry Potter and the Philosopher’s Stone DESCRIBED_BY magic

Book

OF_TYPE

类型

Harry Potter and the Philosopher’s Stone OF_TYPE fantasy

Book

WRITTEN_BY

Person

Harry Potter and the Philosopher’s Stone WRITTEN_BY J. K. Rowling

Book

TRANSLATED_TO

Translation

Harry Potter and the Philosopher’s Stone TRANSLATED_TO Harry Potter A L’Ecole des Sorciers

Book

HAS_ORIGINAL_LANGUAGE

Language

Harry Potter and the Philosopher’s Stone HAS_ORIGINAL_LANGUAGE English

Translation

OF_LANGUAGE

Language

Harry Potter A L’Ecole des Sorciers OF_LANGUAGE French

Translation

MADE_BY

Person

Harry Potter A L’Ecole des Sorciers MADE_BY Jean-François Ménard

Book

HAS_E_VERSION

EBook

Harry Potter and the Philosopher’s Stone HAS_E_VERSION eHarryPotter

Translation

HAS_E_VERSION

EBook

Harry Potter A L’Ecole des Sorciers HAS_E_VERSION eHarryPotterInFrench

Book

HAS_REVIEW

Review

Harry Potter and the Philosopher’s Stone HAS_REVIEW review1

Book

MADE_INTO

Movie

Harry Potter and the Philosopher’s Stone MADE_INTO Harry Potter and the Philosopher’s Stone

Book

WHEN_ACTION

Time

Harry Potter and the Philosopher’s Stone WHEN_ACTION XX century

Book

WHEN_PUBLISHED

Time

Harry Potter and the Philosopher’s Stone WHEN_PUBLISHED 1997

Book

WHERE_ACTION

Place

Harry Potter and the Philosopher’s Stone WHERE_ACTION Londyn

Book

WHERE_PUBLISHED

Place

Harry Potter and the Philosopher’s Stone WHERE_PUBLISHED UK

Book

PUBLISHED_BY

出版社

Harry Potter and the Philosopher’s Stone PUBLISHED_BY Bloomsbury Publishing

图谱数据上传

首先,将测试数据添加到数据库中。

上传的数据包含以下图书及其信息

  • 哈利·波特与魔法石由J. K. Rowling用英语写作,是哈利·波特系列的一部分。它于1997年由Bloomsbury Publishing和Arthur A. Levine Books出版。这本书已被翻译成多种语言,包括法语。还有一部基于该书的电影。故事发生在当代伦敦。描述该电影的关键词:magic, students。

  • 偷书贼由Markus Zusak用英语写作。它于2005年由Picador在澳大利亚首次出版。故事发生在XX世纪的纳粹德国。还有一部基于该书的电影。描述该电影的关键词:death, students, judaism。

  • 汤姆·索亚历险记由Mark Twain用英语写作。它于1876年由American Publishing Company在美国出版。故事发生在美国。描述该电影的关键词:boy, children's novel, change, psychology。

应用

以下数据模型和查询可以根据多种条件检索图书信息。

查找类型为“小说”的图书

MATCH (b:Book)-[:OF_TYPE]->(:Genre{name:'novel'}),
       b-[:DESCRIBED_BY]->(k:Keyword)
RETURN b.title AS book, collect(k.name) as keywords
ORDER BY b.title

查找由“Bloomsbury Publishing”出版的图书

MATCH (b:Book)-[:PUBLISHED_BY]->(:PublishingHouse{name:'Bloomsbury Publishing'}),
       b-[:WHEN_PUBLISHED]->(t:Time),
       b-[:WHERE_PUBLISHED]->(p:Place)
RETURN b.title AS book, t.year as time, p.country as place
ORDER BY t DESC, b.title

查找故事发生在德国XX世纪的图书

MATCH (b:Book)-[:WHERE_ACTION]->(:Place{country:'Germany'}),
       b-[:WHEN_ACTION]->(:Time{century:'XX'})
RETURN b.title AS book
ORDER BY b.title

查找所有被拍成电影的图书

MATCH (b:Book)-[:MADE_INTO]->(m:Movie),
       b-[:WHEN_PUBLISHED]->(t:Time)
WHERE m.title<>""
RETURN b.title AS book, t.year as time
ORDER BY t.year DESC, b.title

查找图书的外语译本

MATCH (b:Book)-[:TRANSLATED_TO]->(t:Translation)
RETURN DISTINCT b.title AS book, collect(t.title) as translations
ORDER BY b.title

总结

所呈现的模型是可扩展的:可以添加其他内容的信息,例如与特定图书对应的电影、有声书、电脑游戏。这些整理好的信息是一个关于图书的知识库,可用于搜索特定内容或内容推荐。可以添加经典社交网络形式的额外层,以实现根据阅读品味为人们建立画像、寻找相似的人(基于他们的阅读品味)等功能。该模型还可用于证明,与关系型数据库相比,该领域的图谱建模和查询要容易得多。

© . All rights reserved.