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
- Host: GitHub
- URL: https://github.com/pdsinterop/solid-typeindex-parser
- Owner: pdsinterop
- License: mit
- Created: 2021-02-14T21:07:47.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-24T13:43:01.000Z (over 1 year ago)
- Last Synced: 2024-07-24T15:50:05.892Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://pdsinterop.org/solid-typeindex-parser/
- Size: 125 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 .
```