Skip to content

Johnsd11/ctakes-pbj-v-1.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cTAKES Installation Instructions:

Windows

-install tortoiseSVN https://tortoisesvn.net/downloads.html
-Make sure to check "command line client tools" when downloading tortoiseSVN
-Once tortoiseSVN is downloaded, open IntelliJ settings, go to the Version control tab on the left hand side. Select the subversion tab, then in the "path to Subversion executable" field fill in : C:\Program Files\TortoiseSVN\bin\svn.exe
-Download ctakes project using the get from VCS button on the "Welcome to IntelliJ" page. -Select the svn option from the Version Control dropdown and add https://svn.apache.org/repos/asf/ctakes/trunk/ then checkout
-Select the 1.8 working format of cTakes
-Go back to the "Welcome to IntelliJ" page and use the get from VCS button again, this time we want to use git.
-Copy this link "https://github.com/Johnsd11/ctakes-pbj-v-1.0" and then save the repo in cTakes under the folder "ctakes-pbj"

Mac and Linux

-Install Subversion using homebrew then type the command brew install subversion(for mac and linux)
-Download ctakes project using the get from VCS button on the "Welcome to IntelliJ" page. -Select the svn option from the Version Control dropdown and add https://svn.apache.org/repos/asf/ctakes/trunk/ then checkout
-Select the 1.8 working format of cTakes
-Go back to the "Welcome to IntelliJ" page and use the get from VCS button again, this time we want to use git.
-Copy this link "https://github.com/Johnsd11/Ctakes_PBJ" and then save the repo in cTakes under the folder "ctakes-pbj"

Windows

-install maven using a package manager: chocolatey
https://www.how2shout.com/how-to/download-and-install-maven-on-windows-10-or-11-via-command-line.html

Mac and Linux

-install maven using brew : brew install maven


-Search for and open pom.xml for ctakes trunk
- Once in the file scroll down until you come across the <modules> list
- add this line <module>ctakes-pbj</module> anywhere on the list
- Next look for the <dependency> list
- add these lines
<dependency>
<groupId>org.apache.ctakes</groupId>
<artifactId>ctakes-pbj</artifactId>
<version>${project.version}</version>
</dependency>
-Next open the maven tab on the top right of the intellij window, click Apache cTAKES, Lifecycle, install
-After this step, the ctakes-pbj directory will appear to have a blue square on it in the left hand side of IntelliJ that displays project structure.

Configurations

-add python plugin from the IntelliJ plugins store
-Set Project SDK: corretto-1.8
-Set Project language level: SDK default (8)
-install the latest version of java
-open Project Structure, navigate to modules tab on the left side, find ctakes-pbj, click on it and then press the plus sign and add python 3.8 to it
-IMPORTANT: You need to make sure that you follow the step above first before you mark the python and java directories as source roots.
-Make sure to mark the ctakes-pbj/src/main/python and ctakes-pbj/src/main/java directories as a source roots

Artemis Instructions For making a Broker:

-First download ActiveMQ Artemis here: https://activemq.apache.org/components/artemis/download/
-Naviagate to the downloaded apache-artemis folder in your command line
-from there cd into bin, then while in bin, type "./artemis create mybroker" for MAC or for windows "artemis create mybroker"
-This will prompt a Username and Password which can be anything you want
-It will also prompt something called --allow-anonymous, Press Y
-From here you can now cd into mybroker/bin
-Once you are in bin again you can run "./artemis run" for MAC or "artemis run" for windows to start the broker
-Here are more directions if you need more help or clarification
-https://activemq.apache.org/components/artemis/documentation/1.0.0/running-server.html

Usage

Example piper files can be found in ctakes-examples and example py files can be found in the ctakes-pbj/examples folder

Creating a Piper file

This is an example piper file that will spin up a complete pbj pipeline.

#  This piper will start the Apache Artemis broker pointed to by the -a parameter on the command line.
#  It will pause for 5 seconds to allow Artemis to fully launch.
#
#  This piper will then launch another instance of Apache cTAKES.
#  That instance of cTAKES will run the third and final bit of the entire PBJ pipeline.
#
#  This piper will then launch a python PBJ bit of the entire pipeline.

We set setJavaHome = no, this is keep things consistent ??????

set SetJavaHome=no

The parameters you need to run the piper file are:

#
#  To run this pipeline from the command line, use the parameters:
#  -p PbjFirstStep
#  -d {python environment Directory}
#  -a {Artemis Broker Directory}
#  -i {Input Document Directory}
#  -o {Output Directory}

Sets up required parameters, starts your Artemis Broker, pips the PBJ project.

load PbjStarter

