Christophe Debruyne 8 years ago
parent
commit
f12f02e5d0

+ 21 - 0
.classpath

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="test"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 23 - 0
.project

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>downlift</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 5 - 0
.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.8

+ 4 - 0
.settings/org.eclipse.m2e.core.prefs

@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1

+ 88 - 0
pom.xml

@@ -0,0 +1,88 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>downlift</groupId>
+  <artifactId>downlift</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  	<build>
+		<finalName>downlift</finalName>
+		<sourceDirectory>src</sourceDirectory>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.3</version>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<configuration>
+					<archive>
+						<manifest>
+							<addClasspath>true</addClasspath>
+							<classpathPrefix>dependency/</classpathPrefix>
+							<mainClass>r2rml.Downlift</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-shade-plugin</artifactId>
+				<version>2.4.3</version>
+				<executions>
+					<execution>
+						<phase>package</phase>
+						<goals>
+							<goal>shade</goal>
+						</goals>
+						<configuration>
+							<finalName>downlift-fat</finalName>
+							<transformers>
+								<transformer
+									implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+									<mainClass>r2rml.GenerateMapping</mainClass>
+								</transformer>
+							</transformers>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-arq</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-core</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-iri</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.11</version>
+		</dependency>
+		<dependency>
+			<groupId>com.h2database</groupId>
+			<artifactId>h2</artifactId>
+			<version>1.4.193</version>
+		</dependency>
+	</dependencies>
+
+	<organization>
+		<name>Adapt Centre, Trinity College Dublin</name>
+		<url>http://www.adaptcentre.ie/</url>
+	</organization>
+</project>

+ 8 - 0
src/log4j.properties

@@ -0,0 +1,8 @@
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

+ 212 - 0
src/r2rml/Downlift.java

