2424 */
2525package semanticstore .ontology .library .generator .olga ;
2626
27- import java .io .File ;
28- import java .io .IOException ;
29- import java .nio .file .Files ;
30- import java .nio .file .Path ;
31- import java .nio .file .Paths ;
3227import java .util .HashMap ;
3328import java .util .Map ;
3429import java .util .Optional ;
35- import java .util .stream .Stream ;
3630import org .apache .commons .cli .CommandLine ;
3731import org .apache .commons .cli .DefaultParser ;
3832import org .apache .commons .cli .HelpFormatter ;
3933import org .apache .commons .cli .Option ;
4034import org .apache .commons .cli .Options ;
4135import org .apache .commons .cli .ParseException ;
4236import org .apache .log4j .Logger ;
43- import org .semanticweb .owlapi .apibinding .OWLManager ;
44- import org .semanticweb .owlapi .model .IRI ;
45- import org .semanticweb .owlapi .model .OWLOntology ;
46- import org .semanticweb .owlapi .model .OWLOntologyCreationException ;
47- import org .semanticweb .owlapi .model .OWLOntologyManager ;
48- import org .semanticweb .owlapi .util .AutoIRIMapper ;
49- import org .semanticweb .owlapi .util .OWLOntologyMerger ;
5037import semanticstore .ontology .library .generator .global .CODE ;
5138import semanticstore .ontology .library .generator .global .LIBRARY ;
52- import semanticstore .ontology .library .generator .global . UTILS ;
39+ import semanticstore .ontology .library .generator .resources . ResourceManager ;
5340
5441public class CliHelper {
5542
56- static Map <String , Object > inputCmdParameters = new HashMap <>();
43+ static Map <String , Object > inputCmdParameters = new HashMap <String , Object >();
5744 static DefaultParser defaultParser ;
5845 final static Logger log = Logger .getLogger (CliHelper .class );
5946 static boolean atLeastOneValidOntologyFile = false ;
@@ -62,22 +49,26 @@ public static Map<String, Object> parseCLI(String[] args) {
6249 // create Options object
6350 Options options = new Options ();
6451 Option outPath = Option .builder ().argName ("out" ).hasArg ().longOpt ("out" )
65- .desc ("a path to output directory" ).build ();
66- Option code = Option .builder ().argName ("code" ).hasArg ().required (). desc ( "java, cs, or py" )
67- .longOpt ("code" ).build ();
52+ .desc (ResourceManager . getResource ( "outPathDesc" ) ).build ();
53+ Option code = Option .builder ().argName ("code" ).hasArg ().required ()
54+ .desc ( ResourceManager . getResource ( "codeDesc" )). longOpt ("code" ).build ();
6855 Option library = Option .builder ().argName ("library" ).hasArg ().required ().longOpt ("library" )
69- .desc ("[trinity]" ).build ();
56+ .desc (ResourceManager . getResource ( "libraryDesc" ) ).build ();
7057 Option name = Option .builder ().argName ("name" ).hasArg ().required ().longOpt ("name" )
71- .desc ("Generated Library Name" ).build ();
58+ .desc (ResourceManager . getResource ( "nameDesc" ) ).build ();
7259 Option pathToOntologies = Option .builder ().argName ("path" ).hasArg ().required ().longOpt ("path" )
73- .desc ("a path to a repository of one or more ontologies" ).build ();
60+ .desc (ResourceManager . getResource ( "pathToOntologiesDesc" ) ).build ();
7461 Option version = Option .builder ().argName ("version" ).hasArg ().longOpt ("version" )
75- .desc (
76- "a new version forced in entry, used when merging two or more ontologies having different versions" )
77- .build ();
62+ .desc (ResourceManager .getResource ("versionDesc" )).build ();
63+ Option skipInverseRelations = Option .builder ().argName ("skipInverseRelations" ).hasArg (false )
64+ .longOpt ("skipInverseRelations" )
65+ .desc (ResourceManager .getResource ("skipInverseRelationsDesc" )).build ();
66+ Option skipCompilation = Option .builder ().argName ("skipCompile" ).hasArg (false )
67+ .longOpt ("skipCompile" ).desc (ResourceManager .getResource ("skipCompileDesc" )).build ();
7868
7969 // add code option
8070 options .addOption (code );
71+ options .addOption (skipInverseRelations );
8172 options .addOption (outPath );
8273 options .addOption (library );
8374 options .addOption (name );
@@ -88,6 +79,7 @@ public static Map<String, Object> parseCLI(String[] args) {
8879 options .addOption ("partial" , false ,
8980 "a parameter if set to true will generate C# code where all classes are partial" );
9081 options .addOption ("skipCleaning" , false , "Skip Directory Cleaning Phase" );
82+ options .addOption (skipCompilation );
9183
9284 defaultParser = new DefaultParser ();
9385 HelpFormatter formatter = new HelpFormatter ();
@@ -125,89 +117,23 @@ public static Map<String, Object> parseCLI(String[] args) {
125117 if (line .hasOption ("help" )) {
126118 formatter .printHelp ("help" , options );
127119 }
120+ if (line .hasOption ("skipInverseRelations" )) {
121+ inputCmdParameters .put ("skipInverseRelations" , true );
122+ } else {
123+ inputCmdParameters .put ("skipInverseRelations" , false );
124+ }
125+ inputCmdParameters .put ("skipCompile" , line .hasOption ("skipCompile" ));
128126 } catch (ParseException exp ) {
129127 System .out .println ("Missing argument:" + exp .getMessage ());
130128 formatter .printHelp ("help" , options );
131129 inputCmdParameters .clear ();
132130 return null ;
133- }
134- return inputCmdParameters ;
135- }
136-
137-
138- public static OWLOntology prepareOntology (String pathToOntologiesParam ) {
139- OWLOntologyManager owlManager ;
140- File directory ;
141-
142- owlManager = OWLManager .createOWLOntologyManager ();
143- directory = new File (pathToOntologiesParam );
144- AutoIRIMapper mapper = new AutoIRIMapper (directory , true );
145- owlManager .getIRIMappers ().add (mapper );
146-
147- try (Stream <Path > paths = Files .walk (Paths .get (pathToOntologiesParam ))) {
148- paths .forEach (filePath -> {
149- if (Files .isRegularFile (filePath )) {
150- File test_ontFile = new File (filePath .toString ());
151- if (UTILS .hasOntologyFormatExtension (test_ontFile .getName ())) {
152- try {
153- OWLOntology currentOntology =
154- owlManager .loadOntologyFromOntologyDocument (test_ontFile );
155-
156- atLeastOneValidOntologyFile = true ;
157- // If the user didn't specify a new version for the merge, just use one of the
158- // versions
159- String ontologyVersion ;
160- if (!(inputCmdParameters .containsKey ("ontVersion" )
161- && UTILS .isVersionPatternValid ((String ) inputCmdParameters .get ("ontVersion" )))) {
162- Optional <IRI > versionOpt = currentOntology .getOntologyID ().getVersionIRI ();
163- if (versionOpt .isPresent ()
164- && UTILS .isVersionPatternValid (versionOpt .get ().getShortForm ())) {
165- ontologyVersion = versionOpt .get ().getShortForm ();
166- } else {
167- ontologyVersion = UTILS .getOlgaVersion ();
168- }
169- inputCmdParameters .put ("ontVersion" , ontologyVersion );
170- } else {
171- ontologyVersion = (String ) inputCmdParameters .get ("ontVersion" );
172- }
173- } catch (OWLOntologyCreationException e ) {
174- log .error (e );
175- log .error (e .getStackTrace ().toString ());
176-
177- System .out .println (e .getMessage ());
178- return ;
179- } catch (Exception e ) {
180- log .error (e );
181- log .error (e .getStackTrace ().toString ());
182- System .out .println (e .getMessage ());
183- return ;
184- }
185- }
186- }
187- });
188- } catch (IOException e ) {
189- log .error (e );
190- log .error (e .getStackTrace ());
191- }
192-
193- if (!atLeastOneValidOntologyFile ) {
194- System .err .println ("No valid Ontology File found" );
195- return null ;
196- }
197- // Merging ontologies if any
198- OWLOntologyMerger merger = new OWLOntologyMerger (owlManager );
199- OWLOntologyManager owlManager2 = OWLManager .createOWLOntologyManager ();
200- IRI mergedOntologyIRI = IRI .create ("mergedOntology" );
201-
202- OWLOntology merged ;
203- try {
204- merged = merger .createMergedOntology (owlManager2 , mergedOntologyIRI );
205- } catch (OWLOntologyCreationException e ) {
206- log .error (e );
131+ } catch (IllegalArgumentException e ) {
207132 System .out .println (e .getMessage ());
133+ formatter .printHelp ("help" , options );
134+ inputCmdParameters .clear ();
208135 return null ;
209136 }
210- return merged ;
137+ return inputCmdParameters ;
211138 }
212-
213139}
0 commit comments