Start another instance of cTAKES, running the pipeline in StartAllExample_end.piper
$OutputDirectory will substitute the value of this cTAKES pipeline's value for OutputDirectory.
$ArtemisBroker will substitute the value of this cTAKES pipeline's value for ArtemisBroker.

add CtakesRunner Pipeline="-p PbjThirdStep -o $OutputDirectory -a $ArtemisBroker"

Declare the python pipeline defining the second step in the total pipeline.

set PbjSecondStep=ctakes_pbj.examples.word_finder_pipeline

There is a fixed order to queue specification in python pipelines.
The incoming (receiver) queue is named first, the outgoing (sender) queue is named second.

add PythonRunner Command="-m $PbjSecondStep JavaToPy PyToJava" LogFile=word_finder_pipeline.log

The pipeline run by this instance of cTAKES.
Load a simple token processing pipeline from another pipeline file

load DefaultTokenizerPipeline

Send CAS to Artemis at the specified queue. Send stop signal when processing has finished.

add PbjSender SendQueue=JavaToPy SendStop=yes

Example py file: WordFinder.py

Start with a function names process

def process(self, cas):
    

While we could use ct.create_type to create and add types, for each type lookup the cas array is searched.
So it is faster to get the types first and then create instances with ct.add_type

anatomy_type = cas.typesystem.get_type(AnatomicalSiteMention)
symptom_type = cas.typesystem.get_type(SignSymptomMention)
procedure_type = cas.typesystem.get_type(ProcedureMention)

Assigning values to sites, findings, and procedures.

sites = ['breast']
findings = ['hernia', 'pain', 'migraines', 'allergies']
procedures = ['thyroidectomy', 'exam']

Not sure what to write here

for segment in cas.select(Segment):
    text = segment.get_covered_text()
    for word in sites:
        begin = text.find(word)
        if begin > -1:
            print("found Anatomic Site")
            end = begin + len(word)
            add_type(cas, anatomy_type, begin, end)
    for word in findings:
        begin = text.find(word)
        if begin > -1:
            print("found Sign or Symptom")
            end = begin + len(word)
            add_type(cas, symptom_type, begin, end)
    for word in procedures:
        begin = text.find(word)
        if begin > -1:
            print("found Procedure")
            end = begin + len(word)
            add_type(cas, procedure_type, begin, end)

Example pipeline file: WordFinderPipeline.py

Start by creating an instance of the pipeline

pipeline = PBJPipeline()

Then adding the process(es)

pipeline.add(WordFinder())
...

Last is adding the sender and receiver while also initializing the pipeline

pipeline.add(PBJSender())
pipeline.initialize()
start_receiver(pipeline)

Running an Example

-You can start running an example by creating an application configuration
-You can call it whatever you want, we called it "StartAllExample"
-Copy down the information you see in the picture below
step3
-p "org/apache/ctakes/pbj/pipeline/StartAllExample"
-i "org/apache/ctakes/examples/notes/annotated"
-a "[Destination of your Artemis Broker]"
-d "[Destinaiton of your python.exe]"
step1

End-to-end PBJ Examples

Temporal Example

  • You first need to get the API side up and running. To do this you need to follow the steps listed here.
  • Once that is running you need to then create this configuration for StartTemporalExample.piper file.
    -p
    org/apache/ctakes/pbj/pipeline/StartTemporalExample
    -i
    (input)
    -a
    (folder where your Artemis broker is)
    -d
    (enviroment)
    -o
    (output)
    --key
    (UMLS key)
  • You should now be able to run that piper file while the API side is running. You can look at the output of running the piper file in "temporal_py.log" as well as the output file that you put into the configuration.

Negation Example

  • You first need to get the API side up and running. To do this you need to follow the steps listed here.
  • Once that is running you need to then create this configuration for StartNegationExample.piper file.
    -p
    org/apache/ctakes/pbj/pipeline/StartNegationExample
    -i
    (input)
    -a
    (folder where your Artemis broker is)
    -d
    (enviroment)
    -o
    (output)
    --key
    (UMLS key)
  • You should now be able to run that piper file while the API side is running. You can look at the output of running the piper file in "negation_py.log" as well as the output file that you put into the configuration.

DTR Example

  • You first need to get the API side up and running. To do this you need to follow the steps listed here.
  • Once that is running you need to then create this configuration for StartDtrExample.piper file.
    -p
    org/apache/ctakes/pbj/pipeline/StartDtrExample
    -i
    (input)
    -a
    (folder where your Artemis broker is)
    -d
    (enviroment)
    -o
    (output)
    --key
    (UMLS key)
  • You should now be able to run that piper file while the API side is running. You can look at the output of running the piper file in "dtr_py.log" as well as the output file that you put into the configuration.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published