我如何关联schema.org中的项目? [英] How do I relate items in schema.org?

查看:114
本文介绍了我如何关联schema.org中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 <!DOCTYPE HTML> 
< html>
< head>
< meta charset =utf-8>
< title> John Doe的新作业< / title>
< / head>
< body>
< h1> John Doe的新作业< / h1>
< p>本周,John Doe接受了成为MITER软件工程师的提议。 John于2005年毕业于麻省理工学院,获得计算机科学学士学位。他之前曾在波士顿附近的一家小公司工作。 Blah,blah,blah。< / p>
< p> MITRE公司是一个非营利组织,专为公共利益而工作。 MITRE公司有两个主要地点:马萨诸塞州的贝德福德和弗吉尼亚州的麦克莱恩。 Blah,blah,blah。< / p>
< / body>
< / html>

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

 <!DOCTYPE HTML> 
< html>
< head>
< meta charset =utf-8>
< title> John Doe的新作业< / title>
< / head>
< body>
< h1> John Doe的新作业< / h1>

MITRE Corporation是一个非营利组织,专为公共利益而工作。 MITRE公司有两个主要位置:< span itemprop =location> Bedford,Massachusetts< / span>和< span itemprop =location&McLean,Virginia< / span> ;. Blah,blah,blah。< / p>
< / body>
< / html>

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

解决方案

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

 < p itemscope itemtype =http://schema.org/Person > 
本周,John Doe接受了成为
< span itemprop =jobTitle>软件工程师< / span>
at< span itemprop =worksForitemref =TheMitreCorporation> MITER< / span> ;.
约翰毕业于< span itemprop =alumniOf> MIT< / span> 2005年
拥有计算机科学学士学位。
他之前曾在波士顿附近的一家小公司工作。等等等等等等。
< / p>

MITRE公司是一家非营利组织,专门为公共利益而工作。
MITRE公司有两个主要地点:$ b​​ $ b< span itemprop =locationitemscope itemtype =http://schema.org/Place>
< span itemprop =name>贝德福德,马萨诸塞州< / span>
< / span>和
< span itemprop =locationitemscope itemtype =http://schema.org/Place>
< span itemprop =name>麦克莱恩,弗吉尼亚< / span>
< / span> ;.等等等等等等。
< / p>

但有些评论者正确地指出,这不适合使用此属性。

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



spec says :itemid属性,如果指定,必须具有一个值,该值是可能被空格包围的有效URL ...全局标识符一个item是它的元素的itemid属性的值(如果它有一个,相对于指定了该属性的元素进行了解析)。itemid属性不能在没有itemscope属性和itemtype的元素上指定

 < p itemcope itemtype =http://schema.org/Person>本周John Doe接受了成为< span itemprop =jobTitle>>软件工程师< / span> at< span itemprop =worksForitemscope itemtype =http://schema.org/Corporationitemid =http://www.mitre.org> MITRE< / span> ;. John毕业于< spanmplmprop =alumniOf> MIT< / span> 2005年获得计算机科学学士学位。他之前曾在波士顿附近的一家小公司工作。 Blah,blah,blah。< / p> 


Suppose I have this simple HTML page about a guy getting a job:

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

If I add semantic data using the schema.org vocabulary, it might look like this:

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

The first paragraph is obviously about the person, John Doe, and the second paragraph is about a company, The MITRE Corporation. But the "MITRE" in the first paragraph is the same as "The MITRE Corporation" in the second. How do I explicitly declare these to be one and the same using schema.org?

解决方案

My first attempt to answer my own question was to use the itemref attribute, like so:

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

But some of the commenters rightly pointed out this was not the right use of this attribute.

So here's my second attempt: Use the itemid attribute instead. Both instances of the company name are given an itemscope and itemtype attribute, and they are both set to the same itemid value, which is a URL.

The spec says: "The itemid attribute, if specified, must have a value that is a valid URL potentially surrounded by spaces...The global identifier of an item is the value of its element's itemid attribute, if it has one, resolved relative to the element on which the attribute is specified...The itemid attribute must not be specified on elements that do not have both an itemscope attribute and an itemtype attribute specified."

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

这篇关于我如何关联schema.org中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