Skip to content

Commit 951a223

Browse files
committed
commit of OLGA as a Service with support of RDF4J, Python code generation and OLGA modules WebService and CLI
1 parent 75e45f4 commit 951a223

File tree

163 files changed

+20971
-10946
lines changed

Some content is hidden

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

163 files changed

+20971
-10946
lines changed

OLGA/OLGA-Cli/pom.xml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
<modelVersion>4.0.0</modelVersion>
7+
<packaging>jar</packaging>
8+
<parent>
9+
<groupId>semanticstore.ontology.library.generator</groupId>
10+
<artifactId>OLGA</artifactId>
11+
<version>0.0.4</version>
12+
</parent>
13+
<artifactId>OLGA-Cli</artifactId>
14+
<name>OLGA-Cli</name>
15+
<url>http://maven.apache.org</url>
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<log.version>1.5.6</log.version>
19+
<log4j.version>1.2.17</log4j.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>semanticstore.ontology.library.generator</groupId>
25+
<artifactId>OLGA-Core</artifactId>
26+
<version>0.0.4</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>log4j</groupId>
30+
<artifactId>log4j</artifactId>
31+
<version>${log4j.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.slf4j</groupId>
35+
<artifactId>slf4j-simple</artifactId>
36+
<version>${log.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.slf4j</groupId>
40+
<artifactId>slf4j-api</artifactId>
41+
<version>${log.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.slf4j</groupId>
45+
<artifactId>slf4j-nop</artifactId>
46+
<version>${log.version}</version>
47+
</dependency>
48+
</dependencies>
49+
<build>
50+
<sourceDirectory>src</sourceDirectory>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.7.0</version>
56+
<configuration>
57+
<source>1.8</source>
58+
<target>1.8</target>
59+
<manifest>
60+
<mainClass>semanticstore.ontology.library.generator.olga.OLGA</mainClass>
61+
</manifest>
62+
</configuration>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-assembly-plugin</artifactId>
67+
<version>3.1.0</version>
68+
<configuration>
69+
<descriptors>
70+
<descriptor>src/assembly/assembly.xml</descriptor>
71+
</descriptors>
72+
<archive>
73+
<manifest>
74+
<mainClass>semanticstore.ontology.library.generator.olga.OLGA</mainClass>
75+
</manifest>
76+
</archive>
77+
<useTransitiveFiltering>true</useTransitiveFiltering>
78+
</configuration>
79+
<executions>
80+
<execution>
81+
<id>create-archive</id>
82+
<phase>package</phase>
83+
<goals>
84+
<goal>single</goal>
85+
</goals>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
<!-- <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId>
90+
<version>0.8.1</version> <configuration> <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
91+
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
92+
</configuration> <executions> <execution> <id>jacoco-initialize</id> <goals>
93+
<goal>prepare-agent</goal> </goals> </execution> <execution> <id>jacoco-site</id>
94+
<phase>package</phase> <goals> <goal>report</goal> </goals> </execution>
95+
</executions> </plugin> -->
96+
<plugin>
97+
<artifactId>maven-site-plugin</artifactId>
98+
<version>3.7.1</version>
99+
<executions>
100+
<execution>
101+
<id>attach-descriptor</id>
102+
<goals>
103+
<goal>attach-descriptor</goal>
104+
</goals>
105+
</execution>
106+
</executions>
107+
</plugin>
108+
<plugin>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-surefire-plugin</artifactId>
111+
<version>2.20.1</version>
112+
<configuration>
113+
<forkMode>once</forkMode>
114+
</configuration>
115+
</plugin>
116+
</plugins>
117+
</build>
118+
119+
</project>

src/main/java/semanticstore/ontology/library/generator/olga/CliHelper.java renamed to OLGA/OLGA-Cli/src/main/java/semanticstore/ontology/library/generator/olga/CliHelper.java

Lines changed: 26 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,23 @@
2424
*/
2525
package 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;
3227
import java.util.HashMap;
3328
import java.util.Map;
3429
import java.util.Optional;
35-
import java.util.stream.Stream;
3630
import org.apache.commons.cli.CommandLine;
3731
import org.apache.commons.cli.DefaultParser;
3832
import org.apache.commons.cli.HelpFormatter;
3933
import org.apache.commons.cli.Option;
4034
import org.apache.commons.cli.Options;
4135
import org.apache.commons.cli.ParseException;
4236
import 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;
5037
import semanticstore.ontology.library.generator.global.CODE;
5138
import semanticstore.ontology.library.generator.global.LIBRARY;
52-
import semanticstore.ontology.library.generator.global.UTILS;
39+
import semanticstore.ontology.library.generator.resources.ResourceManager;
5340

5441
public 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

Comments
 (0)