【问题标题】:How do I relate items in schema.org?如何关联 schema.org 中的项目?
【发布时间】:2011-12-06 10:52:58
【问题描述】:

假设我有一个关于一个人找工作的简单 HTML 页面:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>New Job for John Doe</title>
    </head>
    <body>
        <h1>New Job for John Doe</h1>
        <p>This week John Doe accepted an offer to become a Software Engineer at MITRE.  John graduated from MIT in 2005 with a BS in Computer Science.  He previously worked at a small company near Boston.  Blah, blah, blah.</p>
        <p>The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.  The MITRE Corporation has two principal locations: Bedford, Massachusetts, and McLean, Virginia.  Blah, blah, blah.</p>
    </body>
</html>

如果我使用 schema.org 词汇表添加语义数据,它可能如下所示:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>New Job for John Doe</title>
    </head>
    <body>
        <h1>New Job for John Doe</h1>
        <p itemscope itemtype="http://schema.org/Person">This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor">MITRE</span>.  John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science.  He previously worked at a small company near Boston.  Blah, blah, blah.</p>
        <p itemscope itemtype="http://schema.org/Corporation">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.  The MITRE Corporation has two principal locations: <span itemprop="location">Bedford, Massachusetts</span>, and <span itemprop="location">McLean, Virginia</span>.  Blah, blah, blah.</p>
    </body>
</html>

第一段显然是关于人 John Doe,第二段是关于公司 The MITRE Corporation。但第一段中的“MITRE”与第二段中的“The MITRE Corporation”相同。如何使用 schema.org 明确声明它们是相同的?

【问题讨论】:

    标签: html vocabulary microdata schema.org


    【解决方案1】:

    //更新:Schema.org 扩展了他们的 perso schema 规范

    显然,Person 与 Company 相关,因此您可以做的就是通过“person´s” itemprop “affiliation”在人和组织之间建立关系 所以我所做的是用 itemscope itemtype="Person" 包装段落,并通过添加 itemprop"affiliation" 和 itemscope itemtype="Organization" 来扩展模式人,所以现在有了语义关系,这个人隶属于组织。 我还添加了带有 itemprop="name" 的元标记,因为它需要满足“Person”规范

    <!DOCTYPE HTML>
    <html>
    <head>
        <meta charset="utf-8">
        <title>New Job for John Doe</title>
    </head>
    <body>
    <div itemscope itemtype="http://schema.org/Person">
        <h1>New Job for John Doe</h1>
    <meta itemprop="name" content="John Doe" />
        <p>This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor">MITRE</span>.  John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science.  He previously worked at a small company near Boston.  Blah, blah, blah.</p>
        <p itemprop="affiliation" itemscope itemtype="http://schema.org/Organization">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.  The MITRE Corporation has two principal locations: <span itemprop="location">Bedford, Massachusetts</span>, and <span itemprop="location">McLean, Virginia</span>.  Blah, blah, blah.</p>
    </div> <!-- closing Schema "Person" -->
    </body>
    </html>
    

    你可以把它放到谷歌丰富的 sn-p 测试工具中,我猜输出就是你要找的东西

    Item 
    type:   http://schema.org/person
    property:   
    name:   John Doe
    jobtitle:   Software Engineer
    worksfor:   MITRE
    alumniof:   MIT
    affiliation: Item 1
    
    
    Item 1
    type:   http://schema.org/organization
    property:   
    location:   Bedford, Massachusetts
    location:   McLean, Virginia
    

    【讨论】:

      【解决方案2】:

      我第一次尝试回答我自己的问题是使用 itemref 属性,如下所示:

      <p itemscope itemtype="http://schema.org/Person">
          This week John Doe accepted an offer to become a
          <span itemprop="jobTitle">Software Engineer</span>
          at <span itemprop="worksFor" itemref="TheMitreCorporation">MITRE</span>.
          John graduated from <span itemprop="alumniOf">MIT</span>
          in 2005 with a BS in Computer Science.
          He previously worked at a small company near Boston.  Blah, blah, blah.
      </p>
      
      <p itemscope itemtype="http://schema.org/Corporation" id="TheMitreCorporation">
          The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.
          The MITRE Corporation has two principal locations:
          <span itemprop="location" itemscope itemtype="http://schema.org/Place">
              <span itemprop="name">Bedford, Massachusetts</span>
          </span>, and
          <span itemprop="location" itemscope itemtype="http://schema.org/Place">
              <span itemprop="name">McLean, Virginia</span>
          </span>. Blah, blah, blah.
      </p>
      

      但是一些评论者正确地指出这不是该属性的正确使用。

      所以这是我的第二次尝试:改用itemid 属性。公司名称的两个实例都有一个itemscopeitemtype 属性,并且它们都设置为相同的itemid 值,即一个URL。

      spec says:“如果指定了 itemid 属性,则它的值必须是一个可能被空格包围的有效 URL……一个项目的全局标识符是其元素的 itemid 属性的值,如果它有一,相对于指定属性的元素进行解析...不得在没有同时指定 itemscope 属性和 itemtype 属性的元素上指定 itemid 属性。”

      <p itemscope itemtype="http://schema.org/Person">This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor" itemscope itemtype="http://schema.org/Corporation" itemid="http://www.mitre.org">MITRE</span>.  John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science.  He previously worked at a small company near Boston.  Blah, blah, blah.</p>
      <p itemscope itemtype="http://schema.org/Corporation" itemid="http://www.mitre.org">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.  The MITRE Corporation has two principal locations: <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">Bedford, Massachusetts</span></span>, and <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">McLean, Virginia</span></span>.  Blah, blah, blah.</p>
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多