Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 78bc4a1

Browse files
Merge pull request #201 from Wimmics/development
Merge development changes to doc_development
2 parents c9072e7 + bca607c commit 78bc4a1

File tree

142 files changed

+7948
-3303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+7948
-3303
lines changed

.github/workflows/sphinx.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
contents: write
1010
steps:
1111

12-
- name: Checkout doc_development branch
12+
- name: Checkout development branch
1313
uses: actions/checkout@v4
1414
with:
15-
ref: doc_development
15+
ref: development
1616

1717
- name: Build Sphinx Docs
1818
uses: ammaraskar/sphinx-action@master
@@ -29,7 +29,7 @@ jobs:
2929

3030
- name: Deploy
3131
uses: peaceiris/actions-gh-pages@v3
32-
if: github.ref == 'refs/heads/doc_development'
32+
if: github.ref == 'refs/heads/development'
3333
with:
3434
github_token: ${{ secrets.GITHUB_TOKEN }}
3535
publish_dir: docs/build/html

corese-command/pom.xml

+27-10
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,46 @@
1616

1717
<dependencies>
1818

19-
<dependency>
20-
<groupId>junit</groupId>
21-
<artifactId>junit</artifactId>
22-
<version>4.13.2</version>
23-
<scope>test</scope>
24-
</dependency>
25-
19+
<!-- CLI Interface -->
2620
<dependency>
2721
<groupId>info.picocli</groupId>
2822
<artifactId>picocli</artifactId>
29-
<version>4.7.4</version>
23+
<version>4.7.6</version>
3024
</dependency>
3125

26+
<!-- Corese -->
3227
<dependency>
3328
<groupId>${project.parent.groupId}</groupId>
3429
<artifactId>corese-core</artifactId>
3530
</dependency>
3631

32+
<!-- Unit Test -->
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter-api</artifactId>
36+
<version>5.11.0-M1</version>
37+
<scope>test</scope>
38+
</dependency>
3739
<dependency>
38-
<groupId>jakarta.activation</groupId>
39-
<artifactId>jakarta.activation-api</artifactId>
40+
<groupId>org.junit.jupiter</groupId>
41+
<artifactId>junit-jupiter-engine</artifactId>
42+
<version>5.11.0-M1</version>
43+
<scope>test</scope>
4044
</dependency>
4145

46+
<!-- Mock HTTPS Server for Test -->
47+
<dependency>
48+
<groupId>org.wiremock</groupId>
49+
<artifactId>wiremock</artifactId>
50+
<version>3.8.0</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.assertj</groupId>
55+
<artifactId>assertj-core</artifactId>
56+
<version>3.26.3</version>
57+
<scope>test</scope>
58+
</dependency>
4259

4360
</dependencies>
4461

corese-command/src/main/java/fr/inria/corese/command/App.java

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
package fr.inria.corese.command;
22

3-
import fr.inria.corese.command.programs.canonicalize;
3+
import fr.inria.corese.command.programs.Canonicalize;
44
import fr.inria.corese.command.programs.Convert;
55
import fr.inria.corese.command.programs.RemoteSparql;
66
import fr.inria.corese.command.programs.Shacl;
77
import fr.inria.corese.command.programs.Sparql;
8+
import picocli.AutoComplete.GenerateCompletion;
89
import picocli.CommandLine;
910
import picocli.CommandLine.Command;
11+
import picocli.CommandLine.Help.Ansi.Style;
12+
import picocli.CommandLine.Help.ColorScheme;
1013

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

