An open API service indexing awesome lists of open source software.

https://github.com/pdsinterop/solid-typeindex-parser

Parser to manipulate type index files for Solid
https://github.com/pdsinterop/solid-typeindex-parser

Last synced: about 2 months ago
JSON representation

Parser to manipulate type index files for Solid

Awesome Lists containing this project

README

          

# Solid Type Index Parser

A js library for working with typeindex files. It allows you to parse the turtle representation, update entries and finally convert it back to turtle. *It does not cover fetching typeindex files.*

## Basic example
This example demonstrates how to parse a turtle string into an TypeIndexDoc object, then add a type entry and parse it back to turtle.

```javascript
const SolidTypeIndexParser = require('SolidTypeIndexParser')

const typeIndexUrl = 'https://pod.example.org/settings/privateTypesIndex.ttl'
const turtle = `
@prefix : <#>.
@prefix solid: .
@prefix schem: .
@prefix terms: .

<> a solid:ListedDocument, solid:TypeIndex.`

const { TypeIndexParser } = SolidTypeIndexParser

async function main() {
// Parse the turtle to an TypeIndexDoc object which we can modify
const parser = new TypeIndexParser({ typeIndexUrl })
const doc = await parser.turtleToTypeIndexDoc(turtle)

// Give the type to the type index
const solidType = new SolidType(
"http://www.w3.org/2002/01/bookmark#Bookmark",
"/public/bookmarks.ttl");
}
doc.addType(solidType,{ subjectId: '#bookmarks' })

// Parse it back to turtle so we can store it in the pod
const newTurtle = await parser.typeIndexDocToTurtle(doc)
console.log(newTurtle)
}
main()
```

Output turtle
```text/turtle
@prefix : <#>.
@prefix solid: .
@prefix schem: .
@prefix terms: .

<>
a solid:ListedDocument, solid:TypeIndex;
terms:references :bookmarks.

:bookmarks
a solid:TypeRegistration;
solid:forClass ;
solid:instance .
```

Example for a registration with an instanceContainer
```javascript
const SolidTypeIndexParser = require('SolidTypeIndexParser')

const typeIndexUrl = 'https://pod.example.org/settings/privateTypesIndex.ttl'
const turtle = `
@prefix : <#>.
@prefix solid: .
@prefix schem: .
@prefix terms: .

<> a solid:ListedDocument, solid:TypeIndex.`

const { TypeIndexParser } = SolidTypeIndexParser

async function main() {
// Parse the turtle to an TypeIndexDoc object which we can modify
const parser = new TypeIndexParser({ typeIndexUrl })
const doc = await parser.turtleToTypeIndexDoc(turtle)

// Give the type to the type index
const solidType = new SolidType(
"http://www.w3.org/2002/01/bookmark#Bookmark",
undefined,
"/public/bookmarks/");
}
doc.addType(solidType,{ subjectId: '#bookmarks' })

// Parse it back to turtle so we can store it in the pod
const newTurtle = await parser.typeIndexDocToTurtle(doc)
console.log(newTurtle)
}
main()
```

Output turtle
```text/turtle
@prefix : <#>.
@prefix solid: .
@prefix schem: .
@prefix terms: .

<>
a solid:ListedDocument, solid:TypeIndex;
terms:references :bookmarks.

:bookmarks
a solid:TypeRegistration;
solid:forClass ;
solid:instanceContainer .
```