How do I relate items in schema.org?

2020-02-09 08:54发布

问题:

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?

回答1:

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


回答2:

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>