Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

uri - @id vs. URL for linking JSON-LD nodes

I have defined the publisher Organization on the WebSite node defined on the home page, and I now want to link to that publisher from articles on other pages. However, I also want to link to the WebSite as well, and they naturally share the same @id if I follow the advice of using the URL as the @id.

{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "@id": "http://www.example.com/",
    "url": "http://www.example.com/",
    ...
    "publisher": {
        "@type": "Organization",
        "@id": "http://www.example.com/",  <-- duplicated
        "url": "http://www.example.com/"
    }
}
{
    "@context": "http://schema.org",
    "@type": "WebPage",
    "@id": "http://www.example.com/news",
    "url": "http://www.example.com/news",
    "isPartOf": {
        "@id": "http://www.example.com/"  <-- site or publisher?
    }
    ...
    "publisher": {
        "@id": "http://www.example.com/"  <-- site or publisher?
    }
}

I assume IDs must be unique to each node, so is there a best practice for uniquifying IDs such as adding a hash?

{
    "@id": "http://www.example.com/#site",
    ...
    "publisher": {
        "@id": "http://www.example.com/#publisher",
    }
}

If that works, will processors (Google) load the @id to find the rest of the node's properties?

Related to this, is the url property found in many node types assumed to be the @id if missing? I'm ending up duplicating the full URL of the page as the @id and url for most nodes. Is that the norm?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@id (JSON-LD)

(and the same goes for itemid in Microdata, and resource in RDFa)

Each thing should get a different URI, and if multiple nodes are about the same thing, they should ideally reuse this URI. Note that these don’t have to be URLs, and they should often not be used as values for Schema.org’s url property (see section below).

Using URI fragments is a common and the most simple way to achieve this. For examples (and other ways), see my answers to these questions:

For your example case, an organization’s website, the root URL (http://www.example.com/) typically "stands for" three things:

  • the home page
  • the whole website
  • the organization

As the home page is the resource that gets retrieved, it should get the URI http://www.example.com/. The site and the organization should get their own fragments; it’s up to you to choose which ones, e.g.: http://www.example.com/#site for the site, and http://www.example.com/#organization for the organization (FWIW, Apple seems to use #organization, too.)

  • the home page:
    http://www.example.com/

  • the whole website:
    http://www.example.com/#site

  • the organization:
    http://www.example.com/#organization

(Often only two different things are involved: the document, and the thing described by the document. Then the thing often gets a fragment like #this, and in case of persons, #i, but this is just a convention.)

If that works, will processors (Google) load the @id to find the rest of the node's properties?

Google doesn’t document if they try to load those URIs.

Note that there is no requirement that these URIs actually point to a document. You could use HTTP URIs that give 404 answers, or you could use a URI scheme that doesn’t allow retrieval of documents to begin with (e.g., urn, tag, …).

url (Schema.org)

Schema.org’s url property should be used for the URLs that lead to pages that can be visited. It’s not intended as a way to provide an ID, so it’s not necessarily the same URI as provided in @id.

In your example case, you would probably use the same url value for all three things:

  • the home page:
    @id: http://www.example.com/
    url: http://www.example.com/

  • the whole website:
    @id: http://www.example.com/#site
    url: http://www.example.com/

  • the organization:
    @id: http://www.example.com/#organization
    url: http://www.example.com/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...