Hands-on 2: Working with views in Alexandria

2.1. Initialise Alexandria

First, we will prepare your working directory for usage by initialising Alexandria:

In [1]:
! alexandria init
/bin/sh: alexandria: command not found

2.2. Register a document in Alexandria

The next step is to register "lighthouse-woolf.tagml" as a document in the Alexandria repository you just started on your machine.

In [ ]:
! alexandria add tagml/lighthouse-woolf.tagml

You have now added the TAGML file "lighthouse-woolf.tagml".

At all times, you can check which documents and views are registered in Alexandria:

In [ ]:
! alexandria status

Alexandria will inform you about the registered documents and views, and shows the state of the source files.

Adding files to Alexandria basically means you have registered them for your local repository, but mind you: the files are not yet committed to your local repository. Let's do that now:

In [ ]:
! alexandria commit tagml/lighthouse-woolf.tagml

You can also commit all files that you have added at once with commit -a, which means something like "commit all at once":

In [ ]:
! alexandria commit -a

Help! I get a syntax error

When you commit a TAGML file to your local Alexandria repository, the file is parsed automatically. If you made any syntax mistakes in your TAGML transcription, Alexandria will abort the commit and inform you that you made a syntax error, what error it is exactly and in which line you can find it. You can go back to the file and correct the mistake. Once you have done that, you can commit the file again.

2.3. Define views on the text

Conceptually, views are a selection of layers and/or or markup elements. In a JSON file, you identify the markup and layers you want to include or exclude in the view. We use the file "lighthouse-woolf.tagml" as a starting point for the view definition.

2.3.1. Markup

First, we create a view that includes only the markup element s.

Open a new text file in the views/ directory by selecting 'text file' in the 'New'-dropdown menu on the right side of the Jupyterhub environment.

Enter the following lines of code in the text file:

{"includeMarkup": ["s"]}

Change the name of the file to "view-s-markup.json".

Save and close the file.

2.3.2. Layers

Let's create another view, that includes all markup with the layer ID "T".

Open a new text file in the views/ directory and enter the following code:

{"includeLayers":["T"]}

Rename the file to "view-T-layer.json", then save and close the file.

2.4. Register views in Alexandria

Let's commit the views we just created into our local repository:

In [ ]:
! alexandria commit -a

They should all be ready, so let's check with Alexandria by running alexandria status again:

In [ ]:
! alexandria status

The command provides information about the version plus the documents and the views you have registered in the repository.

Let's take a look at the views we have just created:

In [ ]:
! ls views/

We can now add these views to the Alexandria repository as well. Note that files with the .json extension are automatically understood as views. You add the views in the same way as you've added the transcriptions:

In [ ]:
! alexandria add views/view-s-markup.json
! alexandria commit views/view-s-markup.json

The name of the view is derived from the name of the file, so "view-s-markup.json" will become view-s-markup in the Alexandria repository.

Repeat this step for the other views.

Check with alexandria status if everything worked:

In [ ]:
! alexandria status

2.5. Checkout a view

You can use the views you have just defined to checkout a view on the documents:

In [ ]:
! alexandria checkout view-s-markup

This updates the TAGML files from the document to contain only text and s markup.

2.6. Deactivate a TAGML view

If you want to deactivate the view and return to the original tagml file, you can run:

In [ ]:
! alexandria checkout -

The - parameter after checkout will reset the TAGML files.

You can repeat these steps for the other view you have created. Play around with it for a while!

In the next notebook we will continue working with views, including an export to XML and HTML.