美文网首页
Freebase Datadump结构初探(一)

Freebase Datadump结构初探(一)

作者: Jarkata | 来源:发表于2020-12-30 15:09 被阅读0次

    本文为转载,原文链接:https://blog.csdn.net/hagen666/article/details/54838454

    Freebase 简介

    首先简单说一下Freebase是什么,Freebase乍看上去类似Wikipedia,可以在上面浏览到许多信息条目,其成员可以在上面进行条目创作。与Wikipedia不同的是,Freebase采用结构化的数据形式,而Wikipedia则不是。Freebase已经关闭了,只能通过Data Dump来访问了。有关Freebase的介绍:http://www.ruanyifeng.com/blog/2007/05/freebase_com.html

    FreeBase包含3层结构:Domain-->Type-->Instance(Topic)。举例来说People-->Person-->somebody。

    一个Domain中包含一个或多个Type,Type包含多个Property,它的Property来源有三:

    1. 自身Property。
    2. included type:当前Type集成了included type中所有的Property。这个类似于继承的概念,但又不同于继承,它可以随意删除included type。
    3. incoming properties:其它type的某些Property。

    一个Instance(Topic)属于一个或多个Type,所以该Instance(Topic)就包含这些Type的Property,每个Property的值为另一个Instance(Topic),通过填充Property的值,实现了对该Instance(Topic)的描述,同时也实现了不同Instance(Topic)之间的关联。

    一个Instance(Topic)页面包含:自身介绍(/common/topic类型的各项属性,每个Topic都继承了这个Type;另外还包含初始创建该Topic的Type的Property值),所属其它Type及该Type中的Property值。

    Freebase Data Dump 格式

    目前,Freebase官网提供N-Triple RDF格式的数据压缩包的下载,整个压缩包30G,解压后300G+。下载后,可以用压缩软件解压,也可以通过编程工具(比如Java的GzipInuputStream)边读取边解压。

    解压后发现数据按行组织,每一行都是一个三元组(一行一个Triple):

    下面举个例子:

    <http://rdf.freebase.com/ns/m.0qjjmlt> <http://rdf.freebase.com/ns/type.object.name> “川浦正大”@ja .
    

    从左至右依次是subject(主语)、Predicate(谓词)、Object(宾语或者客体)。
    w3c上对RDF格式是这样解释的[1]:

    the subject, which is an IRI or a blank node
    the predicate, which is an IRI
    the object, which is an IRI, a literal or a blank node

    简单来说,就是主语可以是一个IRI或者是blank node,谓词可以是一个IRI,宾语可以是IRI、blanknode、或者文字。

    关于IRI是什么,其全称是Internationalized Resource Identifiers,即国际化资源定位符,可以认为是扩展的URI,不仅可以使用英文,Unicode字符集都可以使用。[2]

    至于文字(Literal),w3c给出的例子如下[3]:

    <http://example.org/show/218> <http://www.w3.org/2000/01/rdf-schema#label> "That Seventies Show"^^<http://www.w3.org/2001/XMLSchema#string> . 
    # literal with XML Schema string datatype
    <http://example.org/show/218> <http://www.w3.org/2000/01/rdf-schema#label> "That Seventies Show" . # same as above
    <http://example.org/show/218> <http://example.org/show/localName> "That Seventies Show"@en . # literal with a language tag
    <http://example.org/show/218> <http://example.org/show/localName> "Cette Série des Années Septante"@fr-be .  
    # literal outside of ASCII range with a region subtag
    <http://example.org/#spiderman> <http://example.org/text> "This is a multi-line\nliteral with many quotes (\"\"\"\"\")\nand two apostrophes ('')." .
    <http://en.wikipedia.org/wiki/Helium> <http://example.org/elements/atomicNumber> "2"^^<http://www.w3.org/2001/XMLSchema#integer> . # xsd:integer
    <http://en.wikipedia.org/wiki/Helium> <http://example.org/elements/specificGravity> "1.663E-4"^^<http://www.w3.org/2001/XMLSchema#double> .     # xsd:double
    

    这些三元组的最后一元都是文字,可以看到有一部分文字后面有^^,其后跟随的是一个IRI(dataType IRI),表示该文字的类型(identifying a datatype that determines how the lexical form maps to a literal value[1]),有一部分后面有@,其后跟随的是文字的语言(language tag).

    网址[3]中还给出了RDF triple扩展的巴科斯范式的文法,有兴趣的朋友可以点击文末的链接看,为了有一个形象的认识,这里仅贴非终结符部分:

    [1] ntriplesDoc ::= triple? (EOL triple)* EOL?

    [2] triple ::= subject predicate object '.'
    [3] subject ::= IRIREF | BLANK_NODE_LABEL
    [4] predicate ::= IRIREF
    [5] object ::= IRIREF | BLANK_NODE_LABEL | literal
    [6] literal ::= STRING_LITERAL_QUOTE ('^^' IRIREF | LANGTAG)?

    Freebase数据结构

    先来简单了解一下Freebase数据结构:

    整个Freebase数据库是一张大图,每个结点都使用type/object定义,边使用type/link定义。

    每个条目称之为一个Topic,一个Topic往往由很多属性。比如对于某一个人,可能有姓名、性别、出生日期、个人经历、职业等等属性。

    不同的Topic分属不同的type,一个Type下的topic,其属性类型往往是大致相同的。比如"姚明",在Freebase库中的MID是m.01jzhl,在数据库中有条目(忽略前缀):

    <m.01jzhl>  <type.object.type> <people.person>
    

    <person.person>是一个type,属于该type的topic在freebase中还有以property:

    <m.01jzhl>  <people.person.profession>  <m.01445t>  .
    <m.01jzhl>  <people.person.date_of_birth>   "1980-09-12"^^<http://www.w3.org/2001/XMLSchema#date>   .
    <m.01jzhl>  <people.person.education>   <m.0n1k91v> .
    <m.01jzhl>  <people.person.profession>  <m.02h664x> .
    <m.01jzhl>  <people.person.nationality> <m.0d05w3>  .
    <m.01jzhl>  <people.person.parents> <m.0g5bnz5> .
    <m.01jzhl>  <people.person.place_of_birth>  <m.06wjf>   .
    <m.01jzhl>  <people.person.spouse_s>    <m.0j688yq> .
    <m.01jzhl>  <people.person.parents> <m.0g5bnyy> .
    <m.01jzhl>  <people.person.gender>  <m.05zppz>  .
    <m.01jzhl>  <people.person.weight_kg>   "141.0" .
    

    再比如,姚明还是一位运动员:

    <m.01jzhl>  <type.object.type>  <sports.pro_athlete>    .
    
    

    与运动员相关的,他有如下条目:

    <sports.pro_athlete>    <type.type.instance>    <m.01jzhl>  .
    <m.01jzhl>  <sports.pro_athlete.teams>  <m.0j_ny44> .
    <m.01jzhl>  <sports.pro_athlete.teams>  <m.0j2m__w> .
    <m.01jzhl>  <sports.pro_athlete.teams>  <m.0t_6b7s> .
    <m.01jzhl>  <type.object.type>  <sports.pro_athlete>    .
    <m.01jzhl>  <sports.pro_athlete.career_start>   "1997"^^<http://www.w3.org/2001/XMLSchema#gYear>    .
    <m.01jzhl>  <sports.pro_athlete.sports_played_professionally>   <m.0c55c2z> .
    <m.01jzhl>  <sports.pro_athlete.teams>  <m.0j_ny44> .
    <m.01jzhl>  <sports.pro_athlete.teams>  <m.0j2m__w> .
    <m.01jzhl>  <sports.pro_athlete.teams>  <m.0t_6b7s> .
    <m.01jzhl>  <sports.pro_athlete.sports_played_professionally>   <m.0c55c2z> .
    

    同时,多个type属于一个domain,这就构成了domain->type->topic这样的三级关系。

    Freebase属性

    这里还搞的不是很懂,具体可参考[5],里面谈论了很多和Freebase属性相关的问题。

    参考

    [1]w3c RDF1,1 Concept https://www.w3.org/TR/rdf11-concepts/#section-triples
    [2]IRI 百度百科 http://baike.baidu.com/item/iri
    [3]RDF 1.1 N-Triples:https://www.w3.org/TR/n-triples/
    [4]Basic Concepts:http://developers.google.com/freebase/guide/basic_concepts
    [5]Freebase.com语义数据库浅析 http://blog.sina.com.cn/s/blog_600791e00100hd4m.html

    同时再附两篇博客:
    Freebase 介绍:http://www.ruanyifeng.com/blog/2007/05/freebase_com.html
    Freebase再研究 http://www.ruanyifeng.com/blog/2008/04/freebase_reloaded.html

    相关文章

      网友评论

          本文标题:Freebase Datadump结构初探(一)

          本文链接:https://www.haomeiwen.com/subject/vpfqoktx.html