1518
public final class App implements Runnable {
1619

1720
public final static String version = "4.5.1";
1821

1922
public static void main(String[] args) {
20-
int exitCode = new CommandLine(new App()).execute(args);
23+
// Define the color scheme
24+
ColorScheme colorScheme = new ColorScheme.Builder()
25+
.commands(Style.bold) // Commands in blue
26+
.options(Style.fg_yellow) // Options in yellow
27+
.parameters(Style.fg_cyan, Style.bold) // Parameters in cyan and bold
28+
.optionParams(Style.italic, Style.fg_cyan) // Option parameters in italic
29+
.errors(Style.fg_red, Style.bold) // Errors in red and bold
30+
.stackTraces(Style.italic) // Stack traces in italic
31+
.applySystemProperties() // Apply system properties for colors
32+
.build();
33+
34+
CommandLine commandLine = new CommandLine(new App()).setColorScheme(colorScheme);
35+
36+
// Hide the generate-completion command
37+
CommandLine gen = commandLine.getSubcommands().get("generate-completion");
38+
gen.getCommandSpec().usageMessage().hidden(true);
39+
40+
// Execute the command
41+
int exitCode = commandLine.execute(args);
2142
System.exit(exitCode);
2243
}
2344

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package fr.inria.corese.command.programs;
2+
3+
import java.nio.file.Path;
4+
import java.util.Optional;
5+
import java.util.concurrent.Callable;
6+
7+
import fr.inria.corese.command.App;
8+
import fr.inria.corese.command.utils.ConfigManager;
9+
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
10+
import fr.inria.corese.core.util.Property;
11+
import fr.inria.corese.core.util.Property.Value;
12+
import picocli.CommandLine.Command;
13+
import picocli.CommandLine.Model.CommandSpec;
14+
import picocli.CommandLine.Option;
15+
import picocli.CommandLine.Spec;
16+
17+
/**
18+
* Abstract class for all commands.
19+
*
20+
* This class provides common options and methods for all commands.
21+
*/
22+
@Command(version = App.version)
23+
public abstract class AbstractCommand implements Callable<Integer> {
24+
25+
///////////////
26+
// Constants //
27+
///////////////
28+
29+
// Exit codes
30+
protected final int ERROR_EXIT_CODE_SUCCESS = 0;
31+
protected final int ERROR_EXIT_CODE_ERROR = 1;
32+
33+
/////////////
34+
// Options //
35+
/////////////
36+
37+
@Option(names = { "-o",
38+
"--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)
39+
protected Path output;
40+
41+
@Option(names = { "-c", "--config",
42+
"--init" }, description = "Specifies the path to a configuration file. If not provided, the default configuration file will be used.", required = false)
43+
private Path configFilePath;
44+
45+
@Option(names = { "-v",
46+
"--verbose" }, description = "Enables verbose mode, printing more information about the execution of the command.", negatable = true)
47+
protected boolean verbose = false;
48+
49+
@Option(names = { "-w",
50+
"--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)
51+
private boolean noOwlImport;
52+
53+
////////////////
54+
// Properties //
55+
////////////////
56+
57+
// Command specification
58+
@Spec
59+
protected CommandSpec spec;
60+
61+
// Output
62+
protected Boolean outputToFileIsDefault = false;
63+
64+
/////////////
65+
// Methods //
66+
/////////////
67+
68+
@Override
69+
public Integer call() {
70+
71+
// Load configuration file
72+
Optional<Path> configFilePath = Optional.ofNullable(this.configFilePath);
73+
if (configFilePath.isPresent()) {
74+
ConfigManager.loadFromFile(configFilePath.get(), this.spec, this.verbose);
75+
} else {
76+
ConfigManager.loadDefaultConfig(this.spec, this.verbose);
77+
}
78+
79+
// Set owl import
80+
Property.set(Value.DISABLE_OWL_AUTO_IMPORT, this.noOwlImport);
81+
82+
return 0;
83+
}
84+
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package fr.inria.corese.command.programs;
2+
3+
import java.nio.file.Path;
4+
5+
import picocli.CommandLine.Option;
6+
7+
public abstract class AbstractInputCommand extends AbstractCommand {
8+
9+
@Option(names = { "-i",
10+
"--input-data" }, description = "Specifies the path or URL of the input RDF data. Multiple values are allowed.", arity = "1...")
11+
protected String[] inputsRdfData;
12+
13+
@Option(names = { "-R",
14+
"--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")
15+
protected boolean recursive = false;
16+
17+
@Override
18+
public Integer call() {
19+
super.call();
20+
21+
// Check input values
22+
this.checkInputValues();
23+
24+
return 0;
25+
}
26+
27+
/**
28+
* Check if the input values are correct.
29+
*
30+
* @throws IllegalArgumentException if input path is same as output path.
31+
*/
32+
private void checkInputValues() throws IllegalArgumentException {
33+
if (this.inputsRdfData != null && this.output != null) {
34+
for (String input : this.inputsRdfData) {
35+
if (Path.of(input).compareTo(this.output) == 0) {
36+
throw new IllegalArgumentException("Input path cannot be same as output path: " + input);
37+
}
38+
}
39+
}
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package fr.inria.corese.command.programs;
2+
3+
import fr.inria.corese.command.utils.exporter.rdf.EnumCanonicAlgo;
4+
import fr.inria.corese.command.utils.exporter.rdf.RdfDataCanonicalizer;
5+
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
6+
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
7+
import fr.inria.corese.core.Graph;
8+
import picocli.CommandLine.Command;
9+
import picocli.CommandLine.Option;
10+
11+
@Command(name = "canonicalize", description = "Canonicalize an RDF file to a specific format.", mixinStandardHelpOptions = true)
12+
public class Canonicalize extends AbstractInputCommand {
13+
14+
@Option(names = { "-f", "-if",
15+
"--input-format" }, description = "Specifies the RDF serialization format of the input file. Available options are: :@|fg(225) ${COMPLETION-CANDIDATES}|@.")
16+
private EnumRdfInputFormat inputFormat;
17+
18+
@Option(names = { "-a", "-ca", "-r", "-of",
19+
"--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")
20+
private EnumCanonicAlgo canonicalAlgo;
21+
22+
public Canonicalize() {
23+
}
24+
25+
@Override
26+
public Integer call() {
27+
28+
super.call();
29+
30+
try {
31+
// Load the input file(s)
32+
RdfDataLoader loader = new RdfDataLoader(this.spec, this.verbose);
33+
Graph graph = loader.load(this.inputsRdfData, this.inputFormat, this.recursive);
34+
35+
// Canonicalize and export the graph
36+
RdfDataCanonicalizer rdfCanonicalizer = new RdfDataCanonicalizer(this.spec, this.verbose, this.output);
37+
rdfCanonicalizer.export(graph, this.canonicalAlgo);
38+
39+
return this.ERROR_EXIT_CODE_SUCCESS;
40+
} catch (IllegalArgumentException e) {
41+
this.spec.commandLine().getErr().println("Error: " + e.getMessage());
42+
return this.ERROR_EXIT_CODE_ERROR;
43+
}
44+
}
45+
46+
}

0 commit comments

Comments
 (0)