Fix #3208: Fix translated tag suggestions for Pixiv.

* Only suggest the Danbooru tag with the same name if there is no
  matching wiki other name. Example: if we have the Pixiv tag `Fate` and
  the Danbooru tag `fate_(series)` with other name `fate`, suggest that,
  not the Danbooru tag `fate`.

* Don't suggest tags that are empty or whose wiki is deleted.

* Only split tags on "/" if there are no other matches, and only for Pixiv.

* For Pixiv, only include traditional media tags in tag list, not digital media (Photoshop, SAI).

* Add some tests.
This commit is contained in:
evazion
2017-07-09 11:43:55 -05:00
parent a860bec0a7
commit cc8986641b
6 changed files with 112 additions and 20 deletions

View File

@@ -8,7 +8,7 @@ module Sources
:file_url, :ugoira_frame_data, :ugoira_content_type, :image_urls,
:artist_commentary_title, :artist_commentary_desc,
:dtext_artist_commentary_title, :dtext_artist_commentary_desc,
:rewrite_thumbnails, :illust_id_from_url, :to => :strategy
:rewrite_thumbnails, :illust_id_from_url, :translate_tag, :translated_tags, :to => :strategy
def self.strategies
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::ArtStation, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr, Strategies::Pawoo]
@@ -43,23 +43,6 @@ module Sources
url
end
def translated_tags
untranslated_tags = tags
untranslated_tags = untranslated_tags.map(&:first)
untranslated_tags += untranslated_tags.grep(/\//).map {|x| x.split(/\//)}.flatten
untranslated_tags = untranslated_tags.map do |tag|
if tag =~ /\A(\S+?)_?\d+users入り\Z/
$1
else
tag
end
end
untranslated_tags.reject! {|x| x.blank?}
wikis = WikiPage.title_in(untranslated_tags)
wikis += WikiPage.other_names_equal(untranslated_tags)
wikis.uniq.map{|wiki_page| [wiki_page.title, wiki_page.category_name]}
end
def to_h
return {
:artist_name => artist_name,