Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@virtual-assembly/semantizer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@virtual-assembly/semantizer

The semantizer library lets you enhance your object model with semantic data.

Source
npmnpm
Version
1.0.0-alpha.1
Version published
Weekly downloads
36
140%
Maintainers
1
Weekly downloads
 
Created
Source

Semantizer is a library to easily build objects that can be represented as RDF datasets. It is built on top of RDFJS.

This library was writen for the Data Food Consortium project (DFC) which aims to provide interoperability between food supply chain platforms. We use the semantizer library inside our connector library to help developers to exchange data expressed with the DFC ontology.

Get started

Lets take an example, with a simple Address and Person classes:

class Address extends SemanticObject {
  
    constructor(name: string, country: string) {
        super({
            semanticId: "http://myplatform.com/address/" + name,
            semanticType: "https://schema.org/PostalAddress"
        });
        this.setSemanticPropertyLiteral("https://schema.org/addressCountry", country);
    }

    public getCountry(): string {
        return this.getSemanticProperty("https://schema.org/addressCountry");
    }
}

class Person extends SemanticObject {

    constructor(name: string, address: Address) {
        super({
            semanticId: "http://myplatform.com/person/" + name,
            semanticType: "https://schema.org/Person"
        });
        this.setName(name);
        this.setAddress(address);
    }

    public getAddress(): Address {
        return this.getSemanticProperty("https://schema.org/address");
    }

    public getName(): string {
        return this.getSemanticProperty("https://schema.org/givenName");
    }

    public setAddress(address: Address): string {
        this.setSemanticPropertyReference("https://schema.org/address", address);
    }

    public setName(name: string): string {
        this.setSemanticPropertyLiteral("https://schema.org/givenName", name);
    }

}

You can access the properties:

const address = new Address("adr1", "France");
const person = new Person("John", address);

console.log(person.getName()); // => John
console.log(person.getAddress().getCountry()); // => France

You can get a RDF dataset using the toRdfDatasetExt() method.

You can also set all the properties from a RDF dataset with the setSemanticPropertyAllFromRdfDataset(dataset: DatasetExt) method.

FAQs

Package last updated on 28 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts