Options
All
  • Public
  • Public/Protected
  • All
Menu

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"});

Hierarchy

  • SDOAdapter

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.

    example
    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] );

    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.

  • constructURLSchemaVocabulary(version?: string): Promise<string>
  • 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().

    example

    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"

    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

  • 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.

    example
    // creates an array with Class instances for all classes known to mySdoAdapter
    const allClassesArray = mySdoAdapter.getAllClasses();

    Parameters

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Class[]

    An array of Class instances representing all class terms

  • 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.

    example
    // creates an array with DataType instances for all data-types known to mySdoAdapter
    const allDataTypesArray = mySdoAdapter.getAllDataTypes();

    Parameters

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns DataType[]

    An array of DataType instances representing all data-type terms

  • 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.

    example
    // creates an array with EnumerationMember instances for all enumeration members known to mySdoAdapter
    const allEnumerationMembersArray = mySdoAdapter.getAllEnumerationMembers();

    Parameters

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns EnumerationMember[]

    An array of EnumerationMember instances representing all enumeration member terms

  • 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.

    example
    // creates an array with Enumeration instances for all enumerations known to mySdoAdapter
    const allEnumerationsArray = mySdoAdapter.getAllEnumerations();

    Parameters

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Enumeration[]

    An array of Enumeration instances representing all enumeration terms

  • 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.

    example
    // creates an array with Property instances for all properties known to mySdoAdapter
    const allPropertiesArray = mySdoAdapter.getAllProperties();

    Parameters

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Property[]

    An array of Property instances representing all property terms

  • 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.

    example
    // creates an array with term instances for all terms known to mySdoAdapter
    const allTermsArray = mySdoAdapter.getAllTerms();

    Parameters

    • Optional filter: FilterObject

      The filter to be applied on the result

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

    An array of term instances representing all vocabulary terms

  • Creates a Class instance for the given IRI. If the given IRI belongs to an Enumeration, an Enumeration instance is returned.

    example
    // creates a Class instance for schema:Hotel
    const classInstance = mySdoAdapter.getClass("schema:Hotel");

    Parameters

    • id: string

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

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Class

    The Class instance for the given IRI

  • Creates a DataType instance for the given IRI.

    example
    // creates a DataType instance for schema:Number
    const dataTypeInstance = mySdoAdapter.getDataType("schema:Number");

    Parameters

    • id: string

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

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns DataType

    The DataType instance for the given IRI

  • Returns the default filter specified for this SDOAdapter, if any

    example
    const defaultFilter = mySdoAdapter.getDefaultFilter();
    

    Returns undefined | FilterObject

    The default filter of this SDOAdapter, if any

  • Creates an Enumeration instance for the given IRI.

    example
    // creates an Enumeration instance for schema:DayOfWeek
    const enumerationInstance = mySdoAdapter.getEnumeration("schema:DayOfWeek");

    Parameters

    • id: string

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

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Enumeration

    The Enumeration instance for the given IRI

  • Creates an EnumerationMember instance for the given IRI.

    example
    // creates an EnumerationMember instance for schema:Monday
    const enumerationMemberInstance = mySdoAdapter.getEnumerationMember("schema:Monday");

    Parameters

    • id: string

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

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns EnumerationMember

    The EnumerationMember instance for the given IRI

  • getLatestSchemaVersion(): Promise<string>
  • 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().

    example
    const latestSchemaVersion = await mySdoAdapter.getLatestSchemaVersion();
    // get the latest schema.org vocabulary version identifier
    "13.0"

    Returns Promise<string>

    The latest version of the schema.org vocabulary

  • Creates an array of IRIs of all class terms (excluding Enumerations) known to this SDOAdapter.

    example
    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',
    ...
    ]

    Parameters

    • Optional paramObj: ParamObjIRIList

      an optional parameter object that filters and formats the result

    Returns string[]

    An array of IRIs representing all class terms

  • Creates an array of IRIs of all data-type terms known to this SDOAdapter.

    example
    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',
    ...
    ]

    Parameters

    • Optional paramObj: ParamObjIRIList

      an optional parameter object that filters and formats the result

    Returns string[]

    An array of IRIs representing all data-type terms

  • Creates an array of IRIs of all enumeration member terms known to this SDOAdapter.

    example
    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',
    ...
    ]

    Parameters

    • Optional paramObj: ParamObjIRIList

      an optional parameter object that filters and formats the result

    Returns string[]

    An array of IRIs representing all enumeration member terms

  • Creates an array of IRIs of all enumeration terms known to this SDOAdapter.

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

    const allEnumerationsArrayAbsoluteIRIs = mySdoAdapter.getListOfEnumerations({outputFormat: "Absolute"});
    // creates an array with absolute IRIs
    [
    'https://schema.org/PaymentMethod',
    'https://schema.org/DayOfWeek',
    'https://schema.org/GenderType',
    ...
    ]

    Parameters

    • Optional paramObj: ParamObjIRIList

      an optional parameter object that filters and formats the result

    Returns string[]

    An array of IRIs representing all enumeration terms

  • Creates an array of IRIs of all property terms known to this SDOAdapter.

    example
    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',
    ...
    ]

    Parameters

    • Optional paramObj: ParamObjIRIList

      an optional parameter object that filters and formats the result

    Returns string[]

    An array of IRIs representing all property terms

  • Creates an array of IRIs of all vocabulary Terms known to this SDOAdapter.

    example
    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',
    ...
    ]

    Parameters

    • Optional paramObj: ParamObjIRIList

      an optional parameter object that filters and formats the result

    Returns string[]

    An array of IRIs representing all vocabulary terms

  • Creates a Property instance for the given IRI.

    example
    // creates a Property instance for schema:name
    const propertyInstance = mySdoAdapter.getProperty("schema:name");

    Parameters

    • id: string

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

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Property

    The Property instance for the given IRI

  • Creates a corresponding term instance for the given IRI, depending on its term-type.

    example
    // 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");

    Parameters

    • id: string

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

    • Optional filter: FilterObject

      The filter to be applied on the result

    Returns Class | DataType | Property | Enumeration | EnumerationMember

    The term instance for the given IRI

  • getVocabularies(omitStandardVocabs?: boolean): Record<string, string>
  • 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.

    example
    // 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/"
    }

    Parameters

    • omitStandardVocabs: boolean = true

    Returns Record<string, string>

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

  • 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.

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

    Parameters

    • Optional defaultFilter: FilterObject

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

    Returns void