Created
September 29, 2016 20:18
-
-
Save jindrichmynarz/b70405edf61715fa141eaca0242f09c7 to your computer and use it in GitHub Desktop.
Fill down blanks in CSV/RDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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