### Install and Initialize SDKMAN
Source: https://github.com/clulab/processors/blob/master/README-M1.md
This snippet provides the commands to download and install sdkman from its source, followed by initializing it in the current shell session. It concludes with a command to verify the successful installation of sdkman.
```bash
# install sdkman from source:
curl -s "https://get.sdkman.io" | bash
# open a new terminal window and run the following:
source "$HOME/.sdkman/bin/sdkman-init.sh"
# test your installation:
sdk version
```
--------------------------------
### Install SVM-Rank and SVMLight Binaries via Homebrew
Source: https://github.com/clulab/processors/blob/master/docs/install.md
This Bash command sequence demonstrates how to install the optional `svm-rank` and `svmlight` external binaries on Mac OS X. It involves adding a custom Homebrew tap and then installing the packages.
```Bash
brew tap myedibleenso/nlp
brew install svmlight svmrank
```
--------------------------------
### Install Python Dependencies for Text Analysis Script
Source: https://github.com/clulab/processors/blob/master/library/src/main/python/embedding_generator/README.md
This command installs all necessary Python libraries for the `main.py` script by reading the `requirements.txt` file. It ensures the environment is set up correctly to run the text analysis tool.
```bash
pip install -r requirements.txt
```
--------------------------------
### Install SBT and Scala with SDKMAN
Source: https://github.com/clulab/processors/blob/master/README-M1.md
These commands facilitate the installation of sbt (version 1.6.1) and scala (version 2.12.15) via sdkman. These are essential tools for Scala development and are installed to be compatible with the M1 architecture.
```bash
# sbt 1.6
sdk install sbt 1.6.1
# scala 2.12
sdk install scala 2.12.15
```
--------------------------------
### Standard Odin ExtractorEngine Initialization
Source: https://github.com/clulab/processors/blob/master/docs/debugging.md
This snippet demonstrates the typical setup for an Odin ExtractorEngine, including processor annotation and rule-based extraction, before any debugger integration.
```scala
import org.clulab.odin.ExtractorEngine
import org.clulab.processors.clu.CluProcessor
...
val sentence = "..."
val processor = new CluProcessor()
val document = processor.annotate(sentence)
val rules = "..."
val extractorEngine = ExtractorEngine(rules)
val mentions = extractorEngine.extractFrom(document)
```
--------------------------------
### Integrating DebuggingExtractorEngine (Replacement Approach)
Source: https://github.com/clulab/processors/blob/master/docs/debugging.md
An alternative integration method where the DebuggingExtractorEngine directly replaces the instantiation of the standard ExtractorEngine. This simplifies the setup by creating the debugging engine from the start.
```scala
import org.clulab.odin.ExtractorEngine
import org.clulab.odin.debugger.odin.DebuggingExtractorEngine
import org.clulab.processors.clu.CluProcessor
...
val sentence = "..."
val processor = new CluProcessor()
val document = processor.annotate(sentence)
val rules = "..."
val extractorEngine = DebuggingExtractorEngine(ExtractorEngine(rules))
val mentions = extractorEngine.extractFrom(document)
```
--------------------------------
### Run Text Analysis Script with Hugging Face Dataset
Source: https://github.com/clulab/processors/blob/master/library/src/main/python/embedding_generator/README.md
This example shows how to run the `main.py` script using a specific Hugging Face dataset (e.g., 'wikipedia') and an optional subpart. It includes all required parameters like model, tokenizer, context size, device, token count, and a random seed, allowing for analysis on external datasets.
```bash
/home/gigi/hdd/DeBERTa/env/bin/python main.py --context_size 512 --model_type 'microsoft/deberta-base' --tokenizer 'microsoft/deberta-base' --device 'cuda' --number_of_tokens 1000 --huggingface_dataset wikipedia --huggingface_subpart 20220301.en --seed 42
```
--------------------------------
### Run Webapp in SBT Development Mode
Source: https://github.com/clulab/processors/blob/master/webapp/README.md
Start the webapp directly from within sbt for local development. The web page will be accessible at http://localhost:9000.
```sbt
webapp/run
```
--------------------------------
### Run Text Analysis Script with Default Dataset
Source: https://github.com/clulab/processors/blob/master/library/src/main/python/embedding_generator/README.md
This example demonstrates how to execute the `main.py` script using its default dataset (`text_data.json`). It specifies essential parameters such as the model type, tokenizer, context size, processing device, number of tokens to analyze, and a random seed for reproducible results.
```bash
/home/gigi/hdd/DeBERTa/env/bin/python main.py --context_size 512 --model_type 'microsoft/deberta-base' --tokenizer 'microsoft/deberta-base' --device 'cuda' --number_of_tokens 1000 --seed 42
```
--------------------------------
### Install ARM64 Java 11 with SDKMAN
Source: https://github.com/clulab/processors/blob/master/README-M1.md
This command installs a specific ARM64-compatible distribution of Java 11 (Zulu 11.0.14) using sdkman. This version is recommended for M1 Macs and is also compatible with Intel machines.
```bash
sdk install java 11.0.14-zulu
```
--------------------------------
### Configure CLULAB Processors Dependencies in sbt Build
Source: https://github.com/clulab/processors/blob/master/docs/install.md
This Scala snippet shows the equivalent dependency configuration for `processors` and `processors-model` within an `sbt` build file. Remember to substitute `x.x.x` and `y.y.y` with the appropriate library version numbers.
```Scala
libraryDependencies ++= {
Seq(
"org.clulab" %% "processors" % "x.x.x",
"org.clulab" % "processors-model" % "y.y.y"
)
}
```
--------------------------------
### Annotating Entire Documents with BalaurProcessor (Scala)
Source: https://github.com/clulab/processors/blob/master/docs/processors.md
This Scala example demonstrates how to use the `BalaurProcessor` to annotate a full document, performing various NLP tasks like tokenization, lemmatization, POS tagging, and named entity recognition. It iterates through sentences and prints detailed annotations including words, offsets, lemmas, POS tags, chunks, entities, normalized entities, and syntactic dependencies.
```scala
package org.clulab.processors.apps
import org.clulab.processors.{Document, Processor}
import org.clulab.struct.DirectedGraphEdgeIterator
object ProcessorsScalaExample extends App {
val proc = Processor()
// The actual work is done here.
val doc: Document = proc.annotate("John Smith went to China. He visited Beijing on January 10th, 2013.")
// Let's print the sentence-level annotations.
for ((sentence, sentenceIndex) <- doc.sentences.zipWithIndex) {
println("Sentence #" + sentenceIndex + ":")
println("Tokens: " + mkString(sentence.words))
println("Start character offsets: " + mkString(sentence.startOffsets))
println("End character offsets: " + mkString(sentence.endOffsets))
// These annotations are optional, so they are stored using Option objects,
// hence the foreach statement.
sentence.lemmas.foreach(lemmas => println("Lemmas: " + mkString(lemmas)))
sentence.tags.foreach(tags => println("POS tags: " + mkString(tags)))
sentence.chunks.foreach(chunks => println("Chunks: " + mkString(chunks)))
sentence.entities.foreach(entities => println("Named entities: " + mkString(entities)))
sentence.norms.foreach(norms => println("Normalized entities: " + mkString(norms)))
sentence.dependencies.foreach { dependencies =>
println("Syntactic dependencies:")
val iterator = new DirectedGraphEdgeIterator[String](dependencies)
iterator.foreach { dep =>
// Note that we use offsets starting at 0 unlike CoreNLP, which uses offsets starting at 1.
println(" head: " + dep._1 + " modifier: " + dep._2 + " label: " + dep._3)
}
}
println()
}
def mkString[T](elems: Array[T]): String = elems.mkString(" ")
}
```
--------------------------------
### Odin Debugger Stack View Log Example
Source: https://github.com/clulab/processors/blob/master/docs/debugging.md
This log snippet illustrates the output of the Odin Debugger's Stack View. It shows the execution flow of the Odin algorithm, detailing method calls, loop iterations, and token processing within the DebuggingExtractorEngine and related components. The output is designed to be clickable in IntelliJ, linking directly to source code locations.
```Log
beg loop org.clulab.odin.debugger.odin.InnerDebuggingExtractorEngine#extract(DebuggingExtractorEngine.scala:17)[](loop = 1)
beg extractor org.clulab.odin.debugger.odin.DebuggingTokenExtractor#findAllIn(DebuggingTokenExtractor.scala:23)["four-As"]()
beg tokenPattern org.clulab.odin.debugger.odin.DebuggingTokenExtractor#findAllIn(DebuggingTokenExtractor.scala:24)["tokenPattern"]()
beg sentence org.clulab.odin.debugger.odin.DebuggingTokenExtractor#findAllIn(DebuggingTokenExtractor.scala:29)[](index = 0, sentence = "John Doe eats cake .")
beg start org.clulab.odin.debugger.odin.DebuggingTokenPattern#findFirstIn loop r(DebuggingTokenPattern.scala:26)[](start = 0)
beg tok org.clulab.odin.debugger.odin.DebuggingThompsonVM.DebuggingEvaluator#mkThreads(DebuggingThompsonVM.scala:56)[](tok = 0)
instMatches org.clulab.odin.debugger.odin.DebuggingThompsonVM.DebuggingEvaluator#mkThreads loop(DebuggingThompsonVM.scala:78)[](matches = true, ...)
end tok org.clulab.odin.debugger.odin.DebuggingThompsonVM.DebuggingEvaluator#mkThreads(DebuggingThompsonVM.scala:56)[](tok = 0)
beg tok org.clulab.odin.debugger.odin.DebuggingThompsonVM.DebuggingEvaluator#stepSingleThread(DebuggingThompsonVM.scala:114)[](tok = 0)
...
```
--------------------------------
### Add CLULAB Processors Dependencies to Maven pom.xml
Source: https://github.com/clulab/processors/blob/master/docs/install.md
This XML snippet illustrates how to declare the `processors` and `processors-model` libraries as dependencies in a Maven `pom.xml` file. Users should replace `x.x.x` and `y.y.y` with the latest stable version numbers, such as `10.0.0` for `processors` and `0.3.1` for `processors-model`.
```XML
org.clulabprocessors_2.12x.x.xorg.clulabprocessors-modely.y.y
```
--------------------------------
### Debug Webapp with Remote JVM Debugging
Source: https://github.com/clulab/processors/blob/master/webapp/README.md
Enable remote JVM debugging for the webapp by starting sbt with a debug port. This allows setting breakpoints in an IDE like IntelliJ.
```sbt
sbt -jvm-debug 5005
```
--------------------------------
### Configure SDKMAN for ARM64 Compatibility
Source: https://github.com/clulab/processors/blob/master/README-M1.md
This configuration line, to be added or modified in the sdkman config file, ensures that sdkman only lists and installs ARM64-compatible versions of software. Setting sdkman_rosetta2_compatible to false prevents the listing of Intel-only distributions.
```properties
sdkman_rosetta2_compatible=false
```
--------------------------------
### Process Text with CLULAB Processors in Java
Source: https://github.com/clulab/processors/blob/master/docs/processors.md
This Java example demonstrates how to initialize a CLULAB Processor, annotate a given text, and then iterate through the resulting Document and Sentence objects to extract various linguistic annotations such as tokens, lemmas, POS tags, chunks, named entities, normalized entities, and syntactic dependencies. It includes helper methods for string formatting and converting Scala iterators to Java iterables.
```java
package org.clulab.processors.apps;
import org.clulab.processors.Document;
import org.clulab.processors.Processor;
import org.clulab.processors.Processor$;
import org.clulab.processors.Sentence;
import org.clulab.struct.DirectedGraphEdgeIterator;
import org.clulab.utils.JavaUtils;
import java.util.Iterator;
public class ProcessorsJavaExample {
public static void main(String [] args) throws Exception {
// Create the processor
Processor proc = Processor$.MODULE$.mkProcessor();
// The actual work is done here.
Document doc = proc.annotate("John Smith went to China. He visited Beijing on January 10th, 2013.", false);
// You are basically done. The rest of this code simply prints out the annotations.
// Let's print the sentence-level annotations.
for (int sentenceIndex = 0; sentenceIndex < doc.sentences().length; sentenceIndex++) {
Sentence sentence = doc.sentences()[sentenceIndex];
System.out.println("Sentence #" + sentenceIndex + ":");
System.out.println("Tokens: " + mkString(sentence.words()));
System.out.println("Start character offsets: " + mkString(sentence.startOffsets()));
System.out.println("End character offsets: " + mkString(sentence.endOffsets()));
// These annotations are optional, so they are stored using Option objects,
// hence the isDefined() and get() calls.
if (sentence.lemmas().isDefined())
System.out.println("Lemmas: " + mkString(sentence.lemmas().get()));
if (sentence.tags().isDefined())
System.out.println("POS tags: " + mkString(sentence.tags().get()));
if (sentence.chunks().isDefined())
System.out.println("Chunks: " + mkString(sentence.chunks().get()));
if (sentence.entities().isDefined())
System.out.println("Named entities: " + mkString(sentence.entities().get()));
if (sentence.norms().isDefined())
System.out.println("Normalized entities: " + mkString(sentence.norms().get()));
if (sentence.dependencies().isDefined()) {
System.out.println("Syntactic dependencies:");
Iterator> iterator =
JavaUtils.asJava(new DirectedGraphEdgeIterator<>(sentence.dependencies().get()));
for (scala.Tuple3