搜索食谱

  1. 文本限制
  2. 语言限制
  3. 架构限制条件
  4. 元架构限制条件
  5. 评分和排名
  6. 其他限制

本页列出了各种食谱,介绍了如何使用 Search Service 来限制搜索查询。

文本限制

Freebase 实体的文本数据首先来自其名称和别名,然后来自其键和其他文本属性,最后来自其 Wikipedia 锚数据(如果该实体已与特定语言的 Wikipedia 主题进行协调)。

文本限制是特定于语言的;目前支持 18 种语言。英语的覆盖范围最广,是默认语言。

如需查看当前支持的所有语言代码的列表,请访问以下页面:

https://www.googleapis.com/freebase/v1/search?help=langs&indent=true

文本约束是通过 query 参数指定的。其语言通过 lang 参数指定。例如:

query: "gore"
query: "gore" lang: "fr"
query: "gore" lang: "de"

在编入索引期间,系统会以特定于语言的方式对文本数据进行归一化处理。例如,在英语中,文本会转换为小写,并移除重音符号。在查询时,系统会对查询文本执行相同的特定于语言的归一化操作。例如:

query: "beyoncé"
query: "beyonce"

有多个参数可控制文本限制条件的匹配方式。将 prefixed 参数设置为 true 会触发仅对名称和别名进行前缀匹配(对其他文本数据进行常规匹配)。例如:

query: "bob dy" prefixed: true

stemmed 设置为 true 会仅对名称和别名触发词干匹配(对其他文本数据触发常规匹配)。词干匹配可用于覆盖因复数或其他语法形式而产生的特定于语言的后缀差异。例如:

query: "potatos" stemmed: true

使用英文双引号 (“”) 括住查询文本会触发词组匹配。查询中的文本令牌必须在匹配实体的文本数据中相邻显示。例如:

query: "\"to be or not to be\""

使用 namealiastype 参数可匹配名称中包含您要匹配的字词的人员和人员实体。例如:

filter: "(all name:gore alias:gore type:/people/person)"

同样,以下示例仅匹配具有相应 alias/people/person 实体,而匹配其 name

filter: "(all (not name:gore) alias:gore type:/people/person)"

除了指定应匹配哪些文本字段之外,还可以在操作数和文本字段之间插入以下修饰符之一,以指定应如何进行匹配:

  • {word}:要求字符串中的字词与文档中相应文本字段中的字词相匹配。(默认)
  • {phrase}:要求字词在文档的相应文本字段中按相同顺序相邻出现。
  • {full}:与 {phrase} 类似,但还要求短语与文本字段完全匹配,而不仅仅是在文本字段内匹配。换句话说,完全匹配。

例如,如需查找 Marc Broussard 的音乐单曲 Home,请使用如下过滤条件:

filter: "(all type:/music/single name{full}:home /music/track/artist:"Marc Broussard")"

语言限制

如文本限制中所述,lang 参数用于指定要使用哪些语言归一化规则将文本转换为查询令牌。查询的语言也会影响结果排名,因为 freebase-search 会从相应语言的维基百科获取特定于语言的相关性信号。

目前,我们支持 9 种语言:英语 (en)、西班牙语 (es)、法语 (fr)、德语 (de)、意大利语 (it)、葡萄牙语 (pt)、中文 (zh)、日语 (ja) 和韩语 (ko)。英语的覆盖范围最广,是默认语言。

同时使用多种语言进行搜索

lang 参数接受以英文逗号分隔的语言代码列表,这些语言代码会导致搜索以所有指定的语言进行,结果按所列的第一种语言进行排名,并以列表中第一种具有实体名称的语言显示。

例如:

以下示例分别使用德语和法语搜索德语字词“Sonnenblume”。它会对结果进行排名,并以法语显示结果:

query: "Sonnenblume" lang: "fr,de"

以下英文搜索查询会搜索语言为韩语的电影,并显示其韩语名称。查询的英文部分是 expressed_by 限制中的“korean”一词:

filter: "(all expressed_by:korean type:/film/film)" lang: "ko,en"

架构限制

架构限制条件通过 typedomain 参数指定。type 对应于实体的 /type/object/type 属性值。

例如,以下搜索会将搜索范围限制为仅搜索人物:

query: "gore" type: "/people/person"

domain 对应于实体的所有 /type/object/type 值的 /type/type/domain 值。

例如,以下搜索仅限于 /film 网域中的法语实体:

query: "babar" domain: "/film" lang: "fr"

您还可以使用单个 Freebase 属性来过滤查询。例如,以下搜索会将搜索范围限定为来自加拿大的人员:

 query "john" filter: "(all type:/people/person /people/person/nationality:"Canada")"

元架构限制

元架构约束通过语义谓词过滤实体。这些谓词是更高级别的概念,由描述类似语义关系的 Freebase 属性集合构建而成。

元架构限制条件是使用 filter 参数操作数与实体名称或 MID 限制条件组合指定的。

支持的元架构过滤条件操作数

Freebase Search 支持以下元架构过滤条件操作数。点击表格中的链接或使用 Freebase 搜索示例应用,试用每个示例。

