public class RdbToRdf
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.String> |
datatypeProperties
Collection of datatype properties already encountered
|
private static java.lang.String |
DEFAULT_DATA_CLASS
Default class for all the exported records
|
private static java.lang.String |
DEFAULT_NAMESPACE
Default namespace for the data loaded from the RDB
|
private static java.text.SimpleDateFormat |
FORMAT_DATE
Used for formatting DB date column values into the ontology
|
private static java.text.SimpleDateFormat |
FORMAT_DATE_TIME
Used for formatting DB timestamp (date and time) column values into the
ontology
|
private static java.text.SimpleDateFormat |
FORMAT_TIME
Used for formatting DB time column values into the ontology
|
private static java.lang.String[] |
FORMATS
The set of formats that can be output.
|
private long |
latestNumberOfRowsExported
Count of DB rows exported as of last execution of this instance
|
private static org.apache.log4j.Logger |
LOGGER
Logging instance
|
private com.hp.hpl.jena.ontology.OntModel |
ontModel
The loaded ontology
|
private java.lang.String |
outputFileName
The name (and path if necessary) to the output file for the output
triples
|
private java.lang.String |
outputFormat
The output format for the triples
This will default to match the input format
TODO allow control from command line or configuration
|
private java.lang.String |
query
The query returning the result set
|
private java.lang.String |
rdfDataClass
The class of the data instances generated
|
private java.lang.String |
rdfNamespace
The namespace to use for the generated resources and predicates
|
private static java.lang.String |
REASONING_LEVEL
The reasoning level to use
TODO allow this to be controlled from command line or configuration
|
protected static java.lang.String[] |
REASONING_LEVELS
The reasoning levels available.
|
private java.sql.ResultSet |
resultSet
The result set to be exported
|
private java.sql.ResultSetMetaData |
resultSetMetaData
The metadata associated with the result set
|
private static int |
UNKNOWN
Constant used if a value cannot be found in an array
|
Constructor and Description |
---|
RdbToRdf(java.lang.String pOutputFileName,
java.lang.String pQuery,
java.sql.ResultSet pResultSet)
Constructor - sets up the input and output file paths and the triples map
|
Modifier and Type | Method and Description |
---|---|
private void |
addInstance(java.lang.String subject,
java.lang.String namespace,
java.lang.String className)
Add the PK value as a new instance of the data class.
|
private void |
addStatement(java.lang.String subject,
java.lang.String predicate,
java.lang.String objectLiteral,
int rdbColumnType,
java.lang.String namespace,
java.lang.String className)
Add the RDB data, treating the column data as a literal value
|
private java.lang.String |
convertToCamelCase(java.lang.String name,
boolean initialUpper)
Convert a string into CamelCase or camelCase
|
private java.lang.String |
convertToClassName(java.lang.String name)
Convert a string to a CamelCase format matching class naming convention
|
private java.lang.String |
convertToInstanceName(java.lang.String name)
Convert a string into a camelCase format matching instance naming
convention
|
private java.lang.String |
convertToPropertyName(java.lang.String name)
Convert a string into a camelCase format matching property naming
convention
|
private com.hp.hpl.jena.ontology.OntModel |
createModel(java.lang.String reasoningLevel)
Create a model with a reasoner set based on the chosen reasoning level.
|
static java.lang.String |
getArrayAsCSV(java.lang.String[] array)
Create a CSV list from a String array
|
static java.lang.String |
getFormatsAsCSV()
Get the set of defined ontology file formats that the program can load as
a CSV list String
|
static int |
getIndexValue(java.lang.String[] array,
java.lang.String name)
Find a String value within and array of Strings.
|
long |
getLatestNumberOfRowsExported()
Get the number of DB rows exported to triples as of the last exeuction of
this instance
|
java.lang.String |
getOutputFileName()
Get the output file name for the location of the generated report
|
private java.lang.String |
getQuery()
Get the query returning the result set
|
static int |
getReasoningLevelIndex(java.lang.String reasonerName)
Get the index position of the supplied reasoning level label
|
private java.sql.ResultSet |
getResultSet()
Get the result set to be exported
|
private java.sql.ResultSetMetaData |
getResultSetMetaData()
Get the metadata for the result set to be exported
|
private void |
loadModel(java.lang.String reasoningLevel)
Obtain an ontology model set to the chosen reasoning level.
|
private void |
loadModelFromRdb()
Setup the ontology model from the data anbd metadata in the result set
|
private void |
makeDatatypeProperty(java.lang.String namespace,
java.lang.String propertyName)
Check to see if this property URI has been asserted as an
owl:DatatypeProperty.
|
private static java.lang.String |
makeSafeURIValue(java.lang.String value)
Very crude method to create a value that will work as an RDF resource -
e.g.
|
void |
run()
Perform the steps to load, compare and report on the ontology
|
void |
setOutputFileName(java.lang.String pOutputFileName)
Set the output file name, where the report should be written
|
private void |
setQuery(java.lang.String pQuery)
Set the query returning the result set
|
private void |
setResultSet(java.sql.ResultSet pResultSet)
Set the result set to be exported
|
private void |
setResultSetMetaData(java.sql.ResultSetMetaData pResultSetMetaData)
Set the metadata for the result set to be exported
|
private void |
storeModel()
Writes the triples to a data file.
|
private static final org.apache.log4j.Logger LOGGER
private static final java.lang.String DEFAULT_NAMESPACE
private static final java.lang.String DEFAULT_DATA_CLASS
private static final java.text.SimpleDateFormat FORMAT_DATE
private static final java.text.SimpleDateFormat FORMAT_TIME
private static final java.text.SimpleDateFormat FORMAT_DATE_TIME
private java.lang.String rdfNamespace
private java.lang.String rdfDataClass
private static final java.lang.String[] FORMATS
private static final java.lang.String REASONING_LEVEL
private java.lang.String outputFormat
protected static final java.lang.String[] REASONING_LEVELS
private static final int UNKNOWN
private java.lang.String outputFileName
private com.hp.hpl.jena.ontology.OntModel ontModel
private java.lang.String query
private java.sql.ResultSet resultSet
private java.sql.ResultSetMetaData resultSetMetaData
private java.util.Map<java.lang.String,java.lang.String> datatypeProperties
private long latestNumberOfRowsExported
public RdbToRdf(java.lang.String pOutputFileName, java.lang.String pQuery, java.sql.ResultSet pResultSet)
pOutputFileName
- The name (and optional path) for the outputpQuery
- The query associated with the result setpResultSet
- The database result set to exportpublic void run()
run
in interface java.lang.Runnable
private void loadModelFromRdb()
private void addInstance(java.lang.String subject, java.lang.String namespace, java.lang.String className)
subject
- The subject which will be a class instancenamespace
- The namespace for the exported dataclassName
- The class name for the individuals representing the rows of dataprivate void addStatement(java.lang.String subject, java.lang.String predicate, java.lang.String objectLiteral, int rdbColumnType, java.lang.String namespace, java.lang.String className)
subject
- The subject of the triplepredicate
- The predicate of the tripleobjectLiteral
- The object of the triple (treated as a literal)rdbColumnType
- The SQL data type of the column containing this literal valuenamespace
- The namespace for the exported dataclassName
- The class name for the individuals representing the rows of dataprivate void makeDatatypeProperty(java.lang.String namespace, java.lang.String propertyName)
namespace
- The namespace of the propertypropertyName
- The name of the propertyprivate static java.lang.String makeSafeURIValue(java.lang.String value)
value
- the value to be made URI-safeprivate void storeModel()
public static final java.lang.String getFormatsAsCSV()
public static final java.lang.String getArrayAsCSV(java.lang.String[] array)
array
- An arraypublic void setOutputFileName(java.lang.String pOutputFileName)
pOutputFileName
- The output file namepublic java.lang.String getOutputFileName()
private void setQuery(java.lang.String pQuery)
pQuery
- The SQL queryprivate java.lang.String getQuery()
private void setResultSet(java.sql.ResultSet pResultSet)
pResultSet
- The result setprivate java.sql.ResultSet getResultSet()
private void setResultSetMetaData(java.sql.ResultSetMetaData pResultSetMetaData)
pResultSetMetaData
- The metadataprivate java.sql.ResultSetMetaData getResultSetMetaData()
private com.hp.hpl.jena.ontology.OntModel createModel(java.lang.String reasoningLevel)
reasoningLevel
- The reasoning level for this modelprivate void loadModel(java.lang.String reasoningLevel)
reasoningLevel
- The selected reasoning levelpublic static final int getReasoningLevelIndex(java.lang.String reasonerName)
reasonerName
- A reasoning level labelpublic long getLatestNumberOfRowsExported()
public static final int getIndexValue(java.lang.String[] array, java.lang.String name)
array
- An array of string to searchname
- The value to find in the arrayprivate java.lang.String convertToClassName(java.lang.String name)
name
- The text to munge into a class nameprivate java.lang.String convertToPropertyName(java.lang.String name)
name
- The text to munge into a property nameprivate java.lang.String convertToInstanceName(java.lang.String name)
name
- The text to munge into an instance (individual) nameprivate java.lang.String convertToCamelCase(java.lang.String name, boolean initialUpper)
name
- The string to convert to camel caseinitialUpper
- Whether the resulting string should begin with an uppercase
character