Skip to content
Permalink
Browse files
fix: command line scripts
  • Loading branch information
subotic committed Jun 20, 2019
1 parent d078e4a commit 732a0fa56efd88d2f9712cc132181bf24c234f3b
Showing with 47 additions and 38 deletions.
  1. +27 −6 README.md
  2. +8 −2 knora/create_ontology.py
  3. +0 −20 knora/knora-ctl.py
  4. +11 −8 knora/reset_triplestore.py
  5. +1 −2 setup.py
@@ -4,8 +4,10 @@
knora-py is a python package containing a command line tool for data model (ontology) creation, a library allowing creation of single resources and mass upload using the bulk import of data into the Knora framework.

The package consists of:
- ```Knora``` Python modules for accessing Knora using the API (ontology creation, data import/export etc.)
- ```knora-create-ontology``` A command line program to create an ontology out of a simple JSON description
- `Knora` Python modules for accessing Knora using the API (ontology creation, data import/export etc.)
- `knora-create-ontology` A command line program to create an ontology out of a simple JSON description
- `knora-reset-triplestore` A command line program to reset the content of the ontology. Does not require
a restart of the Knora-Stack.

## Install

@@ -135,7 +137,7 @@ The _lists_ object contains an array of lists. Here an example:
```
the _lists_ element is optional.

## Ontology
### Ontology

The _ontology_ object contains the definition of the data model. The ontology has
the following elemens:
@@ -440,7 +442,7 @@ The properties object has the following fields:
}
```
## JSON for lists
### JSON for lists
The JSON schema for uploading hierarchical lists only is simplyfied:
```json
@@ -453,7 +455,7 @@ The JSON schema for uploading hierarchical lists only is simplyfied:
```
The definition of the lists is the same as in the full upload of an ontology!
### A full example for creating lists only
#### A full example for creating lists only
The following JSON definition assumes that there is a project with the shortcode _0808_.
```json
@@ -506,8 +508,27 @@ The following JSON definition assumes that there is a project with the shortcode
}
```
## Reseting the triplestore with `knora-reset-triplestore`
This script reads a JSON file containing the data model (ontology) definition,
connects to the Knora server and creates the data model.
### Usage:
```bash
$ knora-reset-triplestore
```
It supports the following options:
- _"-s server" | "--server server"_: The URl of the Knora server [default: localhost:3333]
- _"-u username" | "--user username"_: Username to log into Knora [default: root@example.com]
- _"-p password" | "--password password"_: The password for login to the Knora server [default: test]
For resetting of the triplestore through Knora-API to work, it is necessary to start the Knora-API server
with a configuration parameter allowing this operation (e.g., `KNORA_WEBAPI_ALLOW_RELOAD_OVER_HTTP`
environment variable or the corresponding setting in `application.conf`).
## Bulk data import
In order to make a bulk data import, a properly formatted XML file has to be created. The python module "knora.py" contains
In order to make a bulk data import, a properly formatted XML file has to be created. The python module "knora" contains
classes and methods to facilitate the creation of such a XML file.
## Requirements
@@ -8,7 +8,7 @@
import sys


def main(args):
def program(args):
# parse the arguments of the command line
parser = argparse.ArgumentParser()
parser.add_argument("ontofile", help="path to ontology file")
@@ -234,5 +234,11 @@ def list_creator(con: Knora, proj_iri: str, list_iri: str, parent_iri: str, node
return nodelist


def main():
program(sys.argv[1:])


if __name__ == '__main__':
main(sys.argv[1:])
print(sys.argv)
print(sys.argv[1:])
program(sys.argv[1:])

This file was deleted.

@@ -1,17 +1,15 @@
import os
from typing import List, Set, Dict, Tuple, Optional
from pprint import pprint
import argparse
import json
from jsonschema import validate
from knora import KnoraError, Knora
import sys

from knora import Knora

def main(args):

def program(args):
# parse the arguments of the command line
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--server", type=str, default="http://0.0.0.0:3333", help="URL of the Knora server")
parser.add_argument("-u", "--user", default="root@example.com", help="Username for Knora")
parser.add_argument("-p", "--password", default="test", help="The password for login")

args = parser.parse_args(args)

@@ -20,5 +18,10 @@ def main(args):
con.login(args.user, args.password)
con.reset_triplestore_content()


def main():
program(sys.argv[1:])


if __name__ == '__main__':
main(sys.argv[1:])
program(sys.argv[1:])
@@ -31,8 +31,7 @@
entry_points={
'console_scripts': [
'knora-create-ontology=knora.create_ontology:main',
'knora-reset-triplestore=knora.reset_triplestore:main',
'knoractl=knora.knora_ctl:cli'
'knora-reset-triplestore=knora.reset_triplestore:main'
],
},
include_package_data=True,

0 comments on commit 732a0fa

Please sign in to comment.