了解 schema.org JSON 表示的正确数据类型和结构

Understanding the right data type & structure for schema.org JSON representation

我一直在研究 schema.org,这似乎是一个 public 项目的好主意,该项目为几种常见类型的数据实体(人、地点、事物、书籍)的模式建模、电影等...)。

我无法理解有关数据类型和结构的两个概念

我将使用 Recipe 架构作为示例,特别是该页面底部的(简化的)原始 JSON 表示:

{
  "@context": "http://schema.org",
  "@type": "Recipe",
  "author": "John Smith",
  "name": "Mom's World Famous Banana Bread",
  "nutrition": {
    "@type": "NutritionInformation",
    "calories": "240 calories",
    "fatContent": "9 grams fat"
  },
  "recipeIngredient": [
    "3 or 4 ripe bananas, smashed",
    "1 egg",
    "3/4 cup of sugar"
  ],
}
  1. author 字段应为 Organization or Person, but the above JSON simply represents it as a string ("John Smith"). On the other hand, the nutrion field is of type NutritionInformation 类型,但它表示为完全结构化的对象(即不仅仅是字符串)。在什么情况下我们应该使用前者而不是后者?如果不需要更多细节,是否假设每个对象都可以选择性地提炼成一个简单的字符串?

  2. recipeIngredient 字段是一个 list/array 项目,但规范文档中没有任何内容提到它应该是一个列表。它也可以只是一个元素吗?我们如何知道何时使用列表而不是单个元素?

预期类型

每个 Schema.org 属性 一个 Text¹、一个 URL¹ 或一个 Role 值,即使它们是未在 "Values expected to be one of these types" 下列出。

引自data model documentation

We also expect that often, where we expect a property value of type Person, Place, Organization or some other subClassOf Thing, we will get a text string, even if our schemas don't formally document that expectation. In the spirit of "some data is better than none", search engines will often accept this markup and do the best we can. Similarly, some types such as Role and URL can be used with all properties, and we encourage this kind of experimentation amongst data consumers.

如果 Text 未列为预期类型,通常最好提供一种预期类型而不是 Text。在您的示例中,使用预期类型至少会传达 authorPerson 还是 Organization,并且您有机会提供 @id价值,它允许其他人对这个食谱的作者做出陈述,或者理解两个作者是同一个人。

多个值

每个 属性 多个值。这是 Schema.org(JSON-LD、Microdata、RDFa)支持的所有三种语法的核心功能。

, you should not put multiple values into one property value, not least because no delimiter is defined. So, not using an array for recipeIngredient 是不正确的,因为这个 属性 期望 "A single ingredient".


¹ 由于 TextURLDataType 的子类型,因此不应指定这些类型。如果是字符串值,就是Text类型;如果它是一个 @id 值,它的类型是 URL.