Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

schema-org-adapter

1.3.0 • Public • Published

Schema.org Adapter

Fast, simple & flexible API for the Schema.org Vocabulary (and vocabulary extensions!) for Node and Browsers

Code style in StandardJS
const SDOAdapter = require('schema-org-adapter')
 
const mySDOAdapter = new SDOAdapter()
 
const urlLatestSDO = await mySDOAdapter.constructSDOVocabularyURL('latest', 'all-layers') 
// resolves to "https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/releases/6.0/all-layers.jsonld" if 6.0 is the latest version
await mySDOAdapter.addVocabularies([urlLatestSDO])
 
let Hotel = mySDOAdapter.getClass('schema:Hotel')
Hotel.getProperties() // 117 -> ["schema:audience", "schema:checkinTime", "schema:availableLanguage", ...]
Hotel.getSuperClasses(false) //only direct superclasses: 1 -> ["schema:LodgingBusiness"]
Hotel.getSuperClasses() //5 -> ["schema:LodgingBusiness", "schema:LocalBusiness", "schema:Place", "schema:Organization", "schema:Thing"]
 
let address = mySDOAdapter.getProperty("schema:address")
address.getRanges() // 2 -> ["schema:PostalAddress", "schema:Text"]
address.getDomains(false) // only direct domains: 5 -> ["schema:Place", "schema:GeoCoordinates", "schema:GeoShape", "schema:Person", "schema:Organization"]
address.getDomains() // 229 -> ["schema:Place", "schema:Accommodation", "schema:TouristAttraction", ...]

Installation

NPM

Install the npm package:

npm install schema-org-adapter

Require the package:

const SDOAdapter = require('schema-org-adapter')

Browser

Script-include the bundled package in /dist or load via a cdn:

<script src="https://cdn.jsdelivr.net/gh/semantifyit/schema-org-adapter/dist/schema-org-adapter.min.js"></script>

Features

Empowers the semantic web: Schema.org has become the standard vocabulary for the semantic web. This Schema.org Adapter gives developers a clear API to access the schema.org vocabulary in a simple way.

Clear data model: The data model of the rdf-based, machine-readable version of Schema.org is slightly adapted (see documentation for details) to create the clear and pragmatic data model of this Schema.org Adapter.

Supports external vocabularies: The Schema.org Adapter is lightweight because it does NOT include the vocabulary data, instead it allows the user to input his needed local/remote vocabularies (JSON-LD or URL to JSON-LD). This gives the user the possibility to specify the version/part of Schema.org he/she needs, and also to use external vocabularies.

Built-in reasoning: The API of Schema.org Adapter offers functions and parameters to enable built-in reasoning on the used vocabulary-terms (e.g. resolution of properties, sub-classes, ranges, etc.)

API

JSDoc

Api documentation generated by JSDoc hosted at GitHub.

Examples

Check the examples for Node and Browser on GitHub.

Use of filters

It is possible to filter the results of some functions by passing a filter object - The filter options can be:

  • "isSuperseded": boolean (e.g. false -> only vocabulary elements that are not superseded will be returned)
  • "termType": string/Array (e.g. ['Property', 'Class'] -> only vocabulary elements that are properties or classes will be returned)
  • "fromVocabulary": string/Array (e.g. ['http://schema.org/'] -> only vocabulary elements that come from a specific vocabulary will be returned (this may be interesting if you use additional external vocabularies))
const SDOAdapter = require('schema-org-adapter')
const mySdoAdapter = new SDOAdapter()
 
//get list of classes that are NOT superseded
let listOfClasses = mySdoAdapter.getAllClasses({
  "isSuperseded": false
})

Acknowledgement

semantify.it

Made with ❤ in Tirol!

Install

npm i schema-org-adapter

DownloadsWeekly Downloads

78

Version

1.3.0

License

CC-BY-SA

Unpacked Size

965 kB

Total Files

15

Last publish

Collaborators

  • avatar
  • avatar