-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from Wimmics/development
Merge development changes to doc_development
- Loading branch information
Showing
142 changed files
with
7,948 additions
and
3,303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 24 additions & 3 deletions
27
corese-command/src/main/java/fr/inria/corese/command/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
corese-command/src/main/java/fr/inria/corese/command/programs/AbstractCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
corese-command/src/main/java/fr/inria/corese/command/programs/AbstractInputCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
corese-command/src/main/java/fr/inria/corese/command/programs/Canonicalize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.