假设我有一个关于找工作的人的简单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,第二段是关于一家公司,MITRE公司。但第一段中的“MITRE”与第二段中的“MITRE公司”相同。如何使用schema.org明确声明这些是同一个?
答案 0 :(得分:4)
//更新:Schema.org扩展了他们的perso schema规范
显然,这个人与公司有关系,所以你能做的就是在人与组织之间建立一种“人”的关系“从属关系” 所以我所做的是用itemscope itemtype =“Person”包装段落,并通过添加itemprop“affiliation”和itemscope itemtype =“Organization”扩展Schema Person,所以现在有一个语义关系,这个人与组织有关系。 我还添加了带有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 :(得分: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
属性。公司名称的两个实例都具有itemscope
和itemtype
属性,并且它们都设置为相同的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>