How do I relate Job (jobTitle) to Organization (worksFor) in Schema.org markup?

依然范特西╮ 提交于 2021-02-07 06:08:20

问题


Under a Person schema, I want to associate each job title with its respective organization. This is in a resume-like setting, so there are many jobs and many organizations.

Here's an actual example of some code from my project (content clipped + changed):

<div itemscope itemtype="http://schema.org/Person">
  …
  <p><!--list of jobs-->
    <span itemprop="jobTitle">Job 1</span>, 
    <span itemprop="jobTitle">Job 2</span>, and 
    <span itemprop="jobTitle">Job 3</span>
  </p>
  <p><!--list of places worked for-->
    <span itemprop="worksFor">Company A</span> and
    <span itemprop="worksFor">Company B</span>
  </p>
</div>

That returns a schema like this from https://search.google.com/structured-data/testing-tool/:

@type   Person
jobTitle    Job 1
jobTitle    Job 2
jobTitle    Job 3
worksFor    
    @type   Organization
    name    Company A
worksFor    
    @type   Organization
    name    Company B

Let's say I want Jobs 1 & 2 to be part of Company A and Job 3 to be with Company B. How would I express that so it has a clean hierarchy in the Schema?

I understand I have the option of itemref (from questions like How do I relate items in schema.org?) but I can't figure out how to engineer a way to make the jobTitle reference the Organization (worksFor).


回答1:


I don't believe this can happen between Schema and how Google (or at least the Structured Data tool) interprets it. I could be wrong, but I think the problem is that both jobTitle and worksFor apply to person. So Google will relate both of those attributes to the person but not necessarily relate the two attributes to each other.

It could also be that I'm missing something in my approach and that this is actually possible. I wanted to post my answer to at least guide you or someone with better experience in the right direction (or confirm my suspicions). I have two approaches, I believe the Microdata approach appears right in the tool but is wrong. I think the JSON-LD approach is correct but does not display properly in the Structured Data tool.

Microdata approach

If you can modify the DOM to an extent, you could use meta tags to nest an organization within the person. Although the Structured data tool shows results as I think you would want, I'm not convinced the data would really be related because the employee isn't really attached to the id:

<div itemscope itemtype="http://schema.org/Person" id="person1">
  <p><!--list of jobs-->
    <span>Job 1</span>, 
    <span>Job 2</span>, and 
    <span>Job 3</span>
  </p>
  <p><!--list of places worked for-->
    <span itemscope itemprop="worksFor" itemtype="http://schema.org/Organization">
        <span itemprop="name">Company A</span>
        <span itemscope itemprop="employee" itemref="person1" itemtype="http://schema.org/Person">
            <meta itemprop="jobTitle" content="Job 1">
        </span>
    </span> and
    <span itemscope itemprop="worksFor" itemtype="http://schema.org/Organization">
        <span itemprop="name">Company B</span>
        <span itemscope itemprop="employee" itemref="person1" itemtype="http://schema.org/Person">
            <meta itemprop="jobTitle" content="Job 2">
            <meta itemprop="jobTitle" content="Job 3">
        </span>
    </span>
  </p>
</div>

Which returns:

@type = Person

worksFor    
    @type = Organization
    name = Company A

    employee    
        @type = Person
        jobTitle = Job 1

worksFor    
    @type = Organization
    name = Company B

    employee    
        @type = Person
        jobTitle = Job 2
        jobTitle = Job 3

I approached this by nesting Person > Organization > Employee (Person) > JobTitle. I added a blank span for employee with meta tags so you can maintain the same front end styles.

My concern with this approach is that the Employee under each Organization would be disconnected from the parent Person. I used an id on the parent and used itemref in each Employee to point to that parent id but I'm not sure if that is truly supported, or maybe it being nested is enough (doubtful).

JSON-LD Approach

I think the JSON-LD approach properly relates the person to the Organization, but Google's tool in the end will push the jobTitle back to the person basically giving you the same results. There might be a better way to relate the data though.

<script type="application/ld+json">
      {
        "@context": {
            "@vocab": "http://schema.org/",
            "id": "@id",
            "graph": "@graph",
            "type": "@type"
        },
        "graph" : [
            {
                "type": "Person",
                "id": "Person1",
                "name": "John Smith",
                "worksFor" : [
                    {
                        "id": "CompanyA"
                    }, 
                    {
                        "id": "CompanyB"
                    }
                ]
            }, 
            {
                "type": "Organization",
                "id": "CompanyA",
                "name": "Company A",
                "employees": [
                    {
                        "@id" : "Person1",
                        "jobTitle" : ["Job 1", "Job 2"]
                    }
                ]
            }, 
            {
                "type": "Organization",
                "id": "CompanyB",
                "name": "Company B",
                "employees": [
                    {
                        "@id" : "Person1",
                        "jobTitle" : "Job 3"
                    }
                ]
            }
        ]
      }
</script>

Which unfortunately returns:

@type : http://www.example.com/Person
@id : http://www.example.com/Person1
name : John Smith
jobTitle : Job 1
jobTitle : Job 2
jobTitle : Job 3

worksFor    
    @type : http://www.example.com/Organization
    @id : http://www.example.com/CompanyA
    name : Company A

worksFor    
    @type : http://www.example.com/Organization
    @id : http://www.example.com/CompanyB
    name : Company B

While the Structured Data tool presents one option above in a way that looks right and one that looks wrong but seems right, it's tough to say how Google is truly relating the data. It may also just be that Schema/Data tool assumes the relation at a more basic level, where normally someone won't have multiple job titles across multiple organizations.. but I'm just speculating at that point.

Bottom line is - I feel the problem is that Organization can only be listed under a person as worksFor. jobTitle can only be under a person and not under Organization. You can relate Person under an Organization as employee, but that seems to just push jobTitle back to the related person anonymously in the structured data tool. The Structured Data Tool has known to have some flaws against Google documentation in the past, so I'm not sure you can't rely 100% on what you see from it.




回答2:


After some struggling to link jobs to companies in my online resume, I implemented something looking like this.

For reference : schema.org OrganizationRole

<div itemscope itemtype="https://schema.org/Person">
  <div itemprop="worksFor" itemscope itemtype="https://schema.org/EmployeeRole">
    <div itemprop="worksFor" itemscope itemtype="https://schema.org/Corporation">
      <span itemprop="name">[COMPANY]</span>
    </div>
    <span itemprop="roleName">[JOB]</span>
  </div>
  <p itemprop="name">[NAME]</p>
</div>

You can test your microdata here (google Structured Data Testing Tool)



来源:https://stackoverflow.com/questions/39128187/how-do-i-relate-job-jobtitle-to-organization-worksfor-in-schema-org-markup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!