# sp1r0s/java-ai-examples architecture

> Architecture diagram of the GitHub repository sp1r0s/java-ai-examples, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sp1r0s/java-ai-examples
- Repository: https://github.com/sp1r0s/java-ai-examples

## Overview

This repository is a set of runnable Java AI examples, not one combined application. Users start an example through its main method: image selection leads to face detection and an annotated image; text documents go through Spark classification; battery-charge input produces a regression estimate; and a sample sentence produces sentiment labels. The graph preserves these distinct workflows and their documented libraries. The README identifies the four capabilities; source excerpts show their implementations, though not every internal integration is sampled.

Main entry points: [`src/main/java/ml/SparkMLExample.java`](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java) (Text classifier), [`src/main/java/cv/FaceDetector.java`](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceDetector.java) (Face detector), [`src/main/java/ml/WekaBatteryPredictionExample.java`](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/WekaBatteryPredictionExample.java) (Battery predictor), [`src/main/java/cv/FaceRecognitionExample.java`](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceRecognitionExample.java) (Image selection UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Computer vision"]
  node_face_ui["Image selection UI"]
  node_face_detector["Face detector<br/>[FaceDetector.java]"]
  node_cascade["Face cascade"]
  node_annotated_image["Annotated image<br/>[FaceDetector.java]"]
end

subgraph group_ml["Machine learning"]
  node_spark_app["Text classifier"]
  node_labeled_docs["Labeled documents"]
  node_documents["Unlabeled documents<br/>[Document.java]"]
  node_tokenizer["Tokenizer"]
  node_feature_hashing["Feature hashing"]
  node_logistic_regression["Logistic regression"]
  node_prediction_output["Class predictions"]
  node_weka_app["Battery predictor"]
  node_training_data["Training data<br/>[training-set.txt]"]
  node_battery_estimate["Battery estimate"]
end

subgraph group_nlp["Language processing"]
  node_nlp_app["Sentiment example<br/>[NLPExample.java]"]
  node_sentiment_output["Sentence sentiment<br/>[NLPExample.java]"]
end

node_user(("Example user"))
node_opencv["OpenCV"]
node_spark["Apache Spark"]
node_weka["Weka"]
node_stanford_nlp["Stanford NLP"]

node_user -->|"starts"| node_face_ui
node_face_ui -->|"calls"| node_face_detector
node_face_detector -->|"loads"| node_cascade
node_face_detector -->|"detects faces"| node_opencv
node_face_detector -->|"returns"| node_annotated_image
node_face_ui -->|"displays"| node_annotated_image
node_user -->|"starts"| node_spark_app
node_spark_app -->|"creates training data"| node_labeled_docs
node_spark_app -->|"creates test data"| node_documents
node_spark_app -->|"configures"| node_tokenizer
node_spark_app -->|"configures"| node_feature_hashing
node_spark_app -->|"configures"| node_logistic_regression
node_spark_app -->|"runs pipeline"| node_spark
node_spark_app -->|"prints predictions"| node_prediction_output
node_user -->|"starts"| node_weka_app
node_weka_app -->|"loads"| node_training_data
node_weka_app -->|"trains and predicts"| node_weka
node_weka_app -->|"prints estimate"| node_battery_estimate
node_user -->|"starts"| node_nlp_app
node_nlp_app -->|"processes text"| node_stanford_nlp
node_nlp_app -->|"prints sentiment"| node_sentiment_output

click node_face_ui "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceRecognitionExample.java"
click node_face_detector "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceDetector.java"
click node_cascade "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/resources/lbpcascade_frontalface.xml"
click node_annotated_image "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceDetector.java"
click node_spark_app "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java"
click node_labeled_docs "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/LabeledDocument.java"
click node_documents "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/Document.java"
click node_tokenizer "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java"
click node_feature_hashing "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java"
click node_logistic_regression "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java"
click node_prediction_output "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java"
click node_weka_app "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/WekaBatteryPredictionExample.java"
click node_training_data "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/resources/training-set.txt"
click node_battery_estimate "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/WekaBatteryPredictionExample.java"
click node_nlp_app "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/nlp/NLPExample.java"
click node_sentiment_output "https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/nlp/NLPExample.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_face_ui,node_face_detector,node_cascade,node_annotated_image,node_user toneBlue
class node_spark_app,node_labeled_docs,node_documents,node_tokenizer,node_feature_hashing,node_logistic_regression,node_prediction_output,node_weka_app,node_training_data,node_battery_estimate toneAmber
class node_nlp_app,node_sentiment_output toneMint
class node_opencv,node_spark,node_weka,node_stanford_nlp toneIndigo
```

## Components

### Computer vision

- [Image selection UI](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceRecognitionExample.java): `src/main/java/cv/FaceRecognitionExample.java`
- [Face detector](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceDetector.java): `src/main/java/cv/FaceDetector.java`
- [Face cascade](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/resources/lbpcascade_frontalface.xml): `src/main/resources/lbpcascade_frontalface.xml`
- [Annotated image](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/cv/FaceDetector.java): `src/main/java/cv/FaceDetector.java`

### Machine learning

- [Text classifier](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java): `src/main/java/ml/SparkMLExample.java`
- [Labeled documents](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/LabeledDocument.java): `src/main/java/ml/LabeledDocument.java`
- [Unlabeled documents](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/Document.java): `src/main/java/ml/Document.java`
- [Tokenizer](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java): `src/main/java/ml/SparkMLExample.java`
- [Feature hashing](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java): `src/main/java/ml/SparkMLExample.java`
- [Logistic regression](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java): `src/main/java/ml/SparkMLExample.java`
- [Class predictions](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/SparkMLExample.java): `src/main/java/ml/SparkMLExample.java`
- [Battery predictor](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/WekaBatteryPredictionExample.java): `src/main/java/ml/WekaBatteryPredictionExample.java`
- [Training data](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/resources/training-set.txt): `src/main/resources/training-set.txt`
- [Battery estimate](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/ml/WekaBatteryPredictionExample.java): `src/main/java/ml/WekaBatteryPredictionExample.java`

### Language processing

- [Sentiment example](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/nlp/NLPExample.java): `src/main/java/nlp/NLPExample.java`
- [Sentence sentiment](https://github.com/sp1r0s/java-ai-examples/blob/master/src/main/java/nlp/NLPExample.java): `src/main/java/nlp/NLPExample.java`

### Other components

- **Example user**
- **OpenCV**
- **Apache Spark**
- **Weka**
- **Stanford NLP**

## Connections

- Example user → Image selection UI: starts (evidence: `README.md`)
- Image selection UI → Face detector: calls (evidence: `src/main/java/cv/FaceRecognitionExample.java`)
- Face detector → Face cascade: loads (evidence: `src/main/java/cv/FaceDetector.java`)
- Face detector → OpenCV: detects faces (evidence: `src/main/java/cv/FaceDetector.java`)
- Face detector → Annotated image: returns (evidence: `src/main/java/cv/FaceDetector.java`)
- Image selection UI → Annotated image: displays (evidence: `src/main/java/cv/FaceRecognitionExample.java`)
- Example user → Text classifier: starts (evidence: `README.md`)
- Text classifier → Labeled documents: creates training data (evidence: `src/main/java/ml/SparkMLExample.java`)
- Text classifier → Unlabeled documents: creates test data (evidence: `src/main/java/ml/SparkMLExample.java`)
- Text classifier → Tokenizer: configures (evidence: `src/main/java/ml/SparkMLExample.java`)
- Text classifier → Feature hashing: configures (evidence: `src/main/java/ml/SparkMLExample.java`)
- Text classifier → Logistic regression: configures (evidence: `src/main/java/ml/SparkMLExample.java`)
- Text classifier → Apache Spark: runs pipeline (evidence: `src/main/java/ml/SparkMLExample.java`)
- Text classifier → Class predictions: prints predictions (evidence: `src/main/java/ml/SparkMLExample.java`)
- Example user → Battery predictor: starts (evidence: `README.md`)
- Battery predictor → Training data: loads (evidence: `src/main/java/ml/WekaBatteryPredictionExample.java`)
- Battery predictor → Weka: trains and predicts (evidence: `src/main/java/ml/WekaBatteryPredictionExample.java`)
- Battery predictor → Battery estimate: prints estimate (evidence: `src/main/java/ml/WekaBatteryPredictionExample.java`)
- Example user → Sentiment example: starts (evidence: `README.md`)
- Sentiment example → Stanford NLP: processes text (evidence: `src/main/java/nlp/NLPExample.java`)
- Sentiment example → Sentence sentiment: prints sentiment (evidence: `src/main/java/nlp/NLPExample.java`)
