Fix #3266: Normalize fullwidth Unicode characters in translated tags.
This commit is contained in:
@@ -87,7 +87,7 @@ module Sources
|
|||||||
|
|
||||||
# Given a tag from the source site, should return an array of corresponding Danbooru tags.
|
# Given a tag from the source site, should return an array of corresponding Danbooru tags.
|
||||||
def translate_tag(untranslated_tag)
|
def translate_tag(untranslated_tag)
|
||||||
translated_tags = Tag.where(name: WikiPage.active.other_names_equal([untranslated_tag]).uniq.select(:title))
|
translated_tags = Tag.where(name: WikiPage.active.other_names_equal(untranslated_tag).uniq.select(:title))
|
||||||
|
|
||||||
if translated_tags.empty?
|
if translated_tags.empty?
|
||||||
normalized_name = TagAlias.to_aliased([Tag.normalize_name(untranslated_tag)])
|
normalized_name = TagAlias.to_aliased([Tag.normalize_name(untranslated_tag)])
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ class WikiPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def other_names_equal(names)
|
def other_names_equal(name)
|
||||||
query_sql = names.map(&:to_escaped_for_tsquery).join(" | ")
|
query_sql = name.unicode_normalize(:nfkc).to_escaped_for_tsquery
|
||||||
where("other_names_index @@ to_tsquery('danbooru', E?)", query_sql)
|
where("other_names_index @@ to_tsquery('danbooru', E?)", query_sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class WikiPage < ApplicationRecord
|
|||||||
subquery = WikiPage.from("unnest(string_to_array(other_names, ' ')) AS other_name").where("other_name ILIKE ?", name.to_escaped_for_sql_like)
|
subquery = WikiPage.from("unnest(string_to_array(other_names, ' ')) AS other_name").where("other_name ILIKE ?", name.to_escaped_for_sql_like)
|
||||||
where(id: subquery)
|
where(id: subquery)
|
||||||
else
|
else
|
||||||
other_names_equal([name])
|
other_names_equal(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ module Sources
|
|||||||
class NijieTest < ActiveSupport::TestCase
|
class NijieTest < ActiveSupport::TestCase
|
||||||
context "The source site for a nijie page" do
|
context "The source site for a nijie page" do
|
||||||
setup do
|
setup do
|
||||||
|
CurrentUser.user = FactoryGirl.create(:user)
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
@site = Sources::Site.new("http://nijie.info/view.php?id=213043")
|
@site = Sources::Site.new("http://nijie.info/view.php?id=213043")
|
||||||
@site.get
|
@site.get
|
||||||
end
|
end
|
||||||
@@ -24,6 +27,17 @@ module Sources
|
|||||||
assert_equal([["眼鏡", "http://nijie.info/search.php?word=%E7%9C%BC%E9%8F%A1"], ["リトルウィッチアカデミア", "http://nijie.info/search.php?word=%E3%83%AA%E3%83%88%E3%83%AB%E3%82%A6%E3%82%A3%E3%83%83%E3%83%81%E3%82%A2%E3%82%AB%E3%83%87%E3%83%9F%E3%82%A2"], ["アーシュラ先生", "http://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"]], @site.tags)
|
assert_equal([["眼鏡", "http://nijie.info/search.php?word=%E7%9C%BC%E9%8F%A1"], ["リトルウィッチアカデミア", "http://nijie.info/search.php?word=%E3%83%AA%E3%83%88%E3%83%AB%E3%82%A6%E3%82%A3%E3%83%83%E3%83%81%E3%82%A2%E3%82%AB%E3%83%87%E3%83%9F%E3%82%A2"], ["アーシュラ先生", "http://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"]], @site.tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "normalize ()characters in tags" do
|
||||||
|
FactoryGirl.create(:tag, :name => "kaga")
|
||||||
|
FactoryGirl.create(:wiki_page, :title => "kaga", :other_names => "加賀(艦これ)")
|
||||||
|
|
||||||
|
@site = Sources::Site.new("http://nijie.info/view.php?id=208316")
|
||||||
|
@site.get
|
||||||
|
|
||||||
|
assert_includes(@site.tags.map(&:first), "加賀(艦これ)")
|
||||||
|
assert_includes(@site.translated_tags.map(&:first), "kaga")
|
||||||
|
end
|
||||||
|
|
||||||
should "get the commentary" do
|
should "get the commentary" do
|
||||||
title = "ジャージの下は"
|
title = "ジャージの下は"
|
||||||
desc = "「リトルウィッチアカデミア」から無自覚サキュバスぶりを発揮するアーシュラ先生です"
|
desc = "「リトルウィッチアカデミア」から無自覚サキュバスぶりを発揮するアーシュラ先生です"
|
||||||
|
|||||||
Reference in New Issue
Block a user