如何在schema.org中关联项目?

13

假设我有一个关于一个人找工作的简单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明确声明这两个实体是同一个呢?

2个回答

4

//更新:Schema.org扩展了其人物模式规范

显然,人物与公司有关联,因此您可以使用"person´s" itemprop "affiliation"来建立人物和组织之间的关系。 我所做的是将段落用itemscope itemtype="Person"包装,并通过添加itemprop"affiliation"和itemscope itemtype="Organization"扩展了Schema Person,现在存在语义关系,该人物隶属于该组织。 我还添加了meta标签,其中包含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>

您可以将此放入谷歌丰富片段测试工具中,我猜输出结果就是您所要寻找的。

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

1

我第一次尝试回答自己的问题是使用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。

规范说:“如果指定了itemid属性,则必须具有可能被空格包围的有效URL值...项目的全局标识符是其元素的itemid属性的值(如果有),相对于指定属性的元素解析...itemid属性不能在没有同时指定itemscope属性和itemtype属性的元素上指定。”

<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>

我尝试过那个了,但似乎没有实际影响到数据模型。 - robertc
2
itemref 仅用于指向 itemscope 的其他属性。因此,在这种情况下,该标签还需要是 Corporation itemtype。而具有 id="The MitreCorporation" 的标签不能是 itemscope。 - Lawrence Woodman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接