Class: Buhos::AnalysisTags
- Inherits:
-
Object
- Object
- Buhos::AnalysisTags
- Defined in:
- lib/buhos/analysis_tags.rb
Overview
Analysis of a set of tags Criteria could be: systematic review, user, canonical_document, tag_id
Instance Method Summary collapse
- #canonical_document_id(cd_id) ⇒ Object
- #canonical_documents_by_tag ⇒ Object
- #get_tags_decision_stats ⇒ Object
-
#initialize ⇒ AnalysisTags
constructor
A new instance of AnalysisTags.
- #systematic_review_id(sr_id) ⇒ Object
- #tag_id(tag_id) ⇒ Object
- #tags_by_canonical_document ⇒ Object
-
#tags_in_cds ⇒ Object
List of tuples of tag_id, text and canonical_document_id.
- #user_id(user_id) ⇒ Object
- #where_sql ⇒ Object
Constructor Details
#initialize ⇒ AnalysisTags
Returns a new instance of AnalysisTags.
34 35 36 37 38 39 40 |
# File 'lib/buhos/analysis_tags.rb', line 34 def initialize @canonical_document_id=nil @user_id=nil @systematic_review_id=nil @tag_id=nil @canonical_documents_by_tag=nil end |
Instance Method Details
#canonical_document_id(cd_id) ⇒ Object
41 42 43 44 |
# File 'lib/buhos/analysis_tags.rb', line 41 def canonical_document_id(cd_id) cd_id=[cd_id] unless cd_id.is_a? Array @canonical_document_id=cd_id end |
#canonical_documents_by_tag ⇒ Object
67 68 69 |
# File 'lib/buhos/analysis_tags.rb', line 67 def canonical_documents_by_tag @canonical_documents_by_tag||=.to_hash_groups(:tag_id) end |
#get_tags_decision_stats ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/buhos/analysis_tags.rb', line 80 def query="SELECT t.id, t.text, SUM(CASE WHEN decision='yes' THEN 1 ELSE 0 END) as d_yes, SUM(CASE WHEN decision='no' THEN 1 ELSE 0 END) as d_no, COUNT(DISTINCT(canonical_document_id)) as n_documents FROM tags t INNER JOIN tag_in_cds tic ON t.id=tag_id WHERE #{where_sql} GROUP BY t.id HAVING d_yes>0 ORDER BY t.text " $db[query] end |
#systematic_review_id(sr_id) ⇒ Object
50 51 52 53 |
# File 'lib/buhos/analysis_tags.rb', line 50 def systematic_review_id(sr_id) sr_id=[sr_id] unless sr_id.is_a? Array @systematic_review_id=sr_id end |
#tag_id(tag_id) ⇒ Object
55 56 57 58 |
# File 'lib/buhos/analysis_tags.rb', line 55 def tag_id(tag_id) tag_id=[tag_id] unless tag_id.is_a? Array @tag_id=tag_id end |
#tags_by_canonical_document ⇒ Object
63 64 65 |
# File 'lib/buhos/analysis_tags.rb', line 63 def @tags_by_canonical_document||=.to_hash_groups(:canonical_document_id) end |
#tags_in_cds ⇒ Object
List of tuples of tag_id, text and canonical_document_id
60 61 62 |
# File 'lib/buhos/analysis_tags.rb', line 60 def @canonical_documents_by_tag||=Tag.join(:tag_in_cds, tag_id: :id).where(Sequel.lit(where_sql)).where(:decision=>TagInCd::DECISION_YES).select(:tag_id, :text, :canonical_document_id) end |
#user_id(user_id) ⇒ Object
45 46 47 48 49 |
# File 'lib/buhos/analysis_tags.rb', line 45 def user_id(user_id) user_id=[user_id] unless user_id.is_a? Array @user_id=user_id end |
#where_sql ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/buhos/analysis_tags.rb', line 70 def where_sql where=["1=1"] where.push " canonical_document_id IN (#{@canonical_document_id.join(',')})" if @canonical_document_id where.push " user_id IN (#{@user_id.join(',')})" if @user_id where.push " systematic_review_id IN (#{@systematic_review_id.join(',')})" if @systematic_review_id where.push " tag_id IN (#{@tag_id.join(',')})" if @tag_id where.join(' AND ') end |