Revise type definition creation
Once this is done we can then update the generation of the type definitions. We want this script to:
load all of the schema.org classes - probably into a map keyed on the class name (e.g. CreativeWork)
join all of the relevant properties into their respective classes
iterate over the extensions in the schema.org-extensions folder and add any new classes
New classes should be joined in where they make sense. That is, if we were adding a class (for example) Truck an appropriate parent would be https://schema.org/Vehicle rather than https://schema.org/Thing. Not relevant for this example but something to keep in mind when creating the extensions crate
then join any properties that have been defined
finally write out a type definitions file containing an object of entity definitions keyed on the class name - see snippet following:
{
...,
"Restaurant": {
"id": "http://schema.org/Restaurant",
"name": "Restaurant",
"help": "A restaurant.",
"subClassOf": ["FoodEstablishment"],
"allowAdditionalProperties": false,
"inputs": [],
"linksTo": [],
"hierarchy": [
"Restaurant",
"FoodEstablishment",
"LocalBusiness",
"Organization",
"Place",
"Thing"
]
},
"LocalBusiness": {
"id": "http://schema.org/LocalBusiness",
"name": "LocalBusiness",
"help": "A particular physical business or branch of an organization. Examples of LocalBusiness include a restaurant, a particular branch of a restaurant chain, a branch of a bank, a medical practice, a club, a bowling alley, etc.",
"subClassOf": ["Organization", "Place"],
"allowAdditionalProperties": false,
"inputs": [
{
"id": "http://schema.org/branchOf",
"name": "branchOf",
"help": "The larger organization that this local business is a branch of, if any. Not to be confused with (anatomical)[[branch]].",
"multiple": true,
"type": ["Organization"]
},
{
"id": "http://schema.org/currenciesAccepted",
"name": "currenciesAccepted",
"help": "The currency accepted.\n\nUse standard formats: ISO 4217 currency format e.g. "USD"; Ticker symbol for cryptocurrencies e.g. "BTC"; well known names for Local Exchange Tradings Systems (LETS) and other currency types e.g. "Ithaca HOUR".",
"multiple": true,
"type": ["Text"]
},
{
"id": "http://schema.org/openingHours",
"name": "openingHours",
"help": "The general opening hours for a business. Opening hours can be specified as a weekly time range, starting with days, then times per day. Multiple days can be listed with commas ',' separating each day. Day or time ranges are specified using a hyphen '-'.\n\n* Days are specified using the following two-letter combinations: Mo, Tu, We, Th, Fr, Sa, Su.\n* Times are specified using 24:00 format. For example, 3pm is specified as 15:00, 10am as 10:00. \n* Here is an example: <time itemprop="openingHours" datetime="Tu,Th 16:00-20:00">Tuesdays and Thursdays 4-8pm</time>.\n* If a business is open 7 days a week, then it can be specified as <time itemprop="openingHours" datetime="Mo-Su">Monday through Sunday, all day</time>.",
"multiple": true,
"type": ["Text"]
},
{
"id": "http://schema.org/paymentAccepted",
"name": "paymentAccepted",
"help": "Cash, Credit Card, Cryptocurrency, Local Exchange Tradings System, etc.",
"multiple": true,
"type": ["Text"]
},
{
"id": "http://schema.org/priceRange",
"name": "priceRange",
"help": "The price range of the business, for example $$$.",
"multiple": true,
"type": ["Text"]
}
],
"linksTo": ["SpecialAnnouncement"],
"hierarchy": ["LocalBusiness", "Organization", "Place", "Thing"]
},
...,
To explain this structure:
"Restaurant": {
"id": "http://schema.org/Restaurant",
"name": "Restaurant",
"help": "A restaurant.",
"subClassOf": ["FoodEstablishment"],
"allowAdditionalProperties": false,
"inputs": [],
"linksTo": [],
"hierarchy": [
"Restaurant",
"FoodEstablishment",
"LocalBusiness",
"Organization",
"Place",
"Thing"
]
},
Consider the definition @ https://schema.org/Restaurant and note that it's a child in two different hierarchies
The key is the class name
The object definition is:
id: the URI to the definition of the thing,
name: the short name,
help: the description,
subClassOf: a link to its parent class,
showAdditionalProperties: unused,
inputs: an array of inputs defined on this class specifically - look at the localBusiness definition for an example,
linksTo: unused (I think... it's been a while),
hierarchy: the class hierarchy - perhaps the most important property as it tells describo how to find the properties that can be defined for this entity. Note that it captures both of the hierarchies.
Revise type definition creation
Once this is done we can then update the generation of the type definitions. We want this script to:
load all of the schema.org classes - probably into a map keyed on the class name (e.g. CreativeWork)
join all of the relevant properties into their respective classes
iterate over the extensions in the schema.org-extensions folder and add any new classes
New classes should be joined in where they make sense. That is, if we were adding a class (for example) Truck an appropriate parent would be https://schema.org/Vehicle rather than https://schema.org/Thing. Not relevant for this example but something to keep in mind when creating the extensions crate
then join any properties that have been defined
finally write out a type definitions file containing an object of entity definitions keyed on the class name - see snippet following:
{
...,
"Restaurant": {
"id": "http://schema.org/Restaurant",
"name": "Restaurant",
"help": "A restaurant.",
"subClassOf": ["FoodEstablishment"],
"allowAdditionalProperties": false,
"inputs": [],
"linksTo": [],
"hierarchy": [
"Restaurant",
"FoodEstablishment",
"LocalBusiness",
"Organization",
"Place",
"Thing"
]
},
"LocalBusiness": {
"id": "http://schema.org/LocalBusiness",
"name": "LocalBusiness",
"help": "A particular physical business or branch of an organization. Examples of LocalBusiness include a restaurant, a particular branch of a restaurant chain, a branch of a bank, a medical practice, a club, a bowling alley, etc.",
"subClassOf": ["Organization", "Place"],
"allowAdditionalProperties": false,
"inputs": [
{
"id": "http://schema.org/branchOf",
"name": "branchOf",
"help": "The larger organization that this local business is a branch of, if any. Not to be confused with (anatomical)[[branch]].",
"multiple": true,
"type": ["Organization"]
},
{
"id": "http://schema.org/currenciesAccepted",
"name": "currenciesAccepted",
"help": "The currency accepted.\n\nUse standard formats: ISO 4217 currency format e.g. "USD"; Ticker symbol for cryptocurrencies e.g. "BTC"; well known names for Local Exchange Tradings Systems (LETS) and other currency types e.g. "Ithaca HOUR".",
"multiple": true,
"type": ["Text"]
},
{
"id": "http://schema.org/openingHours",
"name": "openingHours",
"help": "The general opening hours for a business. Opening hours can be specified as a weekly time range, starting with days, then times per day. Multiple days can be listed with commas ',' separating each day. Day or time ranges are specified using a hyphen '-'.\n\n* Days are specified using the following two-letter combinations:
Mo,Tu,We,Th,Fr,Sa,Su.\n* Times are specified using 24:00 format. For example, 3pm is specified as15:00, 10am as10:00. \n* Here is an example:<time itemprop="openingHours" datetime="Tu,Th 16:00-20:00">Tuesdays and Thursdays 4-8pm</time>.\n* If a business is open 7 days a week, then it can be specified as<time itemprop="openingHours" datetime="Mo-Su">Monday through Sunday, all day</time>.","multiple": true,
"type": ["Text"]
},
{
"id": "http://schema.org/paymentAccepted",
"name": "paymentAccepted",
"help": "Cash, Credit Card, Cryptocurrency, Local Exchange Tradings System, etc.",
"multiple": true,
"type": ["Text"]
},
{
"id": "http://schema.org/priceRange",
"name": "priceRange",
"help": "The price range of the business, for example
$$$.","multiple": true,
"type": ["Text"]
}
],
"linksTo": ["SpecialAnnouncement"],
"hierarchy": ["LocalBusiness", "Organization", "Place", "Thing"]
},
...,
To explain this structure:
"Restaurant": {
"id": "http://schema.org/Restaurant",
"name": "Restaurant",
"help": "A restaurant.",
"subClassOf": ["FoodEstablishment"],
"allowAdditionalProperties": false,
"inputs": [],
"linksTo": [],
"hierarchy": [
"Restaurant",
"FoodEstablishment",
"LocalBusiness",
"Organization",
"Place",
"Thing"
]
},
Consider the definition @ https://schema.org/Restaurant and note that it's a child in two different hierarchies
The key is the class name
The object definition is:
id: the URI to the definition of the thing,
name: the short name,
help: the description,
subClassOf: a link to its parent class,
showAdditionalProperties: unused,
inputs: an array of inputs defined on this class specifically - look at the localBusiness definition for an example,
linksTo: unused (I think... it's been a while),
hierarchy: the class hierarchy - perhaps the most important property as it tells describo how to find the properties that can be defined for this entity. Note that it captures both of the hierarchies.