Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Created September 29, 2016 20:18
Show Gist options
  • Save jindrichmynarz/b70405edf61715fa141eaca0242f09c7 to your computer and use it in GitHub Desktop.
Save jindrichmynarz/b70405edf61715fa141eaca0242f09c7 to your computer and use it in GitHub Desktop.
Fill down blanks in CSV/RDF
# Fills empty cells with values of their nearest preceding non-empty cells.
# For performance reasons, the function is restricted to :column_1.
# Even so, it takes about 10 minutes for 10k row CSV.
PREFIX : <http://localhost/>
PREFIX csvw: <http://www.w3.org/ns/csvw#>
INSERT {
?row :column_1 ?column_1 .
}
WHERE {
[] csvw:describes ?row ;
csvw:rownum ?rownum .
FILTER NOT EXISTS {
?row :column_1 [] .
}
?previousRow csvw:rownum ?previousRownum .
FILTER (?previousRownum < ?rownum)
FILTER NOT EXISTS {
[] csvw:rownum ?evenCloserRownum ;
csvw:describes/:column_1 [] .
FILTER (?evenCloserRownum > ?previousRownum && ?evenCloserRownum < ?rownum)
}
?previousRow csvw:describes/:column_1 ?column_1 .
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment