@innotrade/enapso-graphdb-admin
v1.5.8
Published
ENAPSO Graph Database Admin Tools for Node.js
Downloads
146
Readme
ENAPSO Graph Database Admin client to easily perform administrative and monitoring operations against your RDF stores, your OWL ontologies, or knowledge graphs in nodes.js applications. This client supports an easy import of existing RDF stores and ontologies to Graph Database by uploading via file, strings, or URLs as well as an export in numerous formats and also context management. You can monitor the CPU load and memory usage of Graph Database and run the garbage collector on demand to optimally trigger huge batch operations also provide user management, the creation, and listing of new repositories as well as location and cluster management of graph database.
As of now, we support the connection with three major graph databases
There will be more graph databases added to this list in the future.
You may also find these tools useful
- ENAPSO Graph Database Client: To perform SPARQL queries and update statements against your knowledge graphs or ontologies stored in your graph database.
- ENAPSO Command Line Interface for Graph Databases: To easily perform numerous scriptable convenience operations on graph databases.
🛠️ Installation
npm i @innotrade/enapso-graphdb-admin --save
Create a connection with graph database
const { EnapsoGraphDBClient } = require('@innotrade/enapso-graphdb-client');
const { EnapsoGraphDBAdmin } = require('@innotrade/enapso-graphdb-admin');
let graphDBEndpoint = new EnapsoGraphDBClient.Endpoint({
baseURL: 'http://localhost:7200',
repository: 'Test',
prefixes: [
{
prefix: 'entest',
iri: 'http://ont.enapso.com/test#'
}
],
triplestore: 'graphdb',
version: 9,
apiType: 'RDF4J'
});
Parameters
| Parameter | Type | Description | Values | | --------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | | baseURL(required) | String | Pass the URL in which graph database is running. | | | repository(required) | String | Pass the name of the repository or database of the graph databases with which you want to create a connection. | | | prefixes(required) | Array of objects | Pass the prefix and its IRI as an object which will be used in the SPARQL query to perform crud operations. | | | triplestore(optional) | String | Pass the name of the graph database with which you want to create a connection by default it creates a connection with Ontotext GraphDB. | ('graphdb' , 'stardog' , 'fuseki') | | transform(optional) | String | Pass the type in which you want to show the result of the SPARQL query by default it shows the result in JSON format. | ('toJSON', 'toCSV' , 'toTSV') | | version(optional) | Number | Pass the version of ontotext graphDB to make the tool compatible with an older version by default it works with the latest version of ontotext graphDB. | | | apiType(optional) | String | Pass the type of API which will use for importing ontology in ontotext graphDB by default it uses ontotext graphDB workbench APIs. | ('workbench', 'RDF4J' ) |
📋 Features
| Feature | Description | Ontotext GraphDB | Apache Jena Fuseki | Stardog | | --------------------------------------------------------- | ------------------------------------------------------------------ | ---------------- | ------------------ | ------- | | Login | Authenticate against the graph database | ✔ | ✘ | ✔ | | Query | To retrieve the information from graph database using SPARQL query | ✔ | ✔ | ✔ | | Update | To update the triples in the graph database. | ✔ | ✔ | ✔ | | Create Repository | Create new repository/database in the graph database. | ✔ | ✔ | ✔ | | Delete Repository | Delete existing repository/database from graph database. | ✔ | ✔ | ✔ | | Clear Repository | Remove all triples from graph database repository/database. | ✔ | ✔ | ✔ | | Get Repositories | Get list of all repsoitory from graph database. | ✔ | ✔ | ✔ | | Create User | Create new user and asign the roles in the graph database. | ✔ | ✘ | ✔ | | Get Users | Get list of users from graph database. | ✔ | ✘ | ✔ | | Get Resources | Get list of resources from graph database. | ✔ | ✘ | ✘ | | Update User | Update existing user roles from graph database. | ✔ | ✘ | ✘ | | Assign Role | Assign new roles to the existing user of the graph database. | ✘ | ✘ | ✔ | | Remove Role | Remove roles of the existing user of the graph database. | ✘ | ✘ | ✔ | | Delete User | Delete existing user of graph database. | ✔ | ✘ | ✔ | | Drop SHACL Graph | Drop SHACL graph from graph database. | ✔ | ✘ | ✘ | | Get Contexts | Get all context from graph database repository. | ✔ | ✔ | ✔ | | Upload From File | Upload ontology from file in the graph database. | ✔ | ✔ | ✔ | | Upload From Data | Upoad ontology from data in the graph database. | ✔ | ✘ | ✔ | | Download To File | Download ontology to file from graph database. | ✔ | ✔ | ✔ | | Download To Text | Download ontology to text from graph database. | ✔ | ✔ | ✔ | | Clear Context | Clear specific named graph from graph database repository. | ✔ | ✔ | ✔ | | Get Query | Get query from graph database repository. | ✔ | ✘ | ✔ | | Get Locations | Get locations from graph database repository. | ✔ | ✘ | ✘ | | Perform Garbage Collection | Perform garbage collection in the graph database repository. | ✔ | ✘ | ✘ | | Get Saved Queries | Get saved queries from graph database. | ✔ | ✘ | ✘ |
Login
Login to authenticate the user against graph database and authorize the user according to his roles:
graphDBEndpoint
.login('admin', 'root')
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Query
Querying against the graph database
graphDBEndpoint
.query(
'select *
where {
?class rdf:type owl:Class
filter(regex(str(?class), "http://ont.enapso.com/test#TestClass", "i")) .
}',
{ transform: 'toJSON' }
)
.then((result) => {
console.log(
'Read the classes name:\n' + JSON.stringify(result, null, 2)
);
})
.catch((err) => {
console.log(err);
});
Update
Updating Triples in graph database
graphDBEndpoint
.update(
`insert data {
graph <http://ont.enapso.com/test> {
entest:TestClass rdf:type owl:Class}
}`
)
.then((result) => {
console.log('inserted a class :\n' + JSON.stringify(result, null, 2));
})
.catch((err) => {
`console.log(err);
});
Upload From File
Upload an ontology and import it into the graph database repository automatically if the upload was successful. context (graph) and baseIRI parameters are optional :
graphDBEndpoint
.uploadFromFile({
filename: '../ontologies/EnapsoTest.owl',
format: 'application/rdf+xml',
baseIRI: 'http://ont.enapso.com/test#',
context: 'http://ont.enapso.com/test'
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Upload From Data
Upload data (rather than a file) and automatically import the data into a graph database repository and context (graph) is an optional parameter:
fsPromises
.readFile('../ontologies/EnapsoTest.owl', 'utf-8')
.then((data) => {
graphDBEndpoint
.uploadFromData({
data: data,
context: 'http://ont.enapso.com/test',
format: 'application/rdf+xml'
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
})
.catch((err) => {
console.log(err);
});
Download To Text
Download a Graph from graph database to a Text Variable. For the available export formats, please refer to the EnapsoGraphDBClient.FORMAT_xxx constants. The context (graph) is optional. If you do not pass a context (graph), the entire repository is exported.
graphDBEndpoint
.downloadToText({
format: EnapsoGraphDBClient.FORMAT_TURTLE.type
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Download To File
Download a graph from graph database directly to a Local File. For the available export formats, please refer to the EnapsoGraphDBClient.FORMAT_xxx constants. The context is optional. If you do not pass a context, the entire repository is exported.
let lFormat = EnapsoGraphDBClient.FORMAT_TURTLE;
graphDBEndpoint
.downloadToFile({
format: lFormat.type,
filename:
'../ontologies/' +
graphDBEndpoint.getRepository() +
lFormat.extension
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Perform Garbage Collection
Perform the garbage collection on the server side to release allocated resources: if security is on then the Garbage Collection user role needs to be Administrator else operation is not performed
graphDBEndpoint
.performGarbageCollection()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Get Resources
Get resource details of the repository current connected to the endpoint:
graphDBEndpoint
.getResources()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Create User
Create a new user and provide a user with read/write access to certain repositories in a graph database instance: if security is on then for Creating a new User, the user role needs to be Administrator else operation is not performed
graphDBEndpoint
.createUser({
authorities: [
'WRITE_REPO_Test', // Writing excess wrote WRITE_ and in last name of Repository which excess provided like REPO_Test
'READ_REPO_Test', // Reading excess wrote READ_ and in last name of Repository which excess provided like REPO_Test
'READ_REPO_EnapsoDotNetProDemo',
'ROLE_USER' // Role of the user
],
username: 'TestUser2', // Username
password: 'TestUser2' // Password for the user
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Update User
Update the user's roles (read/write rights) for certain repositories: if security is on then for Updating Existing User, the user role needs to be Administrator else operation is not performed
graphDBEndpoint
.updateUser({
authorities: [
// Writing excess wrote WRITE_ and in the last name of Repository which excess provided like REPO_Test
'READ_REPO_Test', // Reading excess wrote READ_ and in the last name of Repository which excess provided like REPO_Test
'WRITE_REPO_EnapsoDotNetProDemo',
'READ_REPO_EnapsoDotNetProDemo',
'ROLE_USER' // Role of the user
],
username: 'TestUser' // Username
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Assign Role
Assign new roles to the user of the graph database instance
graphDBEndpoint
.assignRoles({
userName: 'ashesh',
authorities: [
{
action: 'READ',
resource_type: 'db',
resource: ['Test']
},
{
action: 'WRITE',
resource_type: 'db',
resource: ['Test']
}
]
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Remove Role
Remove existing roles of a user in the graph database instance
graphDBEndpoint
.removeRoles({
username: 'TestUser',
authorities: [
{
action: 'READ',
resource_type: 'db',
resource: ['Test']
},
{
action: 'WRITE',
resource_type: 'db',
resource: ['Test']
}
]
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Delete User
Caution! This deletes the user including all assigned authorities (roles)! This operation cannot be undone! Deletes a user from the graph database instance: if security is on then for Deleting User, the user role needs to be Administrator else operation is not performed
graphDBEndpoint
.deleteUser({
user: 'TestUser2' // username which you want to delete
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Get Repositories
Get details of all repositories of the graph database repositories operated on the connected host:
graphDBEndpoint
.getRepositories()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Clear Repository
Caution! This removes ALL triples of the given repository! This operation cannot be undone! The entire repository will be emptied, i.e. all data of this repository will be removed. The repository remains active.
graphDBEndpoint
.clearRepository()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Get Users
Get all details of all users of a certain graph database instance:
graphDBEndpoint
.getUsers()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Get Query
Get Query from graph database:
graphDBEndpoint
.getQuery()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Get Contexts
List all named graphs inside a given repository:
graphDBEndpoint
.getContexts()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Clear Context
Caution! This removes ALL triples of the given context! This operation cannot be undone! The entire context will be emptied, i.e. all data from this context will be removed. The repository and other contexts remain active.
graphDBEndpoint
.clearContext('http://ont.enapso.com/test')
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
Get Locations
Get details of all locations which are associated with the connected graph database instance:
graphDBEndpoint
.getLocations()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Get Saved Queries
graphDBEndpoint
.getSavedQueries()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Create Repository
Create a new repository in the graph database instance, isShacl parameter is optional by default it is false. if security is on then for creating a repository, the user role needs to be Repository Manager else operation is not performed
graphDBEndpoint
.createRepository({
id: 'AutomatedTest4',
title: 'enapso Automated Test Repository',
location: '',
isShacl: true
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Delete Repository
Delete a repository in the connected graph database instance: if security is on then for deleting the repository, the user role needs to be Repository Manager else operation is not performed
graphDBEndpoint
.deleteRepository({
id: 'AutomatedTest'
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
Drop SHACL Graph
Drop a shacl Shape from graph database to remove all validations:
graphDBEndpoint
.dropShaclGraph()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
📖 Documentation
View the documentation for further usage examples.
🧪 Testing
Tutorial to run the Test suite against the graph database.
😎 Contributing
Contributing is more than just coding. You can help the project in many ways, and we will be very happy to accept your contribution to our project.
Details of how you can help the project are described in the CONTRIBUTING.md document.
🧑🏫 Contributors
💬 Bugs and Feature Requests
Do you have a bug report or a feature request?
Please feel free to add a new issue or write to us in discussion: Any questions and suggestions are welcome.
🧾 License
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.