time-link / timelink-kleio

Provides translation of files in Kleio notation into XML and other formats. Part of Timelink.
1 stars 0 forks source link

Kleio translation services for Timelink.

kleio-server provides access to translation services for Kleio files.

About Kleio files

Kleio files are text files with a special notation designed to the transcription of historical sources. The notation was created by Manfred Thaller, as part of the Kleio historical database system (http://web.archive.org/web/20130603204750/http://www.hki.uni-koeln.de/kleio/old.website/).

Although Thaller's Kleio database system is no longer publically available, the notation developped for historical source transcritpion proved very powerfull, providing a concise way for the transcription of complex historical documents.

The Timelink-Kleio translator implements a subset of the Kleio notation designed for the Timelink database system. Timelink provides a set of data models designed for handling person-oriented information collected in historical documents.

This is how a (portuguese) baptism looks like in Timelink Kleio notation:

  bap$b1714-2/12/11714/fl.117v./igreja de sao silvestre/manuel lopes serra (padre)

     celebrante$manuel lopes serra
        ls$profissao/padre

     n$francisca/f

        pn$antonio ferreira
           ls$morada/espinheiro
           ls$freguesia/lousa

        mn$leonarda francisca

        pad$joao fernandes ramalheiro
           ls$morada/moita
           ls$freguesia/lousa

        mad$francisca
           ls$ec/solteira

           pmad$joao goncalves
              ls$morada/espinheiro
              ls$freguesia/lousa

Text files implementing the Timelink Kleio notation can be translated by the Timelink kleio-server and imported into the Timelink relational database.

Translation is intelligent in the sense that it operates a normalization of the source information, infering information from the context, and so greatly reducing the overhead of producing normalized data.

Timelink database-services then implement a set of functions that allow the identification of people, reconstruction of biographies, inference of personal networks, and other funcionalities.

For more information on Timelink Kleio Server see: https://github.com/time-link/timelink-kleio

Services provided by the kleio-server API

The API is designed to decouple Kleio source handling from other software components. It provides funcionality to translate source files, inspect results of translation for errors or warnings, obtain the generated data in XML format. It also allows basic file management and basic git operations, so that it can be used to isolate other software components from directly handling file related operations.

Main services privided by the API are:

API documentation is available in docs/api

Api documentation

API documentation is available at docs/api/index.html

Running the server with docker

Run the latest version from docker hub

$ docker run -v $(PWD):/kleio-home -p 8088:8088 -d  timelink-server/kleio-server

Build and run locally

make build-local

$ docker run -v $PWD:/kleio-home -p 8088:8088 -d  kleio-server

Change the external linking port

To have the server listening on port 8089

$ docker run -v $(PWD):/kleio-home -p 8088:8089 -d  kleio-server

Set an admin token

$ docker run -v $(PWD):/kleio-home -e KLEIO_ADMIN_TOKEN=myprivatetoken -p 8088:8088 -d  kleio-server

If KLEIO_ADMIN_TOKEN is not set the server will generate a token with admin privileges which can be obtained in the .kleio.json file in the directory mapped to /kleio-home

$docker run -v $PWD:/kleio-home -p 8088:8088 -d  kleio-server

$cat $PWD/.kleio.json

The generated token is associated with user kleio_admin, and can be invalidated by a client after generating a new one.

Run under current user

On linux system docker will run under the root user. This makes the server generate files that will generate permission errors when accessed by the current user.

To run the kleio server user the current user:

docker run -v $PWD:/kleio-home -u $(id -u):$(id -g) -p 8088:8088 -d  kleio-server

More configuration options

There are more environment variables that can be set to control the behaviour of kleio-server.

The easiest way to test in to use docker compose with the docker-compose.yamlfile in this directory and set the variables in a .env file:

Development

Requirements

Kleio server is written in SWI-Prolog https://www.swi-prolog.org

Recommended tools:

Running the server locally for debugging

Easiest way:

See the README.md file inside the tests directory for more information on testing.

Debugging inside the docker container

After building the image with make build-local run a shell in the kleio-server container

  docker compose run kleio sh

At the prompt start swi Prolog and change to the kleio-home directory

  # swipl -f serverStart.pl
  ?- working_directory(_,'/kleio-home').
  ?- run_debug_server.

Debugging together with MHK

Currently MHK debugging is done by starting the current build together with the other containers (mySQL/MariaDB, Caddy, Portainer and Kleio) through a Docker compose file and by attaching the Intellij IDEA debugger to the running MHK app.

The recomended way is to stop the kleio server that is started with MHK and start a local server in VSCode as explained above, and associating it with the same mhk-home directory of the MHK beeing jointly tested, as described bellow.

In order for MHK to connect to the local running Kleio server the property mhk.kleio.service should be set to http://host.docker.internal:8088 in the file mhk-home/system/conf/mhk_system.properties

This means that the MHK instance running in Docker will try to connect to port 8088 in the local host. Values of http://127.0.0.1:8088 ot http://localhost:8088

The sequence should be:

  1. Build new docker image of MHK
  2. Update local MHK install with local image: mhk update --local (make sure mhk is updating from latest image wiht mhk use-tag latest)
  3. Start mhk with mhk start
  4. Stop the kleio server mhk stop kleio

Steps 1-3 above are normally automated inside Intellij IDEA with a Debug configuration.

Start the Kleio server inside VSCode:

This will start a kleio server from USER_HOME/mhk-home running in port 8088. If mhk-home used by MHK is at a different location pass the path in H. In a port other than 8088 is to be used pass it in P.

Tests

There two type of tests:

See README-tests.md in the directory tests for details. The tests directory also contains reference files and the reference translator necessary to run both semantic and api tests.

Updating

Preparing images

The following tags are used:

To help manage the tags the following targets exist

Release sequence

Make targets

Type make to see more targets that help in development.

  make build-local          build a local docker image and tag with new build number
  make tag-local-TAG        tag last local image with TAG in latest | stable
  make build-multi          build local mage and push multi platform docker imagea tagged with new build number
                            (requires login in dokerhub with 'docker login' )
  make tag-multi-TAG        tag last multi platform image with TAG in latest | stable
  make show-build           return the current build number
  make show-version         return the current version string (major.minor)
  make show-current         return the current version, build number
  make show-last            return the last image build date, version, build number
  make show-env             show KLEIO env variables currently defined
  make inc-NUMBER           increment version with NUMBER in major | minor
  make gen-token            generate a string suitable for KLEIO_ADMIN_TOKEN for .env file
  make bootstrap-token      generate and register a token for 'admin' during bootstrap
                                (only if no tokens exist and server running < 5 minutes)
  make docs                 generate api docs (requires postman_doc_gen and api files)
  make pull-tag tag=x.y.z   pull image with tag x.y.z from docker hub
  make kleio-run-latest     start server with latest multi platform image, .env config and tests/docker_compose.yaml
  make kleio-run-current    start server with most recent build, .env config and tests/docker_compose.yaml
  make kleio-run-tag tag=x.y.z    start server with image with tag x.y.z, .env config and tests/docker_compose.yaml
  make kleio-stop | stop    stop running server
  make test-semantics       run semantic tests
  make test-api             run api tests (requires newman (npm install newman))

Release notes

( make show-last to have timestamp and version info)

2024-10-23 17:25:42 version 12.6.575

Fixes problem with local token db that generated a false error of unkown method in some token operations.

2024-07-29 07:52:13 version 12.6.572

Added property$NAME/VALUE subgroup to the kleio$ group.

This allows for specifying file properties that affect the way the source is translated.

The first (and only) property currently implemented is multuple-entry-flag that sets the character interpreted as separating multiples entries in a field (data flag 8 in the original Manfred Thaller implementation, see issue #34

Example, to set the separator to the pipe " | " character (ascii 124).

   property$multiple-entry-flag/124

Also:

2024-02-29 07:40:48 version 12.5.570

Fix bugs, linked data ids now allow for dashes, improve error and warning line reporting

2024-02-07 13:03:06 version 12.4.567

2024-01-23 07:16:28 version 12.3.561

2024-01-07 12:20:12 version 12.1.557

2023-09-27 14:23:12 version 12.0.550

2023-12-13 18:44:37 version 12.1.554

Fixes a bug in translation of identification files.

2023-09-07 16:58:13 version 12.0.545

Fixes bugs, first tests with timelink-py client.

2023-07-04 04:34:23 version 12.0.540

Adds linked data notation.

  1. Declare the external source, with an attribute of the kleio document: kleio$... link$wikidata/"http://wikidata.org/wiki/$1"

    The format of the link$ group is: link$short-name/url-pattern

    where short-name is a short name for an external sources url-pattern should be a url containing a place holder ($1) for a specific id of the data item to be linked

  2. Anotate element values with external ids

    ls$jesuita-entrada/Goa, Índia# @wikidata:Q1171/15791200

    The format of an external link annotation is:

    @short-name:id

On translation annotation such as

ls$jesuita-entrada/Goa, Índia# @wikidata:Q1171/15791200

will generate

ls$ jesuita-entrada@/https://www.wikidata.org/wiki/Q1171/15791200/obs=%Goa, Índia

2023-06-05 02:04:07 version 11.1.541

Internal:

2023-03-28 14:49:22 version 11.1.536

Clean up targets for build and run

2022-12-26 13:32:53 version 10.19.482

Adds multi-architecture docker builds.

2022-12-25 10.19.464

Fixes issue 5 generates bootstrap token at each startup.

2022-06-15 10.18.463

Fixes CORS pre-flight requests.

2022-06-08 v10.17.456

Adds cors capability. Set env KLEIO_CORS_SITES with comma separeted list of allowed sites or "*" for all.

2022-03-17 v10.16.452

2022-01-20 v10.15

2021-10-09