Skip to content

Commit

Permalink
Merge pull request #201 from Wimmics/development
Browse files Browse the repository at this point in the history
Merge development changes to doc_development
  • Loading branch information
AnnaBobasheva authored Nov 18, 2024
2 parents c9072e7 + bca607c commit 78bc4a1
Show file tree
Hide file tree
Showing 142 changed files with 7,948 additions and 3,303 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
contents: write
steps:

- name: Checkout doc_development branch
- name: Checkout development branch
uses: actions/checkout@v4
with:
ref: doc_development
ref: development

- name: Build Sphinx Docs
uses: ammaraskar/sphinx-action@master
Expand All @@ -29,7 +29,7 @@ jobs:

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/doc_development'
if: github.ref == 'refs/heads/development'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build/html
Expand Down
37 changes: 27 additions & 10 deletions corese-command/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,46 @@

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<!-- CLI Interface -->
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.4</version>
<version>4.7.6</version>
</dependency>

<!-- Corese -->
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>corese-core</artifactId>
</dependency>

<!-- Unit Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.0-M1</version>
<scope>test</scope>
</dependency>

<!-- Mock HTTPS Server for Test -->
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
27 changes: 24 additions & 3 deletions corese-command/src/main/java/fr/inria/corese/command/App.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
package fr.inria.corese.command;

import fr.inria.corese.command.programs.canonicalize;
import fr.inria.corese.command.programs.Canonicalize;
import fr.inria.corese.command.programs.Convert;
import fr.inria.corese.command.programs.RemoteSparql;
import fr.inria.corese.command.programs.Shacl;
import fr.inria.corese.command.programs.Sparql;
import picocli.AutoComplete.GenerateCompletion;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Ansi.Style;
import picocli.CommandLine.Help.ColorScheme;

@Command(name = "Corese-command", version = App.version, mixinStandardHelpOptions = true, subcommands = {
Convert.class, Sparql.class, Shacl.class, RemoteSparql.class, canonicalize.class
Convert.class, Sparql.class, Shacl.class, RemoteSparql.class, Canonicalize.class, GenerateCompletion.class
})

