Skip to content

Commit

Permalink
Misc minor updates in examples and code description
Browse files Browse the repository at this point in the history
  • Loading branch information
frmichel committed Apr 2, 2015
1 parent 2192882 commit a140a33
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 50 deletions.
30 changes: 17 additions & 13 deletions README_code_architecture.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
Below we describe the architecture of classes regarding the treatment of RDBs. This can easily be adapted to the MongoDB case.

base.MorphProperties
Is a java.util.Properties.
Holds members for each property definable in the configuration file
(defaults to examples/morph.properties, set in MorphRDBRunner main)
(defaults to example_mysql/morph.properties, set in project morph-xr2rml-dist, MorphRunner main)

The base.engine.MorphBaseRunnerFactory class is an abstract class that builds an morph.base.engine.MorphBaseRunner.
Database-specific methods are implemented in concrete factory classes like r2rml.rdb.engine.MorphRDBRunnerFactory.

r2rml.rdb.engine.MorphRDBRunnerFactory < base.engine.MorphBaseRunnerFactory
Build an r2rml.rdb.engine.MorphRDBRunner object to initialize:
Provides methods to initialize:
- a mapping document (R2RMLMappingDocument): read the xR2RML mapping file into a JENA model, then create an R2RMLMappingDocument
that consists of a set of classMappings, namely triples maps (R2RMLTriplesMap).
- a DB connection
- a data source reader (MorphBaseDataSourceReader) of which concrete class name (MorphRDBDataSourceReader)
is passed as contruct parameter. The data source reader provides methods to set the connection and run
queries against the DB.
- a mapping document (R2RMLMappingDocument): read the R2RML mapping into a JENA model, then create an R2RMLMappingDocument
that consists of a set of classMappings, namely triples maps (R2RMLTriplesMap).
is passed as contruct parameter. The data source reader provides methods to open, configure, and close the connection,
run queries against the DB, and possibly manage strategies to store results to avoid executing the same query several times in the case of joint queries.
- an unfolder (MorphRDBUnfolder < MorphBaseUnfolder) to create SQL queries using a table name or query
- a data materializer (MorphBaseMaterializer) basically consists of a proper JENA model (either in mem or db)
initialized with a name space etc. The model is used to create statements from subject, predicate, objects read
from the database.
- a data translator (MorphRDBDataTranslator < MorphBaseDataTranslator) that actually makes the translation: it runs
SQL queries created by the unfolder, then generates RDF triples from the results.
- a data materializer (MorphBaseMaterializer) basically consists of a properly initialized (name space, etc.)
JENA model, either in mem or db. The model is used to store statements created from subjects, predicates and objects read
from the database.
- a query translator, query result writer and query result processor

r2rml.rdb.engine.MorphRDBRunner < base.engine.MorphBaseRunner
Main:
fr.unice.i3s.morph.xr2rml.engine.MorphRunner provide the main class to run the process:
- Load the properties
- Create a singleton MorphRDBRunner using the MorphRDBRunnerFactory that creates
a R2RMLMappingDocument, MorphRDBUnfoldern MorphRDBDataMaterializer and MorphRDBDataTranslator (see above).
- Create a singleton MorphBaseRunner using the MorphRDBRunnerFactory that creates
a R2RMLMappingDocument, MorphRDBUnfolder, MorphRDBDataMaterializer and MorphRDBDataTranslator (see above).
- Run the process using either materialization (MorphBaseRunner.materializeMappingDocuments) or query rewriting
- Load the RDF graph produced in a JENA model and save a serialization into a file using the requested RDF syntax.

Expand Down
4 changes: 0 additions & 4 deletions morph-xr2rml-dist/example_mongo/mapping.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ex: <http://example.com/> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<#Students>
a rr:TriplesMap;
xrr:logicalSource [
# Jongo needs strings in singles quotes (difference with MongoDB shell)
xrr:query """db.students.find( { 'FullName' : {$exists: 1} } )""";
xrr:referenceFormulation ql:JSONPath;
];
rr:subjectMap [
rr:template "http://example.org/student/{$._id.*}";
Expand Down Expand Up @@ -51,7 +49,6 @@
a rr:TriplesMap;
xrr:logicalSource [
xrr:query "db.movies.find( { movies: { $exists: true} } )";
xrr:referenceFormulation ql:JSONPath;
rml:iterator "$.movies.*";
];
rr:subjectMap [
Expand All @@ -63,7 +60,6 @@
a rr:TriplesMap;
xrr:logicalSource [
xrr:query "db.movies.find( { directors: { $exists: true} } )";
xrr:referenceFormulation ql:JSONPath;
rml:iterator "$.directors.*";
];
rr:subjectMap [ rr:template "http://example.org/director/{$.name}"; ];
Expand Down
2 changes: 1 addition & 1 deletion morph-xr2rml-dist/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Logging properties
#log4j.rootCategory=file,console
log4j.rootLogger=TRACE,file,console
log4j.rootLogger=INFO,file,console

layout.fileLayout=%d{yyyy-MM-dd HH:mm:ss} %-5p %C{1}.%M:%L %x - %m%n
layout.consoleLayout=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] (%F:%L) - %m%n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ object MorphRunner {
logger.info("properties Directory = " + configDir)
logger.info("properties File = " + configFile)

// Create the runner, parse the mapping document, create the unfolder, data materializer, data translator etc.
val properties = MorphProperties(configDir, configFile)

val runnerFactInstance = Class.forName(properties.runnerFactoryClassName).newInstance()
val runnerFact = runnerFactInstance.asInstanceOf[MorphBaseRunnerFactory]
// Create the runner factory based on the class name given in configuration file
val runnerFact = Class.forName(properties.runnerFactoryClassName).newInstance().asInstanceOf[MorphBaseRunnerFactory]

// Create the runner, parse the mapping document, create the unfolder, data materializer, data translator etc.
val runner = runnerFact.createRunner(properties);

// Start the translation process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MorphJsondocDataTranslator(
extends MorphBaseDataTranslator(md, materializer, unfolder, dataSourceReader, connection, properties)
with MorphR2RMLElementVisitor {

/** Store already executed queries do avoid running them several times */
/** Store already executed queries to avoid running them several times */
private var executedQueries: scala.collection.mutable.Map[String, List[String]] = new scala.collection.mutable.HashMap

override val logger = Logger.getLogger(this.getClass().getName());
Expand Down Expand Up @@ -353,34 +353,6 @@ class MorphJsondocDataTranslator(
result
}

private def getResultSetValue(termMap: R2RMLTermMap, rs: ResultSet, pColumnName: String): Object = {
try {
val zConstant = MorphSQLConstant(pColumnName, ZConstant.COLUMNNAME);
val tableName = zConstant.table;
val columnName = {
if (tableName != null) {
tableName + "." + zConstant.column
} else
zConstant.column
}

val result = if (termMap.datatype == null) {
rs.getString(columnName);
} else if (termMap.datatype.equals(XSDDatatype.XSDdateTime.getURI())) {
rs.getDate(columnName).toString();
} else {
rs.getObject(columnName);
}
result
} catch {
case e: Exception => {
e.printStackTrace();
logger.error("An error occured when reading the SQL result set : " + e.getMessage());
null
}
}
}

/**
* Create a JENA literal resource with optional data type and language tag.
* This method is overriden in the case of JSON to enable the mapping between JSON data types
Expand Down

0 comments on commit a140a33

Please sign in to comment.