@@ -0,0 +1,212 @@
+package r2rml;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.io.IOUtils;
+import org.apache.jena.query.QueryExecution;
+import org.apache.jena.query.QueryExecutionFactory;
+import org.apache.jena.query.QuerySolution;
+import org.apache.jena.query.ResultSet;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.log4j.Logger;
+
+public class Downlift {
+
+	private static Logger logger = Logger.getLogger(Downlift.class.getName());
+
+	private static File csvFile = null;
+	private static File mapFile = null;
+	private static List<File> rdfFiles = new ArrayList<File>();
+
+	private static String pred = null;
+
+	private static List<String> headers = new ArrayList<String>();
+	private static List<String> predicates = new ArrayList<String>();
+
+
+	public static void main(String[] args) {
+		try {
+			parseArguments(args);
+			prepareStructure();
+			prepareData();
+		} catch (Exception e) {
+			logger.error(e.getMessage());
+		}
+	}
+
+	private static void prepareStructure() throws IOException {
+		logger.info("Pre-processing structure of new CSV file.");
+
+		Model mapping = ModelFactory.createDefaultModel();
+		logger.info("Loading " + mapFile);
+		mapping.read(mapFile.getCanonicalPath());
+
+		// Add structure from mapping based on metadata
+		String s = IOUtils.toString(Downlift.class.getResourceAsStream("/structure-query.sparql"));
+		QueryExecution qex = QueryExecutionFactory.create(s, mapping);
+		ResultSet rs = qex.execSelect();
+
+		while(rs.hasNext()) {
+			QuerySolution qs = rs.next();
+			String label = qs.getLiteral("label").getString();
+			String predicate = qs.getResource("predicate").getURI();
+			headers.add(label);
+			predicates.add(predicate);
+		}
+
+		// Add predicate
+		headers.add(pred);
+		predicates.add(pred);
+	}
+
+	private static void prepareData() throws IOException, DownliftException {		
+		// load all the RDF files
+		logger.info("Loading RDF files...");
+		Model data = ModelFactory.createDefaultModel();
+		for(File file : rdfFiles) {
+			logger.info("Loading " + file);
+			data.read(file.getCanonicalPath());
+		}
+
+		// write the header
+		logger.info("Writing headers to CSV file...");
+		FileWriter fileWriter = new FileWriter(csvFile);
+		CSVFormat csvFileFormat = CSVFormat.RFC4180;
+		CSVPrinter csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);
+		csvFilePrinter.printRecord(headers.toArray());
+
+		// create and execute query to prepare data
+		logger.info("Writing records to CSV file...");
+		
+		String s = "", vars = "";
+		s += "PREFIX odef:<http://adaptcentre.ie/ont/odef#>";
+		s += "SELECT *** WHERE { ";
+		s += "?x a odef:Record .";
+		String p = null;
+		for(int i = 0; i < predicates.size(); i++) {
+			p = predicates.get(i);
+			s += "OPTIONAL { ?x <" + p + "> ?x" + i + ".}";
+			vars += " ?x" + i;
+		}
+		s += "} ORDER BY ?x";
+		s = s.replace("***", vars);
+		
+		System.out.println(s);
+
+		/*
+		 * Though Jena provides a method for writing the result set to a CSV
+		 * file, relying on the CSVFilePrinter allows us to extend the tool
+		 * with some options such as defining the delimiter and type of CSV
+		 * file (excel, MySQL, ...) .
+		 */
+		QueryExecution qe = QueryExecutionFactory.create(s, data);
+		ResultSet rs = qe.execSelect();
+		List<String> sol = null;
+		QuerySolution qs = null;
+		RDFNode node = null;
+		while(rs.hasNext()) {
+			qs = rs.next();
+			sol = new ArrayList<String>();
+			for(String var : rs.getResultVars()) {
+				node = qs.get(var);
+				if(node == null) sol.add(null);
+				else if(node.isLiteral()) sol.add(node.asLiteral().getValue().toString());
+				else sol.add(node.toString());
+			}
+			csvFilePrinter.printRecord(sol);
+		}
+
+		// close the output files
+		logger.info("Finishing up writing to CSV file...");
+		try {
+			fileWriter.flush();
+			fileWriter.close();
+			csvFilePrinter.close();
+		} catch (IOException e) {
+			throw new DownliftException("Error while flushing or closing FileWriter or CSVPrinter.", e);
+		}
+	}
+
+	private static void parseArguments(String[] args) throws DownliftException {
+		Options options = new Options();
+		options.addOption("p", true, "The URI of the predicate for the additional column.");
+		options.addOption("o", true, "The filename for the output CSV file (default = output.csv).");
+		options.addOption("m", true, "The filename for the R2RML mapping file.");
+		options.addOption("f", true, "List of RDF files.");
+		options.addOption("h", false, "Display help.");
+
+		try {
+			CommandLineParser parser = new DefaultParser();
+			CommandLine cmd = parser.parse(options, args);
+
+			// Display help
+			if(cmd.hasOption("h")) {
+				HelpFormatter formatter = new HelpFormatter();
+				formatter.printHelp("downlift.jar", options);
+				System.exit(0);
+			}
+
+			String out = null, map = null;
+
+			// Process the R2RML mapping file
+			if(cmd.hasOption("m")) {
+				map = cmd.getOptionValue("m");
+				logger.info("Using R2RML mapping file " + map);
+			} else {				
+				throw new DownliftException("Providing an R2RML mapping file is mandatory.");
+			}
+
+			mapFile = new File(map);
+			if(!mapFile.exists()) {
+				throw new DownliftException("R2RML mapping file does not exist.");
+			}
+
+			// Process output CSV file
+			out = cmd.getOptionValue("o", "output.csv");
+			logger.info("Using output CSV file " + out);
+			csvFile = new File(out);
+
+			// Process predicate for additional column
+			if(cmd.hasOption("p")) {
+				pred = cmd.getOptionValue("p");
+				logger.info("Searching for links with URI " + pred);
+			} else {				
+				throw new DownliftException("Providing URI to a predicate is mandatory.");
+			}
+
+			// Process RDF files
+			if(cmd.hasOption("f") && cmd.getOptionValues("f").length > 0) {
+				String[] files = cmd.getOptionValues("f");
+				for(String file : files) {
+					File f = new File(file);
+					if(!f.exists()) {
+						throw new DownliftException(f + " does not exist.");
+					}
+					logger.info("Using RDF file " + f);
+					rdfFiles.add(f);
+				}
+			} else {				
+				throw new DownliftException("Providing RDF files is mandatory.");
+			}
+
+		} catch(ParseException e) {
+			throw new DownliftException("Parsing failed.  Reason: " + e.getMessage(), e);
+		}
+
+	}
+
+}