操作数名称 示例
abstraction “fettuccine dishes”(意大利宽面条菜肴)试试看。
filter: "(all abstraction:fettuccine)"
abstraction_of “西方堡垒机车的类别”试试看。
filter: "(all abstraction_of:"Western Bulwark")"
adaptation “歌剧《茶花女》改编自”试试看。
filter: "(all adaptation_of:"La Traviata")"
administered_by “戛纳电影节奖项”试试看。
filter: "(all type:awards administered_by:cannes)"
administers “Who runs the Synapse newspaper?”(谁在运营 Synapse 报纸?)试试看。
filter: "(all administers:synapse)"
appears_in “魔笛中的角色”试试看。
filter: "(all appears_in:"magic flute")"
“魔笛中的人物”试试看。
filter: "(all appears_in:"Die Zauberflöte")" lang: "de"
broader_than “空客 319 所属的飞机系列”试试看。
filter: "(all broader_than:"Airbus A319")"
category “法国女演员”试试看。
filter: "(all category:female origin:france notable:actor)"
“french actresses”(变体)试试看。
filter: "(all category:female origin:france practitioner_of:actor)"
“加利福尼亚或法国火山”试试看。
filter: "(all category:volcano (any part_of:california part_of:france))"

“意大利面”试试看。

filter: "(all category:pasta)"
center “以旧金山为枢纽的航空公司”试试看。
filter: "(all type:airline center:"San Francisco")"
“旧金山和亚特兰大设有枢纽的航空公司”试试看
filter: "(all type:airline center:"San Francisco" center:atlanta)"
“以旧金山为中心的报纸”试试看
filter: "(all type:/book/newspaper center:/m/0d6lp)"
center_for “旧金山 49 人队的体育设施”试试看。
filter: "(all center_for:"san francisco 49ers")"
certification “维姆·文德斯执导的 R 级电影”试试看。
filter: "(all type:/film/film contributor:wenders certification:r)"
character “以帕帕基诺为角色的作品”试试看。
filter: "(all character:papageno)"
child “比尔·克林顿的父母”试试看。
filter: "(all child:"bill clinton")"
contributed_to “是谁为《银翼杀手》做出了贡献?”试试看。
filter: "(all contributed_to:"Blade Runner")"
contributor “史蒂文·斯皮尔伯格的电影”试试看
filter: "(all type:/film/film contributor:"Steven Spielberg")"
“史蒂文·斯皮尔伯格的电影”,使用 MID 而不是贡献者的姓名。(试试看。
filter: "(all type:/film/film contributor:/m/06pj8)"
“哈里森·福特出演的电影”试试看
filter: "(all type:/film/film contributor:"Harrison Ford")"
created “谁创作了《丧钟为谁而鸣》”试试看。
filter: "(all created:"for whom the bell tolls")"
created_by “Google 软件”试试看。
filter: "(all notable:software created_by:google)"
discovered “镭的发现者”试试看。
filter: "(all discovered:radium)"
discovered_by “居里的发现”试试看。
filter: "(all discovered_by:curie)"
distributed_by “NPR shows”(NPR 节目)试试看。
filter: "(all type:show distributed_by:npr)"
exhibited “‘不法之徒’是在哪里上映的?”试试看。
filter: "(all exhibited:"down by law")"
exhibited_at “2010 年戛纳电影节上展出的提名作品”试试看
filter: "(all type:"nominated work" exhibited_at:"2010 Cannes Film festival")"
expressed_by "books in esperanto"试试看。
filter: "(all type:book expressed_by:esperanto)"
fictional_link “与米老鼠相关的虚构角色”试试看。
filter: "(all type:/fictional_universe/fictional_character fiction_link:"mickey mouse")"
genre “哥特式教堂”试试看。
filter: "(all category:cathedral genre:gothic)"
“Viollet-le-duc 的哥特式大教堂”试试看。
filter: "(all category:cathedral genre:gothic created_by:viollet)"
identifies “What identifies Southwest Airlines?”试试看。
filter: "(all identifies:"Southwest Airlines")"
leader “Mitch Kapor 的公司”试试看。
filter: "(all type:company leader:kapor)"
leader_of “巴黎市长”试试看。
filter: "(all title:mayor leader_of:paris)"
made_of “蜡画”试一下。
filter: "(all type:painting made_of:wax)"
means_of_demise “被处决的政治家”试试看。
filter: "(all type:politician means_of_demise:"capital punishment")"
member_of “非洲君主”试试看。
filter: "(all type:monarch member_of:africa)"
“民主党政治家和知名演员”试试看。
filter: "(all type:politician member_of:democratic notable:actor)"
narrower_than “v8 引擎的示例”试试看)。
filter: "(all type:engine narrower_than:"v8 engine")"
occurs_in “罗马尼亚使用的语言”试试看。
filter: "(all type:language occurs_in:romania)"
origin “奥地利的共和党州长”试试看。
filter: "(all title:governor member_of:republican origin:austria)"
owner “福特自有品牌”试试看。
filter: "(all type:make owner:ford)"
owns “谁拥有小牛队?”试试看。
filter: "(all owns:mavericks)"
parent “Al Gore's children”(阿尔·戈尔的孩子)试试看。
filter: "(all parent:"al gore")"
“Lisp 编程语言的后代”试试看。
filter: "(all type:/computer/programming_language parent:lisp)"
part_of “瑞典湖泊”试试看。
filter: "(all type:lake part_of:sweden)"
“2008 年夏季奥运会上的比赛”试试看
filter: "(all type:competition part_of:"2008 summer olympics")"
participant “Bowie 演唱会”试试看。
filter: "(all participant:bowie type:concert)" 
participated_in “参加过奥运会的著名奥地利滑雪运动员”试试看
filter: "(all notable:skier member_of:austria participated_in:olympics)"'
peer_of “与戈尔同行的政治家”试试看。
filter: "(all notable:politician peer_of:gore)"
permits_use_of “柴油发动机”试试看。
filter: "(all permits_use_of:diesel)"
portrayed “扮演约翰·列侬的演员”试试看。
filter: "(all notable:actor portrayed:"john lennon")"
portrayed_by “哈里森·福特饰演的角色”试试看。
filter: "(all portrayed_by:"Harrison Ford")"
practitioner_of “female african american lawyers”(非裔美国女律师)试试看。
filter: "(all category:female category:"african american" practitioner_of:lawyer)"
preceeding “sequels to The Lord of the Rings, the two Towers”(《指环王》的续集《双塔奇兵》)试试看。
filter: "(all type:/film/film preceeding:"The Lord of the Rings, the two Towers")"
produced_by “Apple 电脑”试试看。
filter: "(all type:computers produced_by:apple)"
publication “哪本书的初版是 /m/0clw238?”试试看。
filter: "(all publication:/m/0clw238)"
publication_of “La Traviata 的发行版本”试试看。
filter: "(all publication_of:"La Traviata")"
service_area “加利福尼亚州广播公司”试试看。
filter: "(all type:broadcaster service_area:california)"
status “瑞士冰川消融”试试看。
filter: "(all type:glacier status:retreating part_of:switzerland)"
subclass_of “泳衣种类”试试看。
filter: "(all subclass_of:swimwear)"
subject “有关大屠杀的电影”试试看。
filter: "(all type:film subject:holocaust)"
“有关数学的书籍”试试看。
filter: "(all type:book subject:mathematics)"
subsequent “《指环王》前传《双塔奇兵》”试试看。
filter: "(all type:/film/film subsequent:"The Lord of the Rings, the two Towers")"
succeeded_by “哪款汽车平台被 Ford B3 平台取代了?”试试看
filter: "(all succeeded_by:"ford b3 platform")"
succeeds “Who succeeded the House of Stuart ?” (Try it.)
filter: "(all succeeds:stuart)"
superclass_of “冠心病所属的类别”试试看。
filter: "(all superclass_of:"coronary heart disease")"
title “Google 工程师”试试看。
filter: "(all title:engineer member_of:google)"
tookplace_at “马伦戈战役”试试看。
filter: "(all type:battles tookplace_at:marengo)"
use_permitted_by “iPhone 支持的文件格式”试试看。
filter: "(all type:"file format" use_permitted_by:iphone)"

