Schema.org Adapter
    Preparing search index...

    Class SDOAdapter

    An SDOAdapter is an instance of the library itself that holds its own settings and vocabularies (specified by the user). Based on these internal settings and vocabularies the SDOAdapter provides corresponding data through the methods described below (an SDOAdapter can only provide data about a vocabulary, if that vocabulary has been added to the instance). An SDOAdapter instance is created with .create(), have a look at the different settings.

    // load the library
    const { SOA } = require("schema-org-adapter");
    // create a new SDOAdapter instance, in this case with the latest schema.org vocabulary
    const mySdoAdapter = await SOA.create({schemaVersion: "latest"});
    Index

    Methods

    • This method allows the addition of vocabularies after the SDOAdapter instance has been initialized, as an alternative to the vocabulary addition during initialization. You have to pass the vocabularies either as a JSON-LD vocabularies, or as URLs pointing at such JSON-LD vocabularies. The function .constructURLSchemaVocabulary() helps you to construct URLs for the schema.org vocabulary.

      Parameters

      • vocabArray: string | Vocabulary | (string | Vocabulary)[]

        The vocabularies to add the graph. Given directly as JSON-LD or as an URL to fetch.

      Returns Promise<boolean>

      This is an async function, returns true when done.

      const vocabularyOne = require("./myVocabulary.json"); // loads a local JSON-LD vocabulary file
      const vocabularyTwo = "https://raw.githubusercontent.com/semantifyit/schemaorg/main/data/releases/13.0/schemaorg-all-https.jsonld"; // URL pointing to the schema.org vocabulary

      // add the two vocabularies to the SDOAdapter instance
      await mySdoAdapter.addVocabularies( [vocabularyOne, vocabularyTwo] );
    • Creates a URL pointing to the Schema.org vocabulary for the wished version. This URL can then be added to the SDOAdapter to retrieve the Schema.org vocabulary. The Schema.org version listing at https://raw.githubusercontent.com/schemaorg/schemaorg/main/versions.json is used for this function. Check https://schema.org/docs/developers.html for more information. The internal cache is used for this function. If you want to reset the cache, use the global library function .fetchSchemaVersions().

      Parameters

      • version: string = "latest"

        The wished Schema.org vocabulary version for the resulting URL (e.g. "5.0", "3.7", or "latest"). default: "latest"

      Returns Promise<string>

      The URL to the Schema.org vocabulary


      const schemaUrl = await mySdoAdapter.constructURLSchemaVocabulary("13.0");
      // creates following URL pointing to the schema.org vocabulary version 13.0
      "https://raw.githubusercontent.com/semantifyit/schemaorg/main/data/releases/13.0/schemaorg-all-https.jsonld"
    • Creates an array of Class instances of all class terms (excluding Enumerations) known to this SDOAdapter. Depending on the amount of classes, this method could require a lot of resources. If you only need a list of all classes (IRIs), use the method .getListOfClasses() instead.

      Parameters

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Class[]

      An array of Class instances representing all class terms

      // creates an array with Class instances for all classes known to mySdoAdapter
      const allClassesArray = mySdoAdapter.getAllClasses();
    • Creates an array of DataType instances of all data-type terms known to this SDOAdapter. Depending on the amount of data-types, this method could require a lot of resources. If you only need a list of all data-types (IRIs), use the method .getListOfDataTypes() instead.

      Parameters

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns DataType[]

      An array of DataType instances representing all data-type terms

      // creates an array with DataType instances for all data-types known to mySdoAdapter
      const allDataTypesArray = mySdoAdapter.getAllDataTypes();
    • Creates an array of EnumerationMember instances of all enumeration member terms known to this SDOAdapter. Depending on the amount of enumeration members, this method could require a lot of resources. If you only need a list of all enumeration members (IRIs), use the method .getListOfEnumerationMembers() instead.

      Parameters

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns EnumerationMember[]

      An array of EnumerationMember instances representing all enumeration member terms

      // creates an array with EnumerationMember instances for all enumeration members known to mySdoAdapter
      const allEnumerationMembersArray = mySdoAdapter.getAllEnumerationMembers();
    • Creates an array of Enumeration instances of all enumeration terms known to this SDOAdapter. Depending on the amount of enumerations, this method could require a lot of resources. If you only need a list of all enumerations (IRIs), use the method .getListOfEnumerations() instead.

      Parameters

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Enumeration[]

      An array of Enumeration instances representing all enumeration terms

      // creates an array with Enumeration instances for all enumerations known to mySdoAdapter
      const allEnumerationsArray = mySdoAdapter.getAllEnumerations();
    • Creates an array of Property instances of all property terms known to this SDOAdapter. Depending on the amount of properties, this method could require a lot of resources. If you only need a list of all properties (IRIs), use the method .getListOfProperties() instead.

      Parameters

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Property[]

      An array of Property instances representing all property terms

      // creates an array with Property instances for all properties known to mySdoAdapter
      const allPropertiesArray = mySdoAdapter.getAllProperties();
    • Creates an array of term instances (corresponding to their term-types) of all vocabulary Terms known to this SDOAdapter. Depending on the amount of terms, this method could require a lot of resources. If you only need a list of all terms (IRIs), use the method .getListOfTerms() instead.

      Parameters

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns (Class | Enumeration | EnumerationMember | Property | DataType)[]

      An array of term instances representing all vocabulary terms

      // creates an array with term instances for all terms known to mySdoAdapter
      const allTermsArray = mySdoAdapter.getAllTerms();
    • Creates a Class instance for the given IRI. If the given IRI belongs to an Enumeration, an Enumeration instance is returned.

      Parameters

      • id: string

        The identification string of the wished Class, can be an IRI (absolute or compact) or a label

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Class

      The Class instance for the given IRI

      // creates a Class instance for schema:Hotel
      const classInstance = mySdoAdapter.getClass("schema:Hotel");
    • Creates a DataType instance for the given IRI.

      Parameters

      • id: string

        The identification string of the wished DataType, can be an IRI (absolute or compact) or a label

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns DataType

      The DataType instance for the given IRI

      // creates a DataType instance for schema:Number
      const dataTypeInstance = mySdoAdapter.getDataType("schema:Number");
    • Returns the default filter specified for this SDOAdapter, if any

      Returns undefined | FilterObject

      The default filter of this SDOAdapter, if any

      const defaultFilter = mySdoAdapter.getDefaultFilter();
      
    • Creates an Enumeration instance for the given IRI.

      Parameters

      • id: string

        The identification string of the wished Enumeration, can be an IRI (absolute or compact) or a label

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Enumeration

      The Enumeration instance for the given IRI

      // creates an Enumeration instance for schema:DayOfWeek
      const enumerationInstance = mySdoAdapter.getEnumeration("schema:DayOfWeek");
    • Creates an EnumerationMember instance for the given IRI.

      Parameters

      • id: string

        The identification string of the wished EnumerationMember, can be an IRI (absolute or compact) or a label

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns EnumerationMember

      The EnumerationMember instance for the given IRI

      // creates an EnumerationMember instance for schema:Monday
      const enumerationMemberInstance = mySdoAdapter.getEnumerationMember("schema:Monday");
    • Returns the latest version identifier for the schema.org vocabulary. The internal cache is used for this function. If you want to reset the cache, use the global library function .fetchSchemaVersions().

      Returns Promise<string>

      The latest version of the schema.org vocabulary

      const latestSchemaVersion = await mySdoAdapter.getLatestSchemaVersion();
      // get the latest schema.org vocabulary version identifier
      "13.0"
    • Creates an array of IRIs of all class terms (excluding Enumerations) known to this SDOAdapter.

      Parameters

      • OptionalparamObj: ParamObjIRIList

        an optional parameter object that filters and formats the result

      Returns string[]

      An array of IRIs representing all class terms

      const allClassesArray = mySdoAdapter.getListOfClasses();
      // creates an array with IRIs of all class terms known to mySdoAdapter
      [
      'schema:CollegeOrUniversity',
      'schema:Hotel',
      'schema:Patient',
      ...
      ]

      const allClassesArrayAbsoluteIRIs = mySdoAdapter.getListOfClasses({outputFormat: "Absolute"});
      // creates an array with absolute IRIs
      [
      'https://schema.org/CollegeOrUniversity',
      'https://schema.org/Hotel',
      'https://schema.org/Patient',
      ...
      ]
    • Creates an array of IRIs of all data-type terms known to this SDOAdapter.

      Parameters

      • OptionalparamObj: ParamObjIRIList

        an optional parameter object that filters and formats the result

      Returns string[]

      An array of IRIs representing all data-type terms

      const allDataTypesArray = mySdoAdapter.getListOfDataTypes();
      // creates an array with IRIs of all data-type terms known to mySdoAdapter
      [
      'schema:Text',
      'schema:URL',
      'schema:Date',
      ...
      ]

      const allDataTypesArrayAbsoluteIRIs = mySdoAdapter.getListOfDataTypes({outputFormat: "Absolute"});
      // creates an array with absolute IRIs
      [
      'https://schema.org/Text',
      'https://schema.org/URL',
      'https://schema.org/Date',
      ...
      ]
    • Creates an array of IRIs of all enumeration member terms known to this SDOAdapter.

      Parameters

      • OptionalparamObj: ParamObjIRIList

        an optional parameter object that filters and formats the result

      Returns string[]

      An array of IRIs representing all enumeration member terms

      const allEnumerationMembersArray = mySdoAdapter.getListOfEnumerationMembers();
      // creates an array with IRIs of all enumeration member terms known to mySdoAdapter
      [
      'schema:PublicHolidays',
      'schema:UnofficialLegalValue',
      'schema:SoundtrackAlbum',
      ...
      ]

      const allEnumerationMembersArrayAbsoluteIRIs = mySdoAdapter.getListOfEnumerationMembers({outputFormat: "Absolute"});
      // creates an array with absolute IRIs
      [
      'https://schema.org/PublicHolidays',
      'https://schema.org/UnofficialLegalValue',
      'https://schema.org/SoundtrackAlbum',
      ...
      ]
    • Creates an array of IRIs of all enumeration terms known to this SDOAdapter.

      Parameters

      • OptionalparamObj: ParamObjIRIList

        an optional parameter object that filters and formats the result

      Returns string[]

      An array of IRIs representing all enumeration terms

      const allEnumerationsArray = mySdoAdapter.getListOfEnumerations();
      // creates an array with IRIs of all enumeration terms known to mySdoAdapter
      [
      'schema:DayOfWeek',
      'schema:GenderType',
      ...
      ]

      const allEnumerationsArrayAbsoluteIRIs = mySdoAdapter.getListOfEnumerations({outputFormat: "Absolute"});
      // creates an array with absolute IRIs
      [
      'https://schema.org/DayOfWeek',
      'https://schema.org/GenderType',
      ...
      ]
    • Creates an array of IRIs of all property terms known to this SDOAdapter.

      Parameters

      • OptionalparamObj: ParamObjIRIList

        an optional parameter object that filters and formats the result

      Returns string[]

      An array of IRIs representing all property terms

      const allPropertiesArray = mySdoAdapter.getListOfProperties();
      // creates an array with IRIs of all property terms known to mySdoAdapter
      [
      'schema:name',
      'schema:url',
      'schema:openingHours',
      ...
      ]

      const allPropertiesArrayAbsoluteIRIs = mySdoAdapter.getListOfProperties({outputFormat: "Absolute"});
      // creates an array with absolute IRIs
      [
      'https://schema.org/name',
      'https://schema.org/url',
      'https://schema.org/openingHours',
      ...
      ]
    • Creates an array of IRIs of all vocabulary Terms known to this SDOAdapter.

      Parameters

      • OptionalparamObj: ParamObjIRIList

        an optional parameter object that filters and formats the result

      Returns string[]

      An array of IRIs representing all vocabulary terms

      const allTermsArray = mySdoAdapter.getListOfTerms();
      // creates an array with IRIs of all terms known to mySdoAdapter
      [
      'schema:CollegeOrUniversity',
      'schema:name',
      'schema:Monday',
      ...
      ]

      const allTermsArrayAbsoluteIRIs = mySdoAdapter.getListOfTerms({outputFormat: "Absolute"});
      // creates an array with absolute IRIs
      [
      'https://schema.org/CollegeOrUniversity',
      'https://schema.org/name',
      'https://schema.org/Monday',
      ...
      ]
    • Creates a Property instance for the given IRI.

      Parameters

      • id: string

        The identification string of the wished Property, can be an IRI (absolute or compact) or a label

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Property

      The Property instance for the given IRI

      // creates a Property instance for schema:name
      const propertyInstance = mySdoAdapter.getProperty("schema:name");
    • Creates a corresponding term instance for the given IRI, depending on its term-type.

      Parameters

      • id: string

        The identification string of the wished Term, can be an IRI (absolute or compact) or a label

      • Optionalfilter: FilterObject

        The filter to be applied on the result

      Returns Class | Enumeration | EnumerationMember | Property | DataType

      The term instance for the given IRI

      // creates a Class instance for schema:Hotel - using the compact IRI for identification is the recommended approach
      const classInstance = mySdoAdapter.getTerm("schema:Hotel");

      // creates a Property instance for schema:openingHours (handling of http/https is based on the setting "equateVocabularyProtocols")
      const propertyInstance = mySdoAdapter.getTerm("https://schema.org/openingHours");

      // creates an Enumeration instance for schema:DayOfWeek - Using the label for identification is risky when you have multiple vocabularies that may have equal labels
      const enumerationInstance = mySdoAdapter.getTerm("DayOfWeek");
    • Returns an object with key-value pairs representing the vocabulary indicators (used in compact IRIs) and their namespaces, that are used in this SDOAdapter. Vocabularies that are perceived as standard namespaces (e.g. in the context of schema.org or sdo-adapter), and not as vocabularies for the content of SDOAdapter are omitted by default, you can change this behaviour by passing the argument omitStandardVocabs: false.

      Parameters

      • omitStandardVocabs: boolean = true

      Returns Record<string, string>

      An object containing key-value pairs representing the used vocabulary namespaces

      // assume mySdoAdapter has been initialized with schema.org and another example vocabulary
      const usedVocabularies = mySdoAdapter.getVocabularies(); // same as mySdoAdapter.getVocabularies(true)
      // creates an object with vocabulary indicators as keys, and their vocabulary namespaces as values
      {
      "schema": "https://schema.org/",
      "ex": "https://example-vocab.ex/"
      }
    • Overwrites the default filter for this SDOAdapter. The default filter is not supposed to change often, and should be set during the creation of a SDOAdapter instance.

      Parameters

      • OptionaldefaultFilter: FilterObject

        The default filter for this SDOAdapter (pass no parameter to reset the filter)

      Returns void

      mySdoAdapter.setDefaultFilter({
      schemaModuleExclude: "attic",
      isSuperseded: false
      });