+ 19 - 0
src/r2rml/DownliftException.java

@@ -0,0 +1,19 @@
+package r2rml;
+
+public class DownliftException extends Exception {
+
+	private static final long serialVersionUID = -195670607332859688L;
+
+	public DownliftException() {
+		super();
+	}
+
+	public DownliftException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+	public DownliftException(String message) {
+		super(message);
+	}
+	
+}

+ 61 - 0
src/r2rml/R2RML.java

@@ -0,0 +1,61 @@
+package r2rml;
+
+import org.apache.jena.rdf.model.Property;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.ResourceFactory;
+
+/**
+ * R2RML Class.
+ * 
+ * @author Christophe Debruyne
+ * @version 0.1
+ *
+ */
+public final class R2RML {
+	
+	public static final String NS = "http://www.w3.org/ns/r2rml#";
+	
+	public static final Resource BLANKNODE = ResourceFactory.createResource(NS + "BlankNode");
+	public static final Resource IRI = ResourceFactory.createResource(NS + "IRI");
+	public static final Resource LITERAL = ResourceFactory.createResource(NS + "Literal");
+	
+	// Special resource for default graph
+	public static final Resource defaultGraph = ResourceFactory.createResource(NS + "defaultGraph");
+
+	// Classes
+	public static final Resource BaseTableOrView = ResourceFactory.createResource(NS + "BaseTableOrView");
+	public static final Resource GraphMap = ResourceFactory.createResource(NS + "GraphMap");
+	public static final Resource LogicalTable = ResourceFactory.createResource(NS + "LogicalTable");
+	public static final Resource ObjectMap = ResourceFactory.createResource(NS + "ObjectMap");
+	public static final Resource R2RMLView = ResourceFactory.createResource(NS + "R2RMLView");
+	public static final Resource RefObjectMap = ResourceFactory.createResource(NS + "RefObjectMap");
+	public static final Resource SubjectMap = ResourceFactory.createResource(NS + "SubjectMap");
+	public static final Resource TermMap = ResourceFactory.createResource(NS + "TermMap");
+	public static final Resource TriplesMap = ResourceFactory.createResource(NS + "TriplesMap");
+	
+	// Properties
+	public static final Property child = ResourceFactory.createProperty(NS + "child");
+	public static final Property clazz = ResourceFactory.createProperty(NS + "class");
+	public static final Property column = ResourceFactory.createProperty(NS + "column");
+	public static final Property constant = ResourceFactory.createProperty(NS + "constant");
+	public static final Property datatype = ResourceFactory.createProperty(NS + "datatype");
+	public static final Property graph = ResourceFactory.createProperty(NS + "graph");
+	public static final Property graphMap = ResourceFactory.createProperty(NS + "graphMap");
+	public static final Property joinCondition = ResourceFactory.createProperty(NS + "joinCondition");
+	public static final Property language = ResourceFactory.createProperty(NS + "language");
+	public static final Property logicalTable = ResourceFactory.createProperty(NS + "logicalTable");
+	public static final Property object = ResourceFactory.createProperty(NS + "object");
+	public static final Property objectMap = ResourceFactory.createProperty(NS + "objectMap");
+	public static final Property parent = ResourceFactory.createProperty(NS + "parent");
+	public static final Property parentTriplesMap = ResourceFactory.createProperty(NS + "parentTriplesMap");
+	public static final Property predicate = ResourceFactory.createProperty(NS + "predicate");
+	public static final Property predicateMap = ResourceFactory.createProperty(NS + "predicateMap");
+	public static final Property predicateObjectMap = ResourceFactory.createProperty(NS + "predicateObjectMap");
+	public static final Property sqlQuery = ResourceFactory.createProperty(NS + "sqlQuery");
+	public static final Property subject = ResourceFactory.createProperty(NS + "subject");
+	public static final Property subjectMap = ResourceFactory.createProperty(NS + "subjectMap");
+	public static final Property tableName = ResourceFactory.createProperty(NS + "tableName");
+	public static final Property template = ResourceFactory.createProperty(NS + "template");
+	public static final Property termType = ResourceFactory.createProperty(NS + "termType");
+	
+}

