diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f72c36e..2b68b44a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +## [4.2.0] - 2018-11-14 + ### Added - output format: hdt @@ -106,6 +108,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - support for accessing remote files (via HTTP GET) - basic support for functions +[4.2.0]: https://github.com/RMLio/rmlmapper-java/compare/v4.1.0...v4.2.0 [4.1.0]: https://github.com/RMLio/rmlmapper-java/compare/v4.0.0...v4.1.0 [4.0.0]: https://github.com/RMLio/rmlmapper-java/compare/v0.2.1...v4.0.0 [0.2.1]: https://github.com/RMLio/rmlmapper-java/compare/v0.2.0...v0.2.1 diff --git a/README.md b/README.md index 51b66fc8..6086d539 100644 --- a/README.md +++ b/README.md @@ -79,21 +79,27 @@ import be.ugent.rml.records.RecordsFactory; import be.ugent.rml.store.RDF4JStore; import be.ugent.rml.store.QuadStore; -public class Main { +import java.io.FileInputStream; +import java.io.InputStream; + + +class Main { public static void main(String[] args) { - boolean removeDuplicates = false; //set to true if you want to remove duplicates triples/quads from the output String cwd = "/home/rml"; //path to default directory for local files String mappingFile = "/home/rml/mapping.rml.ttl"; //path to the mapping file that needs to be executed - List triplesMaps = new ArrayList<>(); //list of triplesmaps to execute. When this list is empty all triplesmaps in the mapping file are executed - InputStream mappingStream = new FileInputStream(mappingFile); - Model model = Rio.parse(mappingStream, "", RDFFormat.TURTLE); - RDF4JStore rmlStore = new RDF4JStore(model); - - Executor executor = new Executor(rmlStore, new RecordsFactory(new DataFetcher(cwd, rmlStore))); - QuadStore result = executor.execute(triplesMaps, removeDuplicates); + try { + InputStream mappingStream = new FileInputStream(mappingFile); + Model model = Rio.parse(mappingStream, "", RDFFormat.TURTLE); + RDF4JStore rmlStore = new RDF4JStore(model); + + Executor executor = new Executor(rmlStore, new RecordsFactory(new DataFetcher(cwd, rmlStore))); + QuadStore result = executor.execute(null); + } catch (Exception e) { + System.out.println(e.getMessage()); + } } } ``` @@ -137,24 +143,51 @@ You can change the functions.ttl path using a commandline-option (`-f`). This overrides the dynamic loading. See the snippet below for an example of how to do it. -``` +```java +package be.ugent.rml; + +import be.ugent.rml.functions.FunctionLoader; import be.ugent.rml.functions.lib.GrelProcessor; +import be.ugent.rml.records.RecordsFactory; +import be.ugent.rml.store.QuadStore; +import com.google.common.io.Resources; -String mapPath = "path/to/mapping/file"; -String outPath = "path/to/where/the/output/triples/should/be/written"; - -Map libraryMap = new HashMap<>(); -libraryMap.put("GrelFunctions.jar", GrelProcessor.class); -FunctionLoader functionLoader = new FunctionLoader(libraryMap); -try { - Executor executor = this.createExecutor(mapPath, functionLoader); - doMapping(executor, outPath); -} catch (IOException e) { - logger.error(e.getMessage(), e); +import java.io.File; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + + +class Main { + + public static void main(String[] args) { + String mapPath = "path/to/mapping/file"; + String functionPath = "path/to/functions.ttl/file"; + + URL url = Resources.getResource(functionPath); + + Map libraryMap = new HashMap<>(); + libraryMap.put("GrelFunctions.jar", GrelProcessor.class); + try { + File functionsFile = new File(url.toURI()); + FunctionLoader functionLoader = new FunctionLoader(functionsFile, null, libraryMap); + ClassLoader classLoader = Main.class.getClassLoader(); + // execute mapping file + File mappingFile = new File(classLoader.getResource(mapPath).getFile()); + QuadStore rmlStore = Utils.readTurtle(mappingFile); + + Executor executor = new Executor(rmlStore, new RecordsFactory(new DataFetcher(mappingFile.getParent(), rmlStore)), + functionLoader); + QuadStore result = executor.execute(null); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } } ``` ### Testing + #### RDBs Make sure you have [Docker](https://www.docker.com) running. @@ -181,6 +214,7 @@ Make sure you have [Docker](https://www.docker.com) running. | com.opencsv opencsv | Apache License 2.0 | | commons-lang | Apache License 2.0 | | ch.qos.logback | Eclipse Public License 1.0 & GNU Lesser General Public License 2.1 | +| org.rdfhdt.hdt-jena | GNU Lesser General Public License v3.0 | # UML Diagrams ## How to generate with IntelliJ IDEA @@ -189,4 +223,4 @@ Make sure you have [Docker](https://www.docker.com) running. * Right click on package: "be.ugent.rml" * Diagrams > Show Diagram > Java Class Diagrams * Choose what properties of the classes you want to show in the upper left corner -* Export to file > .png | Save diagram > .uml \ No newline at end of file +* Export to file > .png | Save diagram > .uml diff --git a/pom.xml b/pom.xml index c9d6487d..11db504f 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 be.ugent.rml rmlmapper - 4.1.0 + 4.2.0 UTF-8 4.12