Skip to content

Commit

Permalink
1. properties file can now be passed as a command-line argument
Browse files Browse the repository at this point in the history
2. Updated license from 3.0 to 4.0
  • Loading branch information
nkons committed Oct 16, 2014
1 parent 29f6e07 commit 4a3472a
Show file tree
Hide file tree
Showing 30 changed files with 162 additions and 131 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ R2RML implementation written fully in Java 7, using Apache Jena 2.11, Spring 4.0

## Licence

This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 Unported License.

http://creativecommons.org/licenses/by-nc/3.0/
http://creativecommons.org/licenses/by-nc/4.0/

You are free to use and distribute this work as long as you provide proper reference and respect the license terms.

## Publications

1. N. Konstantinou, D. Kouis, N. Mitrou: ["Incremental Export of Relational Database Contents into RDF Graphs"](https://www.researchgate.net/publication/262098563_Incremental_Export_of_Relational_Database_Contents_into_RDF_Graphs). In 4th International Conference on Web Intelligence, Mining and Semantics (WIMS'14), Thessaloniki, Greece, June 2014 [(doi:10.1145/2611040.2611082)](http://dx.doi.org/10.1145/2611040.2611082) [(slides)](http://www.slideshare.net/nkons/wims14-v2)

1. N. Konstantinou, D.E. Spanos, N. Houssos, N. Mitrou: ["Exposing Scholarly Information as Linked Open Data: RDFizing DSpace contents"](https://www.researchgate.net/publication/236881378_Exposing_Scholarly_Information_as_Linked_Open_Data_RDFizing_DSpace_contents). In The Electronic Library, Vol. 32, No. 6, 2014 (to appear)
1. N. Konstantinou, D.E. Spanos, N. Houssos, N. Mitrou: ["Exposing Scholarly Information as Linked Open Data: RDFizing DSpace contents"](https://www.researchgate.net/publication/236881378_Exposing_Scholarly_Information_as_Linked_Open_Data_RDFizing_DSpace_contents). In The Electronic Library, Vol. 32, No. 6, 2014

1. N. Konstantinou, D.E. Spanos, N. Mitrou: ["Transient and persistent RDF views over relational databases in the context of digital repositories"](https://www.researchgate.net/publication/258235039_Transient_and_persistent_RDF_views_over_relational_databases_in_the_context_of_digital_repositories). In 7th Metadata and Semantics Research Conference (MTSR'13), Thessaloniki, Greece, Springer, CCIS 390, pp. 342-354, November 2013 [(doi:10.1007/978-3-319-03437-9_33)](http://dx.doi.org/10.1007/978-3-319-03437-9_33) [(slides)](http://www.slideshare.net/nkons/transient-and-persistent-rdf-views-over-relational-databases-in-the-context-of-digital-repositories)

Expand Down
19 changes: 12 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gr.seab</groupId>
<artifactId>r2rml-parser</artifactId>
<version>0.6</version>
<version>0.7</version>
<packaging>jar</packaging>
<name>R2RML Parser</name>
<properties>
Expand Down Expand Up @@ -114,11 +114,16 @@
<type>pom</type>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
</dependencies>

<!-- Added for oracle JDBC driver -->
Expand All @@ -145,7 +150,7 @@
<developer>
<name>Nikolaos Konstantinou</name>
<email>nkons at cn.ntua.gr</email>
<url>https://www.researchgate.net/profile/Nikolaos_Konstantinou/</url>
<url>http://people.cn.ntua.gr/nkons/</url>
<organization>Hellenic Academic Libraries Link/National Technical University of Athens (HEAL-Link/NTUA)</organization>
<organizationUrl>http://www.seab.gr</organizationUrl>
<roles>
Expand Down
6 changes: 3 additions & 3 deletions r2rml-parser.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
echo This is R2RML Parser 0.6-alpha
java -Xms128m -Xmx1024m -cp "./*;./lib/*;" gr.seab.r2rml.beans.Main %1
echo R2RML Parser 0.6-alpha. Done.
echo This is R2RML Parser 0.7-alpha. Run with -h for help on options.
java -Xms128m -Xmx1024m -cp "./*;./lib/*;" gr.seab.r2rml.beans.Main %1 %2
echo R2RML Parser 0.7-alpha. Done.
6 changes: 3 additions & 3 deletions r2rml-parser.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
echo "This is R2RML Parser 0.6-alpha"
java -Xms128m -Xmx1024m -cp "./*;./lib/*;" -jar lib/r2rml-parser-0.6.jar -o true
echo "R2RML Parser 0.6-alpha. Done."
echo "This is R2RML Parser 0.7-alpha. Run with -h for help on options."
java -Xms128m -Xmx1024m -cp "./*;./lib/*;" -jar lib/r2rml-parser-0.7.jar $1 $2
echo "R2RML Parser 0.7-alpha. Done."
7 changes: 5 additions & 2 deletions src/main/java/gr/seab/r2rml/beans/Database.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported
* Licensed under the Creative Commons Attribution-NonCommercial 4.0 Unported
* License (the "License"). You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
*
* http://creativecommons.org/licenses/by-nc/3.0/
* http://creativecommons.org/licenses/by-nc/4.0/
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
Expand All @@ -13,6 +13,7 @@

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Properties;

public interface Database {

Expand All @@ -22,4 +23,6 @@ public interface Database {

public void testQuery(String query);

public void setProperties(Properties properties);

}
37 changes: 7 additions & 30 deletions src/main/java/gr/seab/r2rml/beans/DatabaseImpl.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* Licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported
* Licensed under the Creative Commons Attribution-NonCommercial 4.0 Unported
* License (the "License"). You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
*
* http://creativecommons.org/licenses/by-nc/3.0/
* http://creativecommons.org/licenses/by-nc/4.0/
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
package gr.seab.r2rml.beans;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
Expand All @@ -35,28 +34,14 @@ public class DatabaseImpl implements Database {

private Connection connection;

private Properties properties = new Properties();

private String propertiesFilename;
private Properties properties;

private Util util;

public DatabaseImpl() {

}

/**
*
*/
public DatabaseImpl(String propertiesFilename) {
try {
properties.load(new FileInputStream(propertiesFilename));
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

public Connection openConnection() {
log.info("Establishing source (relational) connection.");
if (connection == null) {
Expand All @@ -73,7 +58,7 @@ public Connection openConnection() {
log.info("Established source (relational) connection.");
return connection;
} catch (Exception e) {
e.printStackTrace();
log.error("Error establishing source (relational) connection! Please check your connection settings.");
System.exit(1);
}
} else {
Expand All @@ -92,7 +77,7 @@ public ResultSet query(String query) {
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
result = statement.executeQuery(query);
} catch (SQLException e) {
e.printStackTrace();
log.error("Error executing query! Query was: " + query);
System.exit(1);
}
return result;
Expand All @@ -114,19 +99,11 @@ public void testQuery(String query) {

preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
log.error("Error testing query! Query was: " + query);
System.exit(1);
}
}

public String getPropertiesFilename() {
return propertiesFilename;
}

public void setPropertiesFilename(String propertiesFilename) {
this.propertiesFilename = propertiesFilename;
}


public Util getUtil() {
return util;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gr/seab/r2rml/beans/Generator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported
* Licensed under the Creative Commons Attribution-NonCommercial 4.0 Unported
* License (the "License"). You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
*
* http://creativecommons.org/licenses/by-nc/3.0/
* http://creativecommons.org/licenses/by-nc/4.0/
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
Expand Down
80 changes: 65 additions & 15 deletions src/main/java/gr/seab/r2rml/beans/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported
* Licensed under the Creative Commons Attribution-NonCommercial 4.0 Unported
* License (the "License"). You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
*
* http://creativecommons.org/licenses/by-nc/3.0/
* http://creativecommons.org/licenses/by-nc/4.0/
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
Expand All @@ -13,41 +13,91 @@

import gr.seab.r2rml.entities.MappingDocument;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;
import java.util.Properties;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);

/**
* The properties, as read from the properties file.
*/
private static Properties properties = new Properties();

public static void main(String[] args) {
Calendar c0 = Calendar.getInstance();
long t0 = c0.getTimeInMillis();
String appContextFile = "app-context.xml";
if (args.length > 0) {
File f = new File(args[0]);
if (f.exists()) {
log.info("Spring context descriptor set to " + args[0]);
appContextFile = args[0];
} else {
log.info("File " + args[0] + " not in classpath, using app-context.xml instead");

CommandLineParser cmdParser = new PosixParser();

Options cmdOptions = new Options();
cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties");
cmdOptions.addOption("h", "print help", false, "help");

String propertiesFile = "r2rml.properties";

try {
CommandLine line = cmdParser.parse(cmdOptions, args);

if (line.hasOption("h")) {
HelpFormatter help = new HelpFormatter();
help.printHelp("r2rml-parser\n", cmdOptions);
System.exit(0);
}
} else {
log.info("Spring context file not provided, using app-context.xml");

if (line.hasOption("p")) {
propertiesFile = line.getOptionValue("p");
}
} catch (ParseException e1) {
//e1.printStackTrace();
log.error("Error parsing command line arguments.");
System.exit(1);
}
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(appContextFile);

try {
if (StringUtils.isNotEmpty(propertiesFile)) {
properties.load(new FileInputStream(propertiesFile));
log.info("Loaded properties from " + propertiesFile);
}
} catch (FileNotFoundException e) {
//e.printStackTrace();
log.error("Properties file not found (" + propertiesFile + ").");
System.exit(1);
} catch (IOException e) {
//e.printStackTrace();
log.error("Error reading properties file (" + propertiesFile + ").");
System.exit(1);
}

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml");

Database db = (Database) context.getBean("db");
db.setProperties(properties);

Parser parser = (Parser) context.getBean("parser");
parser.setProperties(properties);

MappingDocument mappingDocument = parser.parse();

mappingDocument.getTimestamps().add(t0); //0 Started
mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model.

Generator generator = (Generator) context.getBean("generator");
generator.setProperties(parser.getProperties());
generator.setProperties(properties);
generator.setResultModel(parser.getResultModel());

//Actually do the output
Expand Down
24 changes: 3 additions & 21 deletions src/main/java/gr/seab/r2rml/beans/Parser.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported
* Licensed under the Creative Commons Attribution-NonCommercial 4.0 Unported
* License (the "License"). You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
*
* http://creativecommons.org/licenses/by-nc/3.0/
* http://creativecommons.org/licenses/by-nc/4.0/
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
Expand All @@ -24,9 +24,6 @@
import gr.seab.r2rml.entities.sparql.LocalResultSet;
import gr.seab.r2rml.entities.sql.SelectQuery;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -96,7 +93,7 @@ public class Parser {
/**
* The properties, as read from the properties file.
*/
private Properties properties = new Properties();
private Properties properties;

private boolean verbose;

Expand All @@ -105,21 +102,6 @@ public class Parser {
private Util util;

public Parser() {

}

public Parser(String propertiesFilename) {
this.propertiesFilename = propertiesFilename;
try {
if (StringUtils.isNotEmpty(propertiesFilename)) {
properties.load(new FileInputStream(propertiesFilename));
log.info("Loaded properties from " + propertiesFilename);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

@SuppressWarnings("unchecked")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gr/seab/r2rml/beans/Util.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported
* Licensed under the Creative Commons Attribution-NonCommercial 4.0 Unported
* License (the "License"). You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
*
* http://creativecommons.org/licenses/by-nc/3.0/
* http://creativecommons.org/licenses/by-nc/4.0/
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
Expand Down
Loading

0 comments on commit 4a3472a

Please sign in to comment.