+ 7 - 0
src/structure-query.sparql

@@ -0,0 +1,7 @@
+PREFIX rr: <http://www.w3.org/ns/r2rml#>
+PREFIX odef:<http://adaptcentre.ie/ont/odef#>
+SELECT ?predicate ?label WHERE {
+	?pom odef:label ?label .
+	?pom odef:order ?order .
+	?pom rr:predicate ?predicate .
+} ORDER BY ?order

+ 20 - 0
target/classes/META-INF/MANIFEST.MF

@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Built-By: chrdebru
+Class-Path: dependency/jena-arq-3.0.1.jar dependency/jena-shaded-guava
+ -3.0.1.jar dependency/httpclient-4.2.6.jar dependency/httpcore-4.2.5.
+ jar dependency/commons-codec-1.6.jar dependency/jsonld-java-0.7.0.jar
+  dependency/jackson-core-2.3.3.jar dependency/jackson-databind-2.3.3.
+ jar dependency/jackson-annotations-2.3.0.jar dependency/commons-io-2.
+ 4.jar dependency/httpclient-cache-4.2.6.jar dependency/libthrift-0.9.
+ 2.jar dependency/jcl-over-slf4j-1.7.12.jar dependency/commons-csv-1.0
+ .jar dependency/commons-lang3-3.3.2.jar dependency/slf4j-api-1.7.12.j
+ ar dependency/slf4j-log4j12-1.7.12.jar dependency/log4j-1.2.17.jar de
+ pendency/jena-core-3.0.1.jar dependency/xercesImpl-2.11.0.jar depende
+ ncy/xml-apis-1.4.01.jar dependency/commons-cli-1.3.jar dependency/jen
+ a-base-3.0.1.jar dependency/dexx-collections-0.2.jar dependency/jena-
+ iri-3.0.1.jar dependency/junit-4.11.jar dependency/hamcrest-core-1.3.
+ jar dependency/h2-1.4.193.jar
+Build-Jdk: 1.8.0_51
+Created-By: Maven Integration for Eclipse
+Main-Class: r2rml.Downlift
+

+ 7 - 0
target/classes/META-INF/maven/downlift/downlift/pom.properties

@@ -0,0 +1,7 @@
+#Generated by Maven Integration for Eclipse
+#Mon Feb 13 12:39:07 CET 2017
+version=0.0.1-SNAPSHOT
+groupId=downlift
+m2e.projectName=downlift
+m2e.projectLocation=/Users/chrdebru/GITHUB/adapt-downlift
+artifactId=downlift

+ 88 - 0
target/classes/META-INF/maven/downlift/downlift/pom.xml

@@ -0,0 +1,88 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>downlift</groupId>
+  <artifactId>downlift</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  	<build>
+		<finalName>downlift</finalName>
+		<sourceDirectory>src</sourceDirectory>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.3</version>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<configuration>
+					<archive>
+						<manifest>
+							<addClasspath>true</addClasspath>
+							<classpathPrefix>dependency/</classpathPrefix>
+							<mainClass>r2rml.Downlift</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-shade-plugin</artifactId>
+				<version>2.4.3</version>
+				<executions>
+					<execution>
+						<phase>package</phase>
+						<goals>
+							<goal>shade</goal>
+						</goals>
+						<configuration>
+							<finalName>downlift-fat</finalName>
+							<transformers>
+								<transformer
+									implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+									<mainClass>r2rml.GenerateMapping</mainClass>
+								</transformer>
+							</transformers>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-arq</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-core</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-iri</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.11</version>
+		</dependency>
+		<dependency>
+			<groupId>com.h2database</groupId>
+			<artifactId>h2</artifactId>
+			<version>1.4.193</version>
+		</dependency>
+	</dependencies>
+
+	<organization>
+		<name>Adapt Centre, Trinity College Dublin</name>
+		<url>http://www.adaptcentre.ie/</url>
+	</organization>
+</project>

+ 8 - 0
target/classes/log4j.properties

@@ -0,0 +1,8 @@
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

