columnsToNum = (table, selected) ->
if table? and selected?
.map selected, (i) -> .indexOf _.first csvData[table], i
columnToNum = (table, column) ->
if table? and column?
(_.indexOf Csv.columns(table), column) + 1
propertyLiterals = (mapping, table, lookup) ->
literals = mapping.literals
types = mapping.literalTypes
columns = _.keys mapping.properties[table]
columns = _.filter columns, (i) ->
property = mapping.properties[table][i].prefixedName[0]
return (literals[property] or ((litearls[property] == 'Typed Literal') and types[property]))
properties = _.map columns, (i) ->
property = mapping.properties[table][i].prefixedName[0]
col = ''
if mapping.source == 'csv'
col = columnToNum table, i
else
col = i
switch literals[property]
when 'Blank Node' then lookup[property] = (getVar i, lookup) + ' = bNode(?' + (columnToNum table, i) + ')'
when 'Plain Literal' then lookup[property] = (getVar i, lookup) + ' = plainLiteral(?' + (columnToNum table, i) + ')'
when 'Typed Literal' then lookup[property] = (getVar i, lookup) + ' = typedLiteral(?' + (columnToNum table, i) + ', ' + types[property] + ')'
else ''
if _.isEmpty properties
return ''
else
return _.foldl properties, ((x, y) -> (x + '\n').concat(y))
namespacePrefixes = (mapping) ->
baseUris = [
'Prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>'
'Prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>'
'Prefix xsd: <http://www.w3.org/2001/XMLSchema#>'
]
suggestions = (_.flatten (_.values mapping.classes).concat (_.map (_.values mapping.properties), _.values))
suggestedUris = (_.without (_.map suggestions, (i) ->
if i['vocabulary.prefix']? and i['vocabulary.uri']?
return """Prefix #{_.first i['vocabulary.prefix']}: <#{_.first i['vocabulary.uri']}>"""
else
return null
), null)
baseUri =
if !_.isEmpty(mapping.baseUri)
["""Prefix tns: <#{mapping.baseUri}>"""]
else
[]
return (_.foldl (baseUris.concat suggestedUris, baseUri), ((x, y) -> (x + '\n').concat y))
createClause = (mapping, table) ->
if mapping.source == 'csv'
"Create View Template " + (table.replace /[^\w]/g, '') + " As"
else
"Create View " + (table.replace /[^\w]/g, '') + " As"
fromClause = (mapping, table) ->
if mapping.source == 'rdb'
"From " + table
else
""
{
toSml: (mapping) ->