-
Notifications
You must be signed in to change notification settings - Fork 3
Import lissa from jamieklein (squashed): replace upstream lissa with … #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* Licensed under MIT 2025. */ | ||
| package edu.kit.kastel.sdq.lissa.cli.command; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.nio.file.Path; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| import edu.kit.kastel.sdq.lissa.ratlr.cache.CacheManager; | ||
| import edu.kit.kastel.sdq.lissa.ratlr.configuration.Configuration; | ||
| import edu.kit.kastel.sdq.lissa.ratlr.optimizer.PromptOptimizer; | ||
|
|
||
| import picocli.CommandLine; | ||
|
|
||
| /** | ||
| * CLI subcommand for running LiSSA with a prompt-optimization loop. | ||
| * This command accepts a configuration file, a maximum number of optimization iterations, | ||
| * and a target F1 score. It delegates the optimization process to the PromptOptimizer. | ||
| */ | ||
| @CommandLine.Command(name = "optimize", description = "Runs LiSSA with a prompt-optimization loop") | ||
| public final class OptimizeCommand implements Runnable { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(OptimizeCommand.class); | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"-c", "--config"}, | ||
| required = true, | ||
| description = "Path to the LiSSA JSON configuration") | ||
| private Path config; | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"--max-iter"}, | ||
| defaultValue = "1", | ||
| description = "Maximum optimization iterations (≥1)") | ||
| private int maxIterations; | ||
|
|
||
| @CommandLine.Option( | ||
| names = {"--target-f1"}, | ||
| defaultValue = "0.40", | ||
| description = "Target F1 score to reach before stopping") | ||
| private double targetF1; | ||
|
|
||
| /** | ||
| * Executes the optimization process with the provided configuration. | ||
| * This method initializes the PromptOptimizer and starts the optimization loop. | ||
| */ | ||
| @Override | ||
| public void run() { | ||
| logger.info("Starting optimization for {}", config); | ||
| try { | ||
| Configuration fullConfig = new ObjectMapper().readValue(config.toFile(), Configuration.class); | ||
| String cacheDirectoryString = fullConfig.cacheDir(); | ||
| if (cacheDirectoryString != null) { | ||
| CacheManager.setCacheDir(cacheDirectoryString); | ||
| logger.info("Cache directory set to {}", cacheDirectoryString); | ||
| } else { | ||
| logger.warn("No cache directory found in configuration, caching may be disabled."); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| try { | ||
| new PromptOptimizer(config, maxIterations, targetF1).optimize(); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,10 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||
| import java.nio.file.Path; | ||||||||||||||||||
| import java.nio.file.Paths; | ||||||||||||||||||
| import java.util.Objects; | ||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||
| import java.util.SortedMap; | ||||||||||||||||||
|
|
||||||||||||||||||
| import org.slf4j.Logger; | ||||||||||||||||||
| import org.slf4j.LoggerFactory; | ||||||||||||||||||
|
|
@@ -15,10 +17,12 @@ | |||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.cache.CacheManager; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.classifier.Classifier; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.configuration.Configuration; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.context.ContextStore; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.configuration.GoldStandardConfiguration; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.elementstore.ElementStore; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.embeddingcreator.EmbeddingCreator; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.knowledge.Element; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.knowledge.TraceLink; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.optimizer.ClassificationResultsManager; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.postprocessor.TraceLinkIdPostprocessor; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.preprocessor.Preprocessor; | ||||||||||||||||||
| import edu.kit.kastel.sdq.lissa.ratlr.resultaggregator.ResultAggregator; | ||||||||||||||||||
|
|
@@ -36,10 +40,6 @@ | |||||||||||||||||
| * <li>Statistics generation and result storage</li> | ||||||||||||||||||
| * </ul> | ||||||||||||||||||
| * <p> | ||||||||||||||||||
| * The pipeline uses a {@link edu.kit.kastel.sdq.lissa.ratlr.context.ContextStore} to share context objects | ||||||||||||||||||
| * between components such as artifact providers, preprocessors, embedding creators, classifiers, and aggregators. | ||||||||||||||||||
| * </p> | ||||||||||||||||||
| * | ||||||||||||||||||
| * The pipeline follows these steps: | ||||||||||||||||||
| * <ol> | ||||||||||||||||||
| * <li>Load artifacts from configured providers</li> | ||||||||||||||||||
|
|
@@ -59,25 +59,45 @@ public class Evaluation { | |||||||||||||||||
|
|
||||||||||||||||||
| private Configuration configuration; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** Provider for source artifacts */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Provider for source artifacts | ||||||||||||||||||
| */ | ||||||||||||||||||
| private ArtifactProvider sourceArtifactProvider; | ||||||||||||||||||
| /** Provider for target artifacts */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Provider for target artifacts | ||||||||||||||||||
| */ | ||||||||||||||||||
| private ArtifactProvider targetArtifactProvider; | ||||||||||||||||||
| /** Preprocessor for source artifacts */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Preprocessor for source artifacts | ||||||||||||||||||
| */ | ||||||||||||||||||
| private Preprocessor sourcePreprocessor; | ||||||||||||||||||
| /** Preprocessor for target artifacts */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Preprocessor for target artifacts | ||||||||||||||||||
| */ | ||||||||||||||||||
| private Preprocessor targetPreprocessor; | ||||||||||||||||||
| /** Creator for element embeddings */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Creator for element embeddings | ||||||||||||||||||
| */ | ||||||||||||||||||
| private EmbeddingCreator embeddingCreator; | ||||||||||||||||||
| /** Store for source elements */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Store for source elements | ||||||||||||||||||
| */ | ||||||||||||||||||
| private ElementStore sourceStore; | ||||||||||||||||||
| /** Store for target elements */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Store for target elements | ||||||||||||||||||
| */ | ||||||||||||||||||
| private ElementStore targetStore; | ||||||||||||||||||
| /** Classifier for trace link analysis */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Classifier for trace link analysis | ||||||||||||||||||
| */ | ||||||||||||||||||
| private Classifier classifier; | ||||||||||||||||||
| /** Aggregator for classification results */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Aggregator for classification results | ||||||||||||||||||
| */ | ||||||||||||||||||
| private ResultAggregator aggregator; | ||||||||||||||||||
| /** Postprocessor for trace link IDs */ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Postprocessor for trace link IDs | ||||||||||||||||||
| */ | ||||||||||||||||||
| private TraceLinkIdPostprocessor traceLinkIdPostProcessor; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
|
|
@@ -86,11 +106,11 @@ public class Evaluation { | |||||||||||||||||
| * <ol> | ||||||||||||||||||
| * <li>Validates the configuration file path</li> | ||||||||||||||||||
| * <li>Loads and initializes the configuration</li> | ||||||||||||||||||
| * <li>Sets up all required components for the pipeline, sharing a {@link ContextStore}</li> | ||||||||||||||||||
| * <li>Sets up all required components for the pipeline</li> | ||||||||||||||||||
| * </ol> | ||||||||||||||||||
| * | ||||||||||||||||||
| * @param configFile Path to the configuration file | ||||||||||||||||||
| * @throws IOException If there are issues reading the configuration file | ||||||||||||||||||
| * @throws IOException If there are issues reading the configuration file | ||||||||||||||||||
| * @throws NullPointerException If configFile is null | ||||||||||||||||||
| */ | ||||||||||||||||||
| public Evaluation(Path configFile) throws IOException { | ||||||||||||||||||
|
|
@@ -119,25 +139,21 @@ private void setup() throws IOException { | |||||||||||||||||
| configuration = new ObjectMapper().readValue(configFile.toFile(), Configuration.class); | ||||||||||||||||||
| CacheManager.setCacheDir(configuration.cacheDir()); | ||||||||||||||||||
|
|
||||||||||||||||||
| ContextStore contextStore = new ContextStore(); | ||||||||||||||||||
|
|
||||||||||||||||||
| sourceArtifactProvider = | ||||||||||||||||||
| ArtifactProvider.createArtifactProvider(configuration.sourceArtifactProvider(), contextStore); | ||||||||||||||||||
| targetArtifactProvider = | ||||||||||||||||||
| ArtifactProvider.createArtifactProvider(configuration.targetArtifactProvider(), contextStore); | ||||||||||||||||||
| sourceArtifactProvider = ArtifactProvider.createArtifactProvider(configuration.sourceArtifactProvider()); | ||||||||||||||||||
| targetArtifactProvider = ArtifactProvider.createArtifactProvider(configuration.targetArtifactProvider()); | ||||||||||||||||||
|
|
||||||||||||||||||
| sourcePreprocessor = Preprocessor.createPreprocessor(configuration.sourcePreprocessor(), contextStore); | ||||||||||||||||||
| targetPreprocessor = Preprocessor.createPreprocessor(configuration.targetPreprocessor(), contextStore); | ||||||||||||||||||
| sourcePreprocessor = Preprocessor.createPreprocessor(configuration.sourcePreprocessor()); | ||||||||||||||||||
| targetPreprocessor = Preprocessor.createPreprocessor(configuration.targetPreprocessor()); | ||||||||||||||||||
|
|
||||||||||||||||||
| embeddingCreator = EmbeddingCreator.createEmbeddingCreator(configuration.embeddingCreator(), contextStore); | ||||||||||||||||||
| embeddingCreator = EmbeddingCreator.createEmbeddingCreator(configuration.embeddingCreator()); | ||||||||||||||||||
| sourceStore = new ElementStore(configuration.sourceStore(), false); | ||||||||||||||||||
| targetStore = new ElementStore(configuration.targetStore(), true); | ||||||||||||||||||
|
|
||||||||||||||||||
| classifier = configuration.createClassifier(contextStore); | ||||||||||||||||||
| aggregator = ResultAggregator.createResultAggregator(configuration.resultAggregator(), contextStore); | ||||||||||||||||||
| classifier = configuration.createClassifier(); | ||||||||||||||||||
| aggregator = ResultAggregator.createResultAggregator(configuration.resultAggregator()); | ||||||||||||||||||
|
|
||||||||||||||||||
| traceLinkIdPostProcessor = TraceLinkIdPostprocessor.createTraceLinkIdPostprocessor( | ||||||||||||||||||
| configuration.traceLinkIdPostprocessor(), contextStore); | ||||||||||||||||||
| traceLinkIdPostProcessor = | ||||||||||||||||||
| TraceLinkIdPostprocessor.createTraceLinkIdPostprocessor(configuration.traceLinkIdPostprocessor()); | ||||||||||||||||||
|
|
||||||||||||||||||
| configuration.serializeAndDestroyConfiguration(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -197,7 +213,25 @@ public Set<TraceLink> run() { | |||||||||||||||||
| traceLinks, configFile.toFile(), configuration, sourceArtifacts.size(), targetArtifacts.size()); | ||||||||||||||||||
| Statistics.saveTraceLinks(traceLinks, configFile.toFile(), configuration); | ||||||||||||||||||
|
|
||||||||||||||||||
| CacheManager.getDefaultInstance().flush(); | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Saves detailed classification results for trace links to disk. | ||||||||||||||||||
| * This includes generating JSON results and merging source/target elements | ||||||||||||||||||
| * to produce TP, FP, FN categorizations for further analysis. | ||||||||||||||||||
| */ | ||||||||||||||||||
|
Comment on lines
+216
to
+220
|
||||||||||||||||||
| /** | |
| * Saves detailed classification results for trace links to disk. | |
| * This includes generating JSON results and merging source/target elements | |
| * to produce TP, FP, FN categorizations for further analysis. | |
| */ | |
| // Saves detailed classification results for trace links to disk. | |
| // This includes generating JSON results and merging source/target elements | |
| // to produce TP, FP, FN categorizations for further analysis. |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty Javadoc line without any content. Line 246 has an empty Javadoc comment /** followed by just a newline and *. This should either contain documentation or be removed entirely.
| * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug print statement should be removed from production code. The
System.out.println("ARGS: " + Arrays.toString(args));statement at line 47 is a debugging leftover that should not be in the final codebase. Use proper logging instead or remove it entirely.