+ 11 - 0
target/classes/resources/construct-links.ttl

@@ -0,0 +1,11 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
+@prefix owl: <http://www.w3.org/2002/07/owl#>.
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
+@prefix geo: <http://www.opengis.net/ont/geosparql#>.
+@prefix geof: <http://www.opengis.net/def/function/geosparql/>.
+@prefix osi: <http://ontologies.geohive.ie/osi#>.
+
+<http://www.example.org/record/3> geo:within <http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001>.
+<http://www.example.org/record/1> geo:within <http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001>.
+<http://www.example.org/record/2> geo:within <http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001>.

+ 50 - 0
target/classes/resources/fccweatherstationsp201108292221.csv.ttl

@@ -0,0 +1,50 @@
+<http://www.example.org/record/2>
+        a       <http://adaptcentre.ie/ont/odef#Record> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#AGENCY>
+                "National Roads Authority" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LAT>
+                "53.4096411069945" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LONG>
+                "-6.22759742761812" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#NAME>
+                "M50 Dublin Airport" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#ROW_NUM>
+                "2"^^<http://www.w3.org/2001/XMLSchema#int> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#WEATHER_READING>
+                "http://www.nratraffic.ie/weather/default.asp?weatherstation=IR57&selected=true&showonly=true" ;
+        <http://www.opengis.net/ont/geosparql#asWKT>
+                "POINT(-6.22759742761812 53.4096411069945)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
+
+<http://www.example.org/record/1>
+        a       <http://adaptcentre.ie/ont/odef#Record> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#AGENCY>
+                "National Roads Authority" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LAT>
+                "53.3704660326011" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LONG>
+                "-6.38085144711153" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#NAME>
+                "M50 Blanchardstown" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#ROW_NUM>
+                "1"^^<http://www.w3.org/2001/XMLSchema#int> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#WEATHER_READING>
+                "http://www.nratraffic.ie/weather/default.asp?weatherstation=IR26&selected=true&showonly=true" ;
+        <http://www.opengis.net/ont/geosparql#asWKT>
+                "POINT(-6.38085144711153 53.3704660326011)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
+
+<http://www.example.org/record/3>
+        a       <http://adaptcentre.ie/ont/odef#Record> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#AGENCY>
+                "Met �ireann" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LAT>
+                "53.4215060785623" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LONG>
+                "-6.29784754004026" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#NAME>
+                "Dublin Airport" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#ROW_NUM>
+                "3"^^<http://www.w3.org/2001/XMLSchema#int> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#WEATHER_READING>
+                "http://www.met.ie/latest/reports.asp" ;
+        <http://www.opengis.net/ont/geosparql#asWKT>
+                "POINT(-6.29784754004026 53.4215060785623)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .

+ 36 - 0
target/classes/resources/mapping.ttl

@@ -0,0 +1,36 @@
+@prefix rr:    <http://www.w3.org/ns/r2rml#> .
+@prefix odef:  <http://adaptcentre.ie/ont/odef#> .
+@prefix csv:   </Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#> .
+
+<#TriplesMap>  rr:logicalTable  [ rr:sqlQuery  "SELECT rownum() AS ROW_NUM, * FROM fccweatherstationsp201108292221;" ] ;
+        rr:predicateObjectMap  [ odef:label    "LONG" ;
+                                 odef:order    "5"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "LONG" ] ;
+                                 rr:predicate  csv:LONG
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "LAT" ;
+                                 odef:order    "4"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "LAT" ] ;
+                                 rr:predicate  csv:LAT
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "Agency" ;
+                                 odef:order    "3"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "AGENCY" ] ;
+                                 rr:predicate  csv:AGENCY
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "Weather_Reading" ;
+                                 odef:order    "2"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "WEATHER_READING" ] ;
+                                 rr:predicate  csv:WEATHER_READING
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "Name" ;
+                                 odef:order    "1"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "NAME" ] ;
+                                 rr:predicate  csv:NAME
+                               ] ;
+        rr:predicateObjectMap  [ rr:objectMap  [ rr:column  "ROW_NUM" ] ;
+                                 rr:predicate  csv:ROW_NUM
+                               ] ;
+        rr:subjectMap          [ rr:class     odef:Record ;
+                                 rr:template  "http://www.example.org/record/{ROW_NUM}"
+                               ] .

