npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

knora-jsonld-simplify

v1.0.22

Published

Simplify JSON-LD returned from Knora

Downloads

10

Readme

KnoraJsonldSimplify – a Simplifier for the "simple" JSON-LD returned by Knora

KnoraJsonldSimplify is a small TypeScript module that simplifies the output of the Knora V2 API, notably the results from a resource or gravsearch query. Usage is very simple. Let's assume that the variable jsonld contains the result of a gravsearch query either as JSON string or as an object:

let simplifier = new KnoraJsonldSimplify(jsonld);
const result = simplifier.simplify();

The result is an array of KnoraResource-instances:

Installation source coude

  • download it from github
  • yarn install to install and compile
  • yarn test to perform the testing

Installation npm

Knora-jsonld-simplify is now available as npm module

npm install knora-jsonld-simplify

In a angular projects

npm add knora.jsonld-simplify

should work...

Helpers

export enum KnoraCalendar { GREGORIAN, JULIAN, ISLAMIC, JEWISH }

export enum KnoraCalendarEra { BC, CE }

KnoraResource class

Member variables

A KnoraResource object provides the following member variables that are accessible readonly:

  • iri: [readonly] The Knora IRI of the resource
  • type: [readonly] The type of the resource as defined by the ontology, e.g., mls:Lemma
  • label: [readonly] The label of the resource

Member Methods

In order to access the properties of the resource, the following methods are provided:

  • getNProps(): Returns the number of properties that the resource actually has.
    getNProps(): number
  • getNValues(): Return the number of values available of the given property.
    getNValues(propertyname: string) : number
  • isValue(): Is True if thee value of the given property name and given index is of type KnoraValue, That is, it points to a property value (and is not a link to another resource)
    isValue(propertyname: string, index: number)
  • getValue(): Returns an KnoraValue instance.
    getValue(propertyname: string, index: number): Returns a KnoraValue instance.
  • isResource(): Is True if thee value of the given property name and given index is of type KnoraResource, that is, it is a link property that points to another resource. This resource may be empty (just providing the IRI without property values or it can be a full resource with properties values)
    isResource(propertyname: string, index: number)
  • getResource(): Returns a Knora_Resource (the property must be a link property)
    getResource(propname: string, index?: number) : KnoraResource

KnoraValue class

This class provides access to the property values. Usually KnoraValue it is subclassed to reflect the different data types that Knora provides. The following sublcasses are provided:

Member variables (also available in subclasses)

  • iri: string [readonly]: The IRI of this value
  • subtype: string [readonly]: Get string with subclass name (e.g. "KnoraTextValue")
  • strval: string [readonly]: The string representation of the value (available for all value types!)
  • comment: strong : The comment associated with a value

Member methods (also available in subclasses)

  • stringify: Returns a descriptive string representation (e.g. for logging etc.) stringify(indent: string = ''): string

KnoraTextValue

Represents a text value. This can be a richtext with standoff markup!

Member variables

  • strval: string: Text string or XML
  • mapping: string: The IRI of the XML mapping (see standoff of Knora)

KnoraIntValue

Represents an integer value

Member variables

  • ival: number: Returns the integer value

KnoraListValue

Represents a node from a list

Member variables

  • nodeIri: string: The IRI of the list node
  • label: string: The label of the nodse if available, otherwise undefined

KnoraColorValue

Represents a color value

Member variables

  • color: string: The color in HTML notation

KnoraDecimalValue

Represents a decimal value

Member variables

  • decimal: number: The decimal value

KnoraUriValue

Represents an URI

Member variables

  • uri: string: An URI

KnoraBooleanValue

Represents a boolean

Member variables

  • bool: boolean: A boolean value

KnoraGeomValue

Represents a geometry value of a region. This is a JSON string.

Member variables

  • geom: string: A geometry value as JSON string

KnoraGeonameValue

Represents a geographical location as given by a code by geonames.org

Member variables

  • geonameCode: string: Geonames.org geo code

KnoraIntervalValue

Represents a time interval

Member variables

  • start: number: Start time in seconds (including fractions of seconds)
  • end: number: End time in seconds (including fractions of seconds)

KnoraDateValue

Implemensts the Knora calendar date representation

Member variables

  • calendar: KnoraCalendar: The calendar, either
    • KnoraCalendar.GREGORIAN
    • KnoraCalendar.JULIAN
    • KnoraCalendar.ISLAMIC (NYI!)
    • KnoraCalendar.JEWISH (NYI!)
  • startEra: KnoraCalendarEra: Era of start date, either
    • KnoraCalendarEra.BC
    • KnoraCalendarEra.CE
  • startYear: number: Start year
  • startMonth: number: Start month
  • startDay: number: Start day
  • endEra: KnoraCalendarEra: Era of end date, see startEra
  • endYear: number: End year
  • endMonth: number: End month
  • endDay: number: End day

KnoraStillImageFileValue

Implements the still image value of a Knora StillImageResource

Member variables

  • strval: string: A IIIF compatible URL to access the full image as JPEG
  • filename: string: The filename/file-ID
  • baseUrl: string: The base URL of the IIIF server providing the image
  • dimX: number: X dimension of image (in pixels)
  • dimY: number: Y dimension of image (in pixels)

Example

// create the simplyfier instance
let simplifier = new KnoraJsonldSimplify(); 

// simplify the JSON from knora. We get an array of resources
const result = simplifier.simplify(json); 

// get the IRI of the first resource
let iri = result[0].iri

// get the label of the first resource
let label = result[0].label

// get the type of the first resource, eg. "kpt:restype1"
let type = result[0].type

// check if there is a property "kpt:titleprop"
if (result[0].isValue("kpt:titleprop")) {
  // get the string representation of the first value
  let strval = result[0].getValue("kpt:titleprop").strval
}

// Check if kpt:linkpropValue is a Resource (should be because its a link)
if (result[0].isResource("kpt:linkpropValue")) {
  let res = result[0].getResource("kpt:linkpropValue")
  let restype = res.type; // type of resource
  let resiri = res.iri; // IRI of resource 
  let nprops = res.getNProps(); // see if the resource has been retrieved completely
}