How to manipulate Json-ld? - semantic-web

I've got this json-ld:
{ "#id": "http://www.example.com/john-doe",
"#type": "http://xmlns.com/foaf/0.1/Person",
"http://xmlns.com/foaf/0.1/name": "John Doe",
"http://xmlns.com/foaf/0.1/age": {
"#value": "42",
"#kind": "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"},
"http://xmlns.com/foaf/0.1/knows" : [
{ "#id": "http://www.example.com/charlie-brown" },
{ "#id": "http://www.example.com/jane-doe" }
]
}
I have to write the context so that the below json-ld is valid.
{ "#context" : "context to write....",
"#id": "john-doe",
"#type": "person",
"name": "John Doe",
"age": "42",
"knows": ["charlie-brown", "jane-doe"]
}
I've write a solution but it's incomplete, and I can't figure out how to write a full solution, hope that someone can help me.

You have to use framing to get a result close to your requirements.
See this answer for a Java full code example, How to convert RDF to pretty nested JSON using java rdf4j .
See also this answer that contains some extra tipps in addition JSON-LD to normal JSON
Use this link for an example in json-ld playground. This is how your document with embedded #context would look like:
{
"#context": {
"name": {
"#id": "http://xmlns.com/foaf/0.1/name"
},
"age": {
"#id": "http://xmlns.com/foaf/0.1/age"
},
"knows": {
"#id": "http://xmlns.com/foaf/0.1/knows",
"#container": "#set"
}
},
"#id": "john-doe",
"#type": "person",
"name": "John Doe",
"age": "42",
"knows": [
"charlie-brown",
"jane-doe"
]
}
This is, how the frame would look like
{
"#context": {
"name": {
"#id": "http://xmlns.com/foaf/0.1/name"
},
"age": {
"#id": "http://xmlns.com/foaf/0.1/age"
},
"knows": {
"#id": "http://xmlns.com/foaf/0.1/knows",
"#container": "#set"
}
}
}
This will render to
{
"#context": {
"name": {
"#id": "http://xmlns.com/foaf/0.1/name"
},
"age": {
"#id": "http://xmlns.com/foaf/0.1/age"
},
"knows": {
"#id": "http://xmlns.com/foaf/0.1/knows",
"#container": "#set"
}
},
"#graph": [
{
"#id": "john-doe",
"#type": "https://json-ld.org/playground/person",
"age": "42",
"knows": [
"charlie-brown",
"jane-doe"
],
"name": "John Doe"
}
]
}

Related

Problems with Dynamic Schema Markup

I'm having trouble with making my schema markup dynamic, I've formatted it with the guidelines but very time I validate the code, I get an error saying
"JSON-LD
Syntax error: value, object or array expected."
I'm unsure of how to fix it. Heres the code below. Thanks in advance
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Product",
"name": document.querySelector("#product-title").innerText,
"description": document.querySelector("#product-description").innerText,
"image": document.querySelector("#product-image").src,
"url": window.location.href,
"sku": document.querySelector("#product-sku").innerText,
"brand": document.querySelector("#product-brand").innerText,
"offers": {
"#type": "Offer",
"availability": "http://schema.org/" + document.querySelector("#product-availability").innerText,
"price": document.querySelector("#product-price").innerText,
"priceValidUntil": "2019-12-31",
"priceCurrency": "Currency Code",
"url": window.location.href
},
"aggregateRating": {
"#type": "AggregateRating",
"bestRating": "5",
"ratingValue": "5",
"reviewCount": "3"
},
"review": [
{
"#type": "Review",
"author": document.querySelector("#review-author-1").innerText,
"reviewRating": {
"#type": "Rating",
"bestRating": "5",
"ratingValue": document.querySelector("#review-rating-1").innerText,
"worstRating": "1"
},
"reviewBody": document.querySelector("#review-body-1").innerText
},
{
"#type": "Review",
"author": document.querySelector("#review-author-2").innerText,
"reviewRating": {
"#type": "Rating",
"bestRating": "5",
"ratingValue": document.querySelector("#review-rating-2").innerText,
"worstRating": "1"
},
"reviewBody": document.querySelector("#review-body-2").innerText
},
{
"#type": "Review",
"author": document.querySelector("#review-author-3").innerText,
"reviewRating": {
"#type": "Rating",
"bestRating": "5",
"ratingValue": document.querySelector("#review-rating-3").innerText,
"worstRating": "1"
},
"reviewBody": document.querySelector("#review-body-3").innerText
}
]
}
</script>
I've tried changing format and all sort of things.

# in url into schema markup and #graph in schema

What is meant by the use of hashtags in the url in schema?
#id": "https://www.example.com/#Organization
or
#id": "https://www.example.com/#/schema/Organization/1
What exactly does a graph do in a schema?
"#context": "https://schema.org",
"#graph": [
{
"#type": "Organization",
"#id": "https://www.example.com/#/schema/Organization/1",
"url": "https://www.example.com/",
"name": "Example organization name"
},
{
"#type": "WebSite",
"#id": "https://www.example.com/#/schema/WebSite/1",
"url": "https://www.example.com/",
"name": "Example website",
"publisher": {
"#id": "https://www.example.com/#/schema/Organization/1"
}
},
{
"#type": "WebPage",
"#id": "https://www.example.com/example-page/test/",
"url": "https://www.example.com/example-page/test/",
"name": "Example page name",
"description": "Example page description",
"isPartOf": {
"#id": "https://www.example.com/#/schema/WebSite/1"
thanks

Google Reviews Snippet VS Aggregate Ratings

I have a few questions about what happens if I add both "aggregate reviews" and "review snippets" schema to a webpage.
Will the aggregate number of "votes" and the aggregate vote rating be displaced by the number and average rating of the review snippets?
Is it possible for both to appear at the same time on SERP, with the aggregate votes & average score (1-5) appearing above the review snippets?
Review Snippet Sample:
<script type="application/ld+json">
{
"#context": "https://schema.org/",
"#type": "Product",
"brand": {
"#type": "Brand",
"name": "Penguin Books"
},
"description": "The Catcher in the Rye is a classic coming-of-age story: an story of teenage alienation, capturing the human need for connection and the bewildering sense of loss as we leave childhood behind.",
"sku": "9780241984758",
"mpn": "925872",
"image": "http://www.example.com/catcher-in-the-rye-book-cover.jpg",
"name": "The Catcher in the Rye",
"review": [{
"#type": "Review",
"reviewRating": {
"#type": "Rating",
"ratingValue": "5"
},
"author": {
"#type": "Person",
"name": "John Doe"
},
"reviewBody": "I really enjoyed this book. It captures the essential challenge people face as they try make sense of their lives and grow to adulthood."
},
{
"#type": "Review",
"reviewRating": {
"#type": "Rating",
"ratingValue": "1"
},
"author": {
"#type": "Person",
"name": "Jane Doe"
},
"reviewBody": "I really didn't care for this book."
}],
"aggregateRating": {
"#type": "AggregateRating",
"ratingValue": "88",
"bestRating": "100",
"ratingCount": "20"
},
"offers": {
"#type": "Offer",
"url": "https://example.com/offers/catcher-in-the-rye",
"priceCurrency": "USD",
"price": "5.99",
"priceValidUntil": "2020-11-05",
"itemCondition": "https://schema.org/UsedCondition",
"availability": "https://schema.org/InStock",
"seller": {
"#type": "Organization",
"name": "eBay"
}
}
}
</script>
Aggregate Ratings Sample
<script type="application/ld+json">
{
"#context": "https://schema.org/",
"#type": "Product",
"name": "Executive Anvil",
"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"brand": {
"#type": "Thing",
"name": "ACME"
},
"aggregateRating": {
"#type": "AggregateRating",
"ratingValue": "4.4",
"ratingCount": "89"
},
"offers": {
"#type": "AggregateOffer",
"lowPrice": "119.99",
"highPrice": "199.99",
"priceCurrency": "USD"
}
}
</script>

How can i write a query om SPARQL to fetch the details of class and then details of iots subclass?

For example in the following json i need to fetch Catalog and Artifacts .I must be able to fetch catalog by artifact and artifact by catalog.While Artifact is not a direct child of Catalog,here is my jsonld.
{ "#context": { "ids": "https://w3id.org/idsa/core/", "idsc": "https://w3id.org/idsa/code/" }, "#type": "ids:Root", "#id": "http://component.abc.xyz.domainname.de", "ids:resourceCatalog": [ { "#type": "ids:ResourceCatalog", "#id": "https://w3id.org/idsa/autogen/resourceCatalog/897434ab-8638-4cf5-81da-7e1ea8ccd850", "ids:offeredResource": [ { "#type": "ids:Resource", "#id": "https://w3id.org/idsa/autogen/resource/ffcc840c-f7a9-4465-aee7-7d9f3ce39d27", "ids:representation": [ { "#type": "ids:Representation", "#id": "https://w3id.org/idsa/autogen/representation/3ef065fd-c985-4d5a-af8f-59f875c88931", "ids:instance": [ { "#type": "ids:Artifact", "#id": "http://component.abc.xyz.domainname.de/artifact/json-jsonld.txt", "ids:fileName": "json-jsonld.txt", "ids:creationDate": { "#value": "2020-12-17T18:27:44.158+01:00", "#type": "http://www.w3.org/2001/XMLSchema#dateTimeStamp" }, "ids:byteSize": 694 } ] } ] }, { "#type": "ids:Resource", "#id": "https://w3id.org/idsa/autogen/resource/cc011e72-c1e3-4754-94b2-30a45ca967a3", "ids:representation": [ { "#type": "ids:Representation", "#id": "https://w3id.org/idsa/autogen/representation/343c0a82-e2d9-4453-a16b-93c23d172733", "ids:instance": [ { "#type": "ids:Artifact", "#id": "http://component.abc.xyz.domainname.de/artifact/demoSample-desc.jsonId", "ids:fileName": "demoSample-desc.jsonId", "ids:creationDate": { "#value": "2020-11-05T12:44:00.788+01:00", "#type": "http://www.w3.org/2001/XMLSchema#dateTimeStamp" }, "ids:byteSize": 1338 } ] }]}]}]}

Combining Local business with Service & Area served schema

When I insert this code in the structured data testing tool I am only getting the first schema to show up. I can switch the order of the Local business and service w/ area served but when I do that only one of them shows up in the tool. The same thing happens when I try to split the two up and get them individually.
Working with json-ld scripts:
<script type="application/ld+json">
{
"#context": "https://schema.org",
"#type": "ProfessionalService",
"name": "Sebastian River Exterminating",
"image": "http://sebastianriverexterminating.com/images/extermination-logo-sebastian-fl.png",
"#id": "",
"url": "http://sebastianriverexterminating.com/",
"telephone": "7722289969",
"address": {
"#type": "PostalAddress",
"streetAddress": "124 Salazar Lane",
"addressLocality": "Sebastian",
"addressRegion": "FL",
"postalCode": "32958",
"addressCountry": "US"
},
"geo": {
"#type": "GeoCoordinates",
"latitude": 27.7600115,
"longitude": -80.50620599999999
},
"openingHoursSpecification": {
"#type": "OpeningHoursSpecification",
"dayOfWeek": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
],
"opens": "08:00",
"closes": "18:00"
},
"sameAs": "https://www.facebook.com/SebastianRiverExterminatingFL/timeline"
}
{
"#context": "http://schema.org",
"#type": "Service",
"serviceType": "Exterminator",
"additionalType": "https://en.wikipedia.org/wiki/Pest_control",
"areaServed": [
{
"#type": "City",
"name": "Sebastian",
"#id": "https://en.wikipedia.org/wiki/Sebastian,_Florida"
},
{
"#type": "City",
"name": "Roseland",
"#id": "https://en.wikipedia.org/wiki/Roseland,_Florida"
}
]}
</script>
That is not valid json or json-ld. You can only add one object to each script. e.g.
<script type="application/ld+json">
{
...
}
</script>
You can't list objects like you did.
One way around the issue is to add each into their own script tag.
Another is to use #graph to add them as an array inside an object. e.g.
<script type="application/ld+json">
{
"#graph": [
{
...
},
{
...
}
]
}
</script>
I believe you should use a sameAs not an #id in this case, since you are providing a reference for the search engine. also, I don't believe #id is a valid property of areaServed