+ 4 - 0
target/classes/resources/output.csv

@@ -0,0 +1,4 @@
+Name,Weather_Reading,Agency,LAT,LONG,http://www.opengis.net/ont/geosparql#within
+M50 Blanchardstown,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR26&selected=true&showonly=true,National Roads Authority,53.3704660326011,-6.38085144711153,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+M50 Dublin Airport,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR57&selected=true&showonly=true,National Roads Authority,53.4096411069945,-6.22759742761812,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+Dublin Airport,http://www.met.ie/latest/reports.asp,Met �ireann,53.4215060785623,-6.29784754004026,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001

+ 4 - 0
target/classes/resources/output2.csv

@@ -0,0 +1,4 @@
+Name,Weather_Reading,Agency,LAT,LONG,http://www.opengis.net/ont/geosparql#within
+M50 Blanchardstown,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR26&selected=true&showonly=true,National Roads Authority,53.3704660326011,-6.38085144711153,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+M50 Dublin Airport,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR57&selected=true&showonly=true,National Roads Authority,53.4096411069945,-6.22759742761812,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+Dublin Airport,http://www.met.ie/latest/reports.asp,Met �ireann,53.4215060785623,-6.29784754004026,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001

+ 7 - 0
target/classes/structure-query.sparql

@@ -0,0 +1,7 @@
+PREFIX rr: <http://www.w3.org/ns/r2rml#>
+PREFIX odef:<http://adaptcentre.ie/ont/odef#>
+SELECT ?predicate ?label WHERE {
+	?pom odef:label ?label .
+	?pom odef:order ?order .
+	?pom rr:predicate ?predicate .
+} ORDER BY ?order

+ 11 - 0
test/resources/construct-links.ttl

@@ -0,0 +1,11 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
+@prefix owl: <http://www.w3.org/2002/07/owl#>.
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
+@prefix geo: <http://www.opengis.net/ont/geosparql#>.
+@prefix geof: <http://www.opengis.net/def/function/geosparql/>.
+@prefix osi: <http://ontologies.geohive.ie/osi#>.
+
+<http://www.example.org/record/3> geo:within <http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001>.
+<http://www.example.org/record/1> geo:within <http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001>.
+<http://www.example.org/record/2> geo:within <http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001>.

+ 50 - 0
test/resources/fccweatherstationsp201108292221.csv.ttl

@@ -0,0 +1,50 @@
+<http://www.example.org/record/2>
+        a       <http://adaptcentre.ie/ont/odef#Record> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#AGENCY>
+                "National Roads Authority" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LAT>
+                "53.4096411069945" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LONG>
+                "-6.22759742761812" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#NAME>
+                "M50 Dublin Airport" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#ROW_NUM>
+                "2"^^<http://www.w3.org/2001/XMLSchema#int> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#WEATHER_READING>
+                "http://www.nratraffic.ie/weather/default.asp?weatherstation=IR57&selected=true&showonly=true" ;
+        <http://www.opengis.net/ont/geosparql#asWKT>
+                "POINT(-6.22759742761812 53.4096411069945)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
+
+<http://www.example.org/record/1>
+        a       <http://adaptcentre.ie/ont/odef#Record> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#AGENCY>
+                "National Roads Authority" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LAT>
+                "53.3704660326011" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LONG>
+                "-6.38085144711153" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#NAME>
+                "M50 Blanchardstown" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#ROW_NUM>
+                "1"^^<http://www.w3.org/2001/XMLSchema#int> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#WEATHER_READING>
+                "http://www.nratraffic.ie/weather/default.asp?weatherstation=IR26&selected=true&showonly=true" ;
+        <http://www.opengis.net/ont/geosparql#asWKT>
+                "POINT(-6.38085144711153 53.3704660326011)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
+
+<http://www.example.org/record/3>
+        a       <http://adaptcentre.ie/ont/odef#Record> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#AGENCY>
+                "Met �ireann" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LAT>
+                "53.4215060785623" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#LONG>
+                "-6.29784754004026" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#NAME>
+                "Dublin Airport" ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#ROW_NUM>
+                "3"^^<http://www.w3.org/2001/XMLSchema#int> ;
+        <file:///Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#WEATHER_READING>
+                "http://www.met.ie/latest/reports.asp" ;
+        <http://www.opengis.net/ont/geosparql#asWKT>
+                "POINT(-6.29784754004026 53.4215060785623)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .

