set -euo pipefail

# Replace objects `"... "^^<...#wktLiteral>` which literal starts with `<...>` to xsd:string
# Ex: "<http://www.wikidata.org/entity/Q111> Point(351.83 -14.47)"^^<...#wktLiteral> to ^^<...#string>

bunzip2 -c latest/latest-all.nt.bz2 | awk '
{
  if ($0 ~ /"[^"]*"(\^\^<http:\/\/www\.opengis\.net\/ont\/geosparql#wktLiteral>)[[:space:]]*\.[[:space:]]*$/ && $0 ~ /"<[^>]+>[[:space:]]/) {
    gsub(/\^\^<http:\/\/www\.opengis\.net\/ont\/geosparql#wktLiteral>/, "^^<http://www.w3.org/2001/XMLSchema#string>")
  }
  print
}
' | bzip2 > latest/latest-all.geo-as-string.nt.bz2

