aboutsummaryrefslogtreecommitdiff
path: root/sources/db
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-23 20:24:05 +0100
committerJochen Topf <jochen@topf.org>2013-01-23 20:24:10 +0100
commite39328c81887ffd013f7f2f6a280cb0cec7c43c5 (patch)
treea20852a2008a2397600d03708da135de9185a3d4 /sources/db
parent480c018596d1883a402be16eb4420244bd3d2ff5 (diff)
downloadtaginfo-e39328c81887ffd013f7f2f6a280cb0cec7c43c5.tar
taginfo-e39328c81887ffd013f7f2f6a280cb0cec7c43c5.tar.gz
Reimplemented update_characters in Ruby.
Now that we are using Ruby 1.9 we have the necessary Unicode support and can get rid of the last Perl dependency.
Diffstat (limited to 'sources/db')
-rwxr-xr-xsources/db/update.sh2
-rwxr-xr-xsources/db/update_characters.rb60
2 files changed, 61 insertions, 1 deletions
diff --git a/sources/db/update.sh b/sources/db/update.sh
index f293503..1f00088 100755
--- a/sources/db/update.sh
+++ b/sources/db/update.sh
@@ -53,7 +53,7 @@ fi
$TAGSTATS --tags $DIR/interesting_tags.lst --relation-types $DIR/interesting_relation_types.lst --left=$left --bottom=$bottom --top=$top --right=$right --width=$width --height=$height $PLANETFILE $DATABASE
echo "`$DATECMD` Running update_characters... "
-./update_characters.pl $DIR
+./update_characters.rb $DIR
echo "`$DATECMD` Running post.sql... "
sqlite3 $DATABASE <post.sql
diff --git a/sources/db/update_characters.rb b/sources/db/update_characters.rb
new file mode 100755
index 0000000..671b38e
--- /dev/null
+++ b/sources/db/update_characters.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/ruby
+#------------------------------------------------------------------------------
+#
+# Taginfo source: DB
+#
+# update_characters.rb
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (C) 2013 Jochen Topf <jochen@remote.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+#------------------------------------------------------------------------------
+
+require 'sqlite3'
+
+dir = ARGV[0] || '.'
+db = SQLite3::Database.new(dir + '/taginfo-db.db')
+db.results_as_hash = true
+
+regexes = [
+ [ 'plain', %r{^[a-z]([a-z_]*[a-z])?$} ],
+ [ 'colon', %r{^[a-z][a-z_:]*[a-z]$} ],
+ [ 'letters', %r{^[\p{L}\p{M}]([\p{L}\p{M}\p{N}_:]*[\p{L}\p{M}\p{N}])?$}u ],
+ [ 'space', %r{[\s\p{Z}]}u ],
+ [ 'problem', %r{[=+/&<>;\@'"?%#\\,\p{C}]}u ]
+];
+
+keys = {}
+db.execute("SELECT key FROM keys").map{ |row| row['key'] }.each do |key|
+ keys[key] = 'rest'
+ regexes.each do |type, regex|
+ if key.match(regex)
+ keys[key] = type
+ break
+ end
+ end
+end
+
+db.execute('BEGIN TRANSACTION');
+
+keys.each do |key, type|
+ db.execute("UPDATE keys SET characters=? WHERE key=?", type, key);
+end
+
+db.execute('COMMIT');
+