Skip to content

Commit

Permalink
commit of OLGA as a Service with support of RDF4J, Python code genera…
Browse files Browse the repository at this point in the history
…tion and OLGA modules WebService and CLI
  • Loading branch information
charbull committed Oct 9, 2018
1 parent 75e45f4 commit 951a223
Show file tree
Hide file tree
Showing 163 changed files with 20,971 additions and 10,946 deletions.
119 changes: 119 additions & 0 deletions OLGA/OLGA-Cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>semanticstore.ontology.library.generator</groupId>
<artifactId>OLGA</artifactId>
<version>0.0.4</version>
</parent>
<artifactId>OLGA-Cli</artifactId>
<name>OLGA-Cli</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<log.version>1.5.6</log.version>
<log4j.version>1.2.17</log4j.version>
</properties>

<dependencies>
<dependency>
<groupId>semanticstore.ontology.library.generator</groupId>
<artifactId>OLGA-Core</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${log.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${log.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${log.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<manifest>
<mainClass>semanticstore.ontology.library.generator.olga.OLGA</mainClass>
</manifest>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>semanticstore.ontology.library.generator.olga.OLGA</mainClass>
</manifest>
</archive>
<useTransitiveFiltering>true</useTransitiveFiltering>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version> <configuration> <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration> <executions> <execution> <id>jacoco-initialize</id> <goals>
<goal>prepare-agent</goal> </goals> </execution> <execution> <id>jacoco-site</id>
<phase>package</phase> <goals> <goal>report</goal> </goals> </execution>
</executions> </plugin> -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
<executions>
<execution>
<id>attach-descriptor</id>
<goals>
<goal>attach-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
</build>

</project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,23 @@
*/
package semanticstore.ontology.library.generator.olga;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.Logger;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.OWLOntologyMerger;
import semanticstore.ontology.library.generator.global.CODE;
import semanticstore.ontology.library.generator.global.LIBRARY;
import semanticstore.ontology.library.generator.global.UTILS;
import semanticstore.ontology.library.generator.resources.ResourceManager;

public class CliHelper {

static Map<String, Object> inputCmdParameters = new HashMap<>();
static Map<String, Object> inputCmdParameters = new HashMap<String, Object>();
static DefaultParser defaultParser;
final static Logger log = Logger.getLogger(CliHelper.class);
static boolean atLeastOneValidOntologyFile = false;
Expand All @@ -62,22 +49,26 @@ public static Map<String, Object> parseCLI(String[] args) {
// create Options object
Options options = new Options();
Option outPath = Option.builder().argName("out").hasArg().longOpt("out")
.desc("a path to output directory").build();
Option code = Option.builder().argName("code").hasArg().required().desc("java, cs, or py")
.longOpt("code").build();
.desc(ResourceManager.getResource("outPathDesc")).build();
Option code = Option.builder().argName("code").hasArg().required()
.desc(ResourceManager.getResource("codeDesc")).longOpt("code").build();
Option library = Option.builder().argName("library").hasArg().required().longOpt("library")
.desc("[trinity]").build();
.desc(ResourceManager.getResource("libraryDesc")).build();
Option name = Option.builder().argName("name").hasArg().required().longOpt("name")
.desc("Generated Library Name").build();
.desc(ResourceManager.getResource("nameDesc")).build();
Option pathToOntologies = Option.builder().argName("path").hasArg().required().longOpt("path")
.desc("a path to a repository of one or more ontologies").build();
.desc(ResourceManager.getResource("pathToOntologiesDesc")).build();
Option version = Option.builder().argName("version").hasArg().longOpt("version")
.desc(
"a new version forced in entry, used when merging two or more ontologies having different versions")
.build();
.desc(ResourceManager.getResource("versionDesc")).build();
Option skipInverseRelations = Option.builder().argName("skipInverseRelations").hasArg(false)
.longOpt("skipInverseRelations")
.desc(ResourceManager.getResource("skipInverseRelationsDesc")).build();
Option skipCompilation = Option.builder().argName("skipCompile").hasArg(false)
.longOpt("skipCompile").desc(ResourceManager.getResource("skipCompileDesc")).build();

// add code option
options.addOption(code);
options.addOption(skipInverseRelations);
options.addOption(outPath);
options.addOption(library);
options.addOption(name);
Expand All @@ -88,6 +79,7 @@ public static Map<String, Object> parseCLI(String[] args) {
options.addOption("partial", false,
"a parameter if set to true will generate C# code where all classes are partial");
options.addOption("skipCleaning", false, "Skip Directory Cleaning Phase");
options.addOption(skipCompilation);

defaultParser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
Expand Down Expand Up @@ -125,89 +117,23 @@ public static Map<String, Object> parseCLI(String[] args) {
if (line.hasOption("help")) {
formatter.printHelp("help", options);
}
if (line.hasOption("skipInverseRelations")) {
inputCmdParameters.put("skipInverseRelations", true);
} else {
inputCmdParameters.put("skipInverseRelations", false);
}
inputCmdParameters.put("skipCompile", line.hasOption("skipCompile"));
} catch (ParseException exp) {
System.out.println("Missing argument:" + exp.getMessage());
formatter.printHelp("help", options);
inputCmdParameters.clear();
return null;
}
return inputCmdParameters;
}


public static OWLOntology prepareOntology(String pathToOntologiesParam) {
OWLOntologyManager owlManager;
File directory;

owlManager = OWLManager.createOWLOntologyManager();
directory = new File(pathToOntologiesParam);
AutoIRIMapper mapper = new AutoIRIMapper(directory, true);
owlManager.getIRIMappers().add(mapper);

try (Stream<Path> paths = Files.walk(Paths.get(pathToOntologiesParam))) {
paths.forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
File test_ontFile = new File(filePath.toString());
if (UTILS.hasOntologyFormatExtension(test_ontFile.getName())) {
try {
OWLOntology currentOntology =
owlManager.loadOntologyFromOntologyDocument(test_ontFile);

atLeastOneValidOntologyFile = true;
// If the user didn't specify a new version for the merge, just use one of the
// versions
String ontologyVersion;
if (!(inputCmdParameters.containsKey("ontVersion")
&& UTILS.isVersionPatternValid((String) inputCmdParameters.get("ontVersion")))) {
Optional<IRI> versionOpt = currentOntology.getOntologyID().getVersionIRI();
if (versionOpt.isPresent()
&& UTILS.isVersionPatternValid(versionOpt.get().getShortForm())) {
ontologyVersion = versionOpt.get().getShortForm();
} else {
ontologyVersion = UTILS.getOlgaVersion();
}
inputCmdParameters.put("ontVersion", ontologyVersion);
} else {
ontologyVersion = (String) inputCmdParameters.get("ontVersion");
}
} catch (OWLOntologyCreationException e) {
log.error(e);
log.error(e.getStackTrace().toString());

System.out.println(e.getMessage());
return;
} catch (Exception e) {
log.error(e);
log.error(e.getStackTrace().toString());
System.out.println(e.getMessage());
return;
}
}
}
});
} catch (IOException e) {
log.error(e);
log.error(e.getStackTrace());
}

if (!atLeastOneValidOntologyFile) {
System.err.println("No valid Ontology File found");
return null;
}
// Merging ontologies if any
OWLOntologyMerger merger = new OWLOntologyMerger(owlManager);
OWLOntologyManager owlManager2 = OWLManager.createOWLOntologyManager();
IRI mergedOntologyIRI = IRI.create("mergedOntology");

OWLOntology merged;
try {
merged = merger.createMergedOntology(owlManager2, mergedOntologyIRI);
} catch (OWLOntologyCreationException e) {
log.error(e);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
formatter.printHelp("help", options);
inputCmdParameters.clear();
return null;
}
return merged;
return inputCmdParameters;
}

}
Loading

0 comments on commit 951a223

Please sign in to comment.