评分和排名

Freebase 实体的固有相关性得分(排名)是在编入索引期间计算的,是其在 Freebase 和 Wikipedia 中的入站链接数和出站链接数的函数。部分热门 Freebase 实体的热度得分由 Google 计算得出。默认情况下,在查询期间,这两个得分会合并在一起。

如果存在文本限制,系统会根据搜索索引返回的命中次数计算文本匹配得分,并将其与相关性得分相结合。

FreebaseSearch 结果始终按最终得分排序,得分最高的排在最前面。

通过评分参数,您可以控制使用哪些相关性得分组成部分来计算最终得分:

freebase:仅使用 Freebase 相关性得分。

query: "beyoncé" scoring: freebase

实体:同时使用这两个相关性得分,并将所有缺失的 Google 得分替换为 1.0。这是默认值。

query: "beyoncé" scoring: entity

schema:在查找类型、属性或网域等架构实体时使用。架构实体的链接数量的计算方式有所不同。

query: "performance" scoring: schema

其他限制

可以使用 with 或 without 参数按索引标记过滤实体。实体在编入索引期间会被标记,每个标记对应于一个或多个在搜索期间运行成本过高的 Freebase 查询:

commons 是一种标记,可用于限制架构搜索仅返回 Freebase Commons 架构。 例如,与“颜色”一词匹配的 Freebase Commons 类型

query: "color" type: "/type/type" with: "commons"

gg 是一种可用于将搜索范围限制为具有或不具有 Google 热度得分的实体的标记。

query: "1923" type: "/people/person" with: "gg"
query: "1923" type: "/people/person" without: "gg"

without 参数相当于过滤表达式中的否定 with。

query: "color" limit: 5 type: "/type/type" without: "commons"
query: "color" limit: 5 type: "/type/type" filter: "(not with:commons)"