+ 36 - 0
test/resources/mapping.ttl

@@ -0,0 +1,36 @@
+@prefix rr:    <http://www.w3.org/ns/r2rml#> .
+@prefix odef:  <http://adaptcentre.ie/ont/odef#> .
+@prefix csv:   </Users/chrdebru/Desktop/workspace_local/generate-mapping/test/resources/fccweatherstationsp201108292221.csv#> .
+
+<#TriplesMap>  rr:logicalTable  [ rr:sqlQuery  "SELECT rownum() AS ROW_NUM, * FROM fccweatherstationsp201108292221;" ] ;
+        rr:predicateObjectMap  [ odef:label    "LONG" ;
+                                 odef:order    "5"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "LONG" ] ;
+                                 rr:predicate  csv:LONG
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "LAT" ;
+                                 odef:order    "4"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "LAT" ] ;
+                                 rr:predicate  csv:LAT
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "Agency" ;
+                                 odef:order    "3"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "AGENCY" ] ;
+                                 rr:predicate  csv:AGENCY
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "Weather_Reading" ;
+                                 odef:order    "2"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "WEATHER_READING" ] ;
+                                 rr:predicate  csv:WEATHER_READING
+                               ] ;
+        rr:predicateObjectMap  [ odef:label    "Name" ;
+                                 odef:order    "1"^^<http://www.w3.org/2001/XMLSchema#int> ;
+                                 rr:objectMap  [ rr:column  "NAME" ] ;
+                                 rr:predicate  csv:NAME
+                               ] ;
+        rr:predicateObjectMap  [ rr:objectMap  [ rr:column  "ROW_NUM" ] ;
+                                 rr:predicate  csv:ROW_NUM
+                               ] ;
+        rr:subjectMap          [ rr:class     odef:Record ;
+                                 rr:template  "http://www.example.org/record/{ROW_NUM}"
+                               ] .

+ 4 - 0
test/resources/output.csv

@@ -0,0 +1,4 @@
+Name,Weather_Reading,Agency,LAT,LONG,http://www.opengis.net/ont/geosparql#within
+M50 Blanchardstown,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR26&selected=true&showonly=true,National Roads Authority,53.3704660326011,-6.38085144711153,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+M50 Dublin Airport,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR57&selected=true&showonly=true,National Roads Authority,53.4096411069945,-6.22759742761812,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+Dublin Airport,http://www.met.ie/latest/reports.asp,Met �ireann,53.4215060785623,-6.29784754004026,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001

+ 4 - 0
test/resources/output2.csv

@@ -0,0 +1,4 @@
+Name,Weather_Reading,Agency,LAT,LONG,http://www.opengis.net/ont/geosparql#within
+M50 Blanchardstown,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR26&selected=true&showonly=true,National Roads Authority,53.3704660326011,-6.38085144711153,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+M50 Dublin Airport,http://www.nratraffic.ie/weather/default.asp?weatherstation=IR57&selected=true&showonly=true,National Roads Authority,53.4096411069945,-6.22759742761812,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001
+Dublin Airport,http://www.met.ie/latest/reports.asp,Met �ireann,53.4215060785623,-6.29784754004026,http://data.geohive.ie/resource/county/2AE19629144F13A3E055000000000001

+ 20 - 0
test/test/TestDownlift.java

@@ -0,0 +1,20 @@
+package test;
+
+import r2rml.Downlift;
+
+public class TestDownlift {
+
+	public static void main(String[] args) {
+		args = new String[] { 
+				"-p", "http://www.opengis.net/ont/geosparql#within",
+				"-m", "./test/resources/mapping.ttl",
+				"-o", "./test/resources/output.csv", 
+				"-f", "./test/resources/fccweatherstationsp201108292221.csv.ttl",  
+				"-f", "./test/resources/construct-links.ttl"
+				
+		};
+
+		Downlift.main(args);
+	}
+
+}