Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
histream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raphael
histream
Commits
6fa8694f
Commit
6fa8694f
authored
Sep 10, 2016
by
R.W.Majeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maven plugin for RDF ontology to SQL translation
parent
3cdc7271
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
2187 additions
and
0 deletions
+2187
-0
histream-maven-plugin/.gitignore
histream-maven-plugin/.gitignore
+4
-0
histream-maven-plugin/pom.xml
histream-maven-plugin/pom.xml
+73
-0
histream-maven-plugin/src/main/java/de/sekmi/histream/maven/OntologyMojo.java
...n/src/main/java/de/sekmi/histream/maven/OntologyMojo.java
+121
-0
histream-maven-plugin/src/test/java/de/sekmi/histream/maven/TestOntologyMojo.java
...c/test/java/de/sekmi/histream/maven/TestOntologyMojo.java
+33
-0
histream-maven-plugin/src/test/resources/ontology.properties
histream-maven-plugin/src/test/resources/ontology.properties
+13
-0
histream-maven-plugin/src/test/resources/skos-aktin-cda.ttl
histream-maven-plugin/src/test/resources/skos-aktin-cda.ttl
+1943
-0
No files found.
histream-maven-plugin/.gitignore
0 → 100644
View file @
6fa8694f
.settings/
.classpath
.project
target/
histream-maven-plugin/pom.xml
0 → 100644
View file @
6fa8694f
<project>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
de.sekmi.histream.maven
</groupId>
<artifactId>
histream-maven-plugin
</artifactId>
<version>
0.9-SNAPSHOT
</version>
<packaging>
maven-plugin
</packaging>
<name>
HIStream maven plugin
</name>
<build>
<plugins>
<!-- use new plugin plugin. default 3.2 will not work with java 8 -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugin-plugin
</artifactId>
<version>
3.4
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.5.1
</version>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- functional dependencies -->
<dependency>
<groupId>
de.sekmi.histream
</groupId>
<artifactId>
histream-i2b2
</artifactId>
<version>
0.9-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
de.sekmi.histream
</groupId>
<artifactId>
histream-skos
</artifactId>
<version>
0.9-SNAPSHOT
</version>
</dependency>
<!-- maven plugin dependencies -->
<dependency>
<groupId>
org.apache.maven
</groupId>
<artifactId>
maven-plugin-api
</artifactId>
<version>
3.3.9
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.shared/file-management -->
<dependency>
<groupId>
org.apache.maven.shared
</groupId>
<artifactId>
file-management
</artifactId>
<version>
3.0.0
</version>
</dependency>
<!-- dependencies to annotations -->
<dependency>
<groupId>
org.apache.maven.plugin-tools
</groupId>
<artifactId>
maven-plugin-annotations
</artifactId>
<version>
3.4
</version>
<scope>
provided
</scope>
</dependency>
<!-- testing -->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
histream-maven-plugin/src/main/java/de/sekmi/histream/maven/OntologyMojo.java
0 → 100644
View file @
6fa8694f
package
de.sekmi.histream.maven
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Properties
;
import
org.apache.maven.plugin.AbstractMojo
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.plugins.annotations.Mojo
;
import
org.apache.maven.plugins.annotations.Parameter
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.shared.model.fileset.FileSet
;
import
org.apache.maven.shared.model.fileset.util.FileSetManager
;
import
org.openrdf.repository.RepositoryException
;
import
de.sekmi.histream.i2b2.ont.SQLGenerator
;
import
de.sekmi.histream.ontology.OntologyException
;
import
de.sekmi.histream.ontology.skos.Store
;
@Mojo
(
name
=
"ontology"
)
public
class
OntologyMojo
extends
AbstractMojo
{
@Parameter
(
required
=
true
)
FileSet
source
;
/**
* Destination for the generated resources.
* Defaults to {@code ${project.build.directory}/generated-resources/sql/}
*/
@Parameter
(
required
=
false
,
defaultValue
=
"${project.build.directory}/generated-resources/sql"
)
File
destination
;
/**
* Overwrite existing files in the destination
*/
@Parameter
boolean
overwrite
;
@Parameter
Properties
properties
;
@Parameter
(
defaultValue
=
"${project}"
,
readonly
=
true
,
required
=
true
)
MavenProject
project
;
private
void
logWarning
(
String
message
){
getLog
().
warn
(
message
);
}
private
List
<
File
>
getSourceFiles
(){
// read source files
Objects
.
requireNonNull
(
source
);
FileSetManager
fsm
=
new
FileSetManager
();
String
[]
files
=
fsm
.
getIncludedFiles
(
source
);
String
base
=
source
.
getDirectory
();
List
<
File
>
list
=
new
ArrayList
<>(
files
.
length
);
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++
){
list
.
add
(
new
File
(
base
,
files
[
i
]));
}
return
list
;
}
private
Map
<
String
,
String
>
loadConfiguration
(){
Map
<
String
,
String
>
map
=
new
HashMap
<>();
if
(
properties
!=
null
){
for
(
String
name
:
properties
.
stringPropertyNames
()
){
map
.
put
(
name
,
properties
.
getProperty
(
name
));
}
}
if
(
!
map
.
containsKey
(
"meta.sourcesystem_cd"
)
){
// use artifact id
this
.
getLog
().
warn
(
"Using project artifact id for missing property meta.sourcesystem_cd"
);
map
.
put
(
"meta.sourcesystem_cd"
,
project
.
getArtifactId
());
}
// language
if
(
!
map
.
containsKey
(
"ont.language"
)
){
this
.
getLog
().
warn
(
"Using system default language for missing property ont.language: "
+
Locale
.
getDefault
().
getLanguage
());
map
.
put
(
"ont.language"
,
Locale
.
getDefault
().
getLanguage
());
}
// TODO use defaults for missing properties meta.table, etc
return
map
;
}
@Override
public
void
execute
()
throws
MojoExecutionException
,
MojoFailureException
{
// copy properties to string map
Map
<
String
,
String
>
map
=
loadConfiguration
();
// create destination directories if not existing
try
{
Files
.
createDirectories
(
destination
.
toPath
());
}
catch
(
IOException
e
)
{
throw
new
MojoExecutionException
(
"Unable to create destination directory: "
+
destination
,
e
);
}
Path
metaSQL
=
new
File
(
destination
,
"meta.sql"
).
toPath
();
Path
dataSQL
=
new
File
(
destination
,
"data.sql"
).
toPath
();
// load ontology
Store
store
;
try
{
store
=
new
Store
(
getSourceFiles
(),
null
);
}
catch
(
RepositoryException
|
IOException
e
)
{
throw
new
MojoExecutionException
(
"Unable to load ontology"
,
e
);
}
try
{
SQLGenerator
gen
=
new
SQLGenerator
(
metaSQL
,
dataSQL
,
map
,
overwrite
);
gen
.
setWarningHandler
(
this
::
logWarning
);
gen
.
writeOntologySQL
(
store
);
gen
.
close
();
store
.
close
();
}
catch
(
IOException
|
SQLException
|
OntologyException
e
)
{
throw
new
MojoExecutionException
(
"Ontology to SQL transformation failed"
,
e
);
}
}
}
histream-maven-plugin/src/test/java/de/sekmi/histream/maven/TestOntologyMojo.java
0 → 100644
View file @
6fa8694f
package
de.sekmi.histream.maven
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.Collections
;
import
java.util.Properties
;
import
org.apache.maven.shared.model.fileset.FileSet
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
TestOntologyMojo
{
@Test
public
void
expectSuccessfulExecution
()
throws
Exception
{
URL
ttl
=
getClass
().
getResource
(
"/skos-aktin-cda.ttl"
);
File
source
=
new
File
(
ttl
.
toURI
());
Assert
.
assertTrue
(
source
.
isFile
());
OntologyMojo
mojo
=
new
OntologyMojo
();
mojo
.
source
=
new
FileSet
();
mojo
.
source
.
setDirectory
(
source
.
getParent
());
mojo
.
source
.
addInclude
(
source
.
getName
());
mojo
.
destination
=
new
File
(
"target/"
);
mojo
.
properties
=
new
Properties
();
mojo
.
overwrite
=
true
;
try
(
InputStream
in
=
getClass
().
getResourceAsStream
(
"/ontology.properties"
)
){
mojo
.
properties
.
load
(
in
);
}
mojo
.
execute
();
}
}
histream-maven-plugin/src/test/resources/ontology.properties
0 → 100644
View file @
6fa8694f
# metadata table
meta.table
=
i2b2metadata.i2b2
# metadata table access
meta.access
=
i2b2metadata.table_access
meta.basepath
=
\\
i2b2
\\
# Before each import, data for this sourcesystem_cd will be deleted
meta.sourcesystem_cd
=
test
data.concept.table
=
i2b2demodata.concept_dimension
# language to use for accessing ontology
ont.language
=
DE
histream-maven-plugin/src/test/resources/skos-aktin-cda.ttl
0 → 100644
View file @
6fa8694f
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment