In this exercise, follow the instructions here: read the Markdown cells and execute the Code cells (the ones with In + a number on their left).
Not sure how to execute cells in a Notebook? Check the Jupyter Notebook tutorial.
In this notebook, you might have already the code and the outputs, that is the results. We want to create the results afresh, so let's clear all the outputs. Go to the menu 'Kernel' and choose 'Restart & Clear Output' and confirm it when Jupyter asks for it. Wait some seconds, a blue string appears telling 'Kernel ready'; if you don't see it, don't worry, it is so quick that you might have lost it. But the Notebook is ready again.
Please note that we are clearing the results only because we want to run everything in the exercise. But if in the future you come back here, you don't need to delete the results before starting.
In [1]:
!pip install --upgrade collatex
Or directly in the commandline: pip install --upgrade collatex
(without the exclamation mark at the beginning of the line).
In [2]:
from collatex import *
Now we're ready to make a collation object. We do this with the slightly hermetic line of code:
collation = Collation()
Here the lower case collation
is the arbitrary named variable that refers to a copy (officially it is called an instance) of the CollateX collation engine. We simply tell the collation library to create a new instance by saying Collation()
.
In [3]:
collation = Collation()
Now we add some witnesses. Each witness gets a letter or name that will identify them, and for each we add the literal text of the witness to the collation object.
In [4]:
collation.add_plain_witness( "A", "The quick brown fox jumped over the lazy dog.")
collation.add_plain_witness( "B", "The brown fox jumped over the dog." )
collation.add_plain_witness( "C", "The bad fox jumped over the lazy dog." )
And now we can let CollateX do its work of collating these witnesses and sit back for about 0.001 seconds. The result will be an alignment table, so we'll refer to the result with a variable named alignment_table
.
In [5]:
alignment_table = collate(collation, layout='vertical', segmentation=False )
Well, that worked nicely it seems. But there's no printout, no visualization. That's okay, we can come up with a printout of the alignment table too:
In [6]:
print( alignment_table )
CollateX can also collect the segments that run parallel and display them together. To do that, just delete the option segmentation=False
as in the line below. We can now collate and print the output again.
In [7]:
alignment_table = collate(collation, layout='vertical' )
print( alignment_table )
You may have noticed that if you run the cells in the Notebook in order, they know about one another. For this reason, in the end of this tutorial we could produce different outputs using the information typed into the previous cells. When you open a notebook, remember to run the cells in order or to "run all cells" (from the menu Cell), otherwise you may get an error message.
Before moving forward and see how to collate texts stored in files and discover the various outputs that CollateX provide, let's recap what we've done and exercise a bit.
We are using
First, create a new Markdown cell at the end of this Notebook (you could also create a new Notebook, but we'll save time by working in this one). Write in the new cell something like My CollateX test
, so you know that this is your tests from that cell onwards. You can use the Markdown cells to document what is happening around them.
Then, create a Code cell and copy the code here below: this is all CollateX needs to collate some texts, the same instructions we gave it before but all together.
Now run the cell a first time and see the results.
Make changes and see how the output changes when you run the cell again. Change one thing at a time: this way, if you get an error message, it will be easier to debug the code. Try the following changes:
In [6]:
from collatex import *
collation = Collation()
collation.add_plain_witness( "W1", "Some texts here")
collation.add_plain_witness( "W2", "Some text here as well" )
collation.add_plain_witness( "W3", "Some texts in the third witness as well" )
collation.add_plain_witness( "W4", "Some texts here")
alignment_table = collate(collation, layout='vertical')
print( alignment_table )