SoS Notebook is a Jupyter kernel that allows the use of multiple kernels in one Jupyter notebook. This module provides a language module for the IRuta kernel that is based on the Apache UIMA Ruta programming language.
To install this repository from PyPI, use pip install sos-ruta
. To install this repository from source, clone it and run pip install .
in this directory.
Using the %expand
magic, one can transfer String variables from Ruta to Python Cells in the same notebook. Please see the example below.
documentText = '"Patient has fevers, but no chills."'
problem_list = '"fevers|chills|nausea"'
newTypeName = "Diagnosis"
%expand
%documentText {documentText}
DECLARE {newTypeName};
{problem_list} -> {newTypeName};
COLOR({newTypeName},"green");
is automatically expanded to
%documentText "Patient has fevers, but no chills."
DECLARE Diagnosis;
"fevers|chills|nausea" -> Diagnosis;
COLOR(Diagnosis,"green");
This annotates "fevers" and "chills" as annotations of type "Diagnosis".
A Cas object holds information about the document text and all annotations together with a TypeSystem. They can be exchanged between UIMA Ruta and Python using the Python library dkpro-cassis and this sos-ruta package.
(In a Python cell) Load a UIMA Cas with dkpro-cassis.
import cassis
with open('MyTypeSystem.xml', 'rb') as f:
typesystem = cassis.load_typesystem(f)
with open("MyCasExample.xmi", "rb") as f:
cas1 = cassis.load_cas_from_xmi(f, typesystem=typesystem)
Transfer it to UIMA Cas using the %get cas1
magic command in a Ruta Cell. This automatically loads the content of the variable cas1
together with its TypeSystem into the current Cas in Ruta.
(In a Ruta cell) Execute the following magic that is provided by sos-ruta to pass a Cas from Python to Ruta.
%get cas1`
One can for instance inspect the results with a basic AnnotationViewer using the magic %displayMode DYNAMIC_HTML
.
If required, the Cas object can be passed back to Python using %put cas_output
which assigns the content of the current Cas in Uima Ruta to a variable named cas_output
in Python.
(In a Ruta cell) Execute the following magic that is provided by sos-ruta to pass the Cas from Ruta to Python.
%put cas_output
The tests in this repository use Selenium and Google Chrome to simulate a Jupyter Notebook. Please read more about sos-notebook tests here: https://vatlab.github.io/sos-docs/doc/user_guide/language_module.html#Testing.