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

发布于 2024-12-09 15:54:29 字数 2058 浏览 0 评论 0原文

假设我有一个关于一个人找工作的简单 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”与第二段中的“The MITRE Corporation”相同。如何使用 schema.org 显式声明它们是相同的?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方的巷 2024-12-16 15:54:29

//更新:Schema.org扩展了他们的个人模式规范,

显然个人与公司相关,所以你可以做的是在个人和组织之间建立一个关系“person´s”itemprop“affiliation”
所以我所做的就是用 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

//Update : Schema.org expanded their specifications of perso schema

obviously the Person is related to the Company, so what you can do is to make a relation between person and organisation wit "person´s" itemprop "affiliation"
so what i did is wrapping the paragraphs with itemscope itemtype="Person" and expanded the Schema Person by adding itemprop"affiliation" and itemscope itemtype="Organization" so now theres a semantic relation, the person is affiliated with the organization.
I also added meta tag with itemprop="name" because it´s needed to fulfill "Person" specifications

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

You can put this into google rich snippet testing tool and i guess the Output is what you where looking for

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
梦巷 2024-12-16 15:54:29

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文