public final class App implements Runnable {

public final static String version = "4.5.1";

public static void main(String[] args) {
int exitCode = new CommandLine(new App()).execute(args);
// Define the color scheme
ColorScheme colorScheme = new ColorScheme.Builder()
.commands(Style.bold) // Commands in blue
.options(Style.fg_yellow) // Options in yellow
.parameters(Style.fg_cyan, Style.bold) // Parameters in cyan and bold
.optionParams(Style.italic, Style.fg_cyan) // Option parameters in italic
.errors(Style.fg_red, Style.bold) // Errors in red and bold
.stackTraces(Style.italic) // Stack traces in italic
.applySystemProperties() // Apply system properties for colors
.build();

CommandLine commandLine = new CommandLine(new App()).setColorScheme(colorScheme);

// Hide the generate-completion command
CommandLine gen = commandLine.getSubcommands().get("generate-completion");
gen.getCommandSpec().usageMessage().hidden(true);

// Execute the command
int exitCode = commandLine.execute(args);
System.exit(exitCode);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package fr.inria.corese.command.programs;

import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.Callable;

import fr.inria.corese.command.App;
import fr.inria.corese.command.utils.ConfigManager;
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
import fr.inria.corese.core.util.Property;
import fr.inria.corese.core.util.Property.Value;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.Spec;

/**
* Abstract class for all commands.
*
* This class provides common options and methods for all commands.
*/
@Command(version = App.version)
public abstract class AbstractCommand implements Callable<Integer> {

///////////////
// Constants //
///////////////

// Exit codes
protected final int ERROR_EXIT_CODE_SUCCESS = 0;
protected final int ERROR_EXIT_CODE_ERROR = 1;

/////////////
// Options //
/////////////

@Option(names = { "-o",
"--output-data" }, description = "Specifies the output file path. If not provided, the result will be written to standard output.", arity = "0..1", fallbackValue = RdfDataExporter.DEFAULT_OUTPUT)
protected Path output;

@Option(names = { "-c", "--config",
"--init" }, description = "Specifies the path to a configuration file. If not provided, the default configuration file will be used.", required = false)
private Path configFilePath;

@Option(names = { "-v",
"--verbose" }, description = "Enables verbose mode, printing more information about the execution of the command.", negatable = true)
protected boolean verbose = false;

@Option(names = { "-w",
"--owl-import" }, description = "Disables the automatic importation of ontologies specified in 'owl:imports' statements. When this flag is set, the application will not fetch and include referenced ontologies. Default is '${DEFAULT-VALUE}'.", required = false, defaultValue = "false", negatable = true)
private boolean noOwlImport;

////////////////
// Properties //
////////////////

// Command specification
@Spec
protected CommandSpec spec;

// Output
protected Boolean outputToFileIsDefault = false;

/////////////
// Methods //
/////////////

@Override
public Integer call() {

// Load configuration file
Optional<Path> configFilePath = Optional.ofNullable(this.configFilePath);
if (configFilePath.isPresent()) {
ConfigManager.loadFromFile(configFilePath.get(), this.spec, this.verbose);
} else {
ConfigManager.loadDefaultConfig(this.spec, this.verbose);
}

// Set owl import
Property.set(Value.DISABLE_OWL_AUTO_IMPORT, this.noOwlImport);

return 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package fr.inria.corese.command.programs;

import java.nio.file.Path;

import picocli.CommandLine.Option;

public abstract class AbstractInputCommand extends AbstractCommand {

@Option(names = { "-i",
"--input-data" }, description = "Specifies the path or URL of the input RDF data. Multiple values are allowed.", arity = "1...")
protected String[] inputsRdfData;

@Option(names = { "-R",
"--recursive" }, description = "If set to true and an input is a directory, all files in the directory will be loaded recursively. Default value: ${DEFAULT-VALUE}.", defaultValue = "false")
protected boolean recursive = false;

@Override
public Integer call() {
super.call();

// Check input values
this.checkInputValues();

return 0;
}

/**
* Check if the input values are correct.
*
* @throws IllegalArgumentException if input path is same as output path.
*/
private void checkInputValues() throws IllegalArgumentException {
if (this.inputsRdfData != null && this.output != null) {
for (String input : this.inputsRdfData) {
if (Path.of(input).compareTo(this.output) == 0) {
throw new IllegalArgumentException("Input path cannot be same as output path: " + input);
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package fr.inria.corese.command.programs;

import fr.inria.corese.command.utils.exporter.rdf.EnumCanonicAlgo;
import fr.inria.corese.command.utils.exporter.rdf.RdfDataCanonicalizer;
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
import fr.inria.corese.core.Graph;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "canonicalize", description = "Canonicalize an RDF file to a specific format.", mixinStandardHelpOptions = true)
public class Canonicalize extends AbstractInputCommand {

@Option(names = { "-f", "-if",
"--input-format" }, description = "Specifies the RDF serialization format of the input file. Available options are: :@|fg(225) ${COMPLETION-CANDIDATES}|@.")
private EnumRdfInputFormat inputFormat;

@Option(names = { "-a", "-ca", "-r", "-of",
"--canonical-algo" }, required = true, description = "Specifies the canonicalization algorithm to be applied to the input file. Available options are: :@|fg(225) ${COMPLETION-CANDIDATES}|@. The default algorithm is ${DEFAULT-VALUE}.", defaultValue = "rdfc-1.0")
private EnumCanonicAlgo canonicalAlgo;

public Canonicalize() {
}

@Override
public Integer call() {

super.call();

try {
// Load the input file(s)
RdfDataLoader loader = new RdfDataLoader(this.spec, this.verbose);
Graph graph = loader.load(this.inputsRdfData, this.inputFormat, this.recursive);

// Canonicalize and export the graph
RdfDataCanonicalizer rdfCanonicalizer = new RdfDataCanonicalizer(this.spec, this.verbose, this.output);
rdfCanonicalizer.export(graph, this.canonicalAlgo);

return this.ERROR_EXIT_CODE_SUCCESS;
} catch (IllegalArgumentException e) {
this.spec.commandLine().getErr().println("Error: " + e.getMessage());
return this.ERROR_EXIT_CODE_ERROR;
}
}

}
Loading

0 comments on commit 78bc4a1

Please sign in to comment.