Class: Mei::HomosaurusSubjectResource

Inherits:
Object
  • Object
show all
Defined in:
app/models/mei/homosaurus_subject_resource.rb

Class Method Summary collapse

Class Method Details

.find(subject, type, solr_field) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/mei/homosaurus_subject_resource.rb', line 4

def self.find(subject, type, solr_field)
  #solr_response = ActiveFedora::Base.find_with_conditions({subject_tesim: "test"} , rows: '10', fl: 'subject_tesim' )
  #ActiveFedora::Base.find_each("subject_tesim:tes*") { |x| puts 'hi' }
  matches = []
  dup_checker = []
  subject = subject.downcase #FIXME?

  solr_response = Homosaurus.find_with_conditions("dta_homosaurus_lcase_prefLabel_ssi:*#{solr_clean(subject)}*", rows: '25', fl: 'identifier_ssi, prefLabel_ssim, altLabel_ssim, narrower_ssim, broader_ssim, related_ssim' )

  #FIXME - A result for "http" gives back the entire array of values...
  if solr_response.present?

    solr_response.each do |indv_response|
      indv_subj = indv_response["identifier_ssi"]
      if dup_checker.length < 20 && !dup_checker.include?(indv_subj)
        matches << indv_response
        dup_checker << indv_subj
      end
    end
  end


  if dup_checker.length < 20
    solr_response = Homosaurus.find_with_conditions("dta_homosaurus_lcase_altLabel_ssim:*#{solr_clean(subject)}*", rows: '25', fl: 'identifier_ssi, prefLabel_ssim, altLabel_ssim, narrower_ssim, broader_ssim, related_ssim' )

    #FIXME - A result for "http" gives back the entire array of values...
    if solr_response.present?

      solr_response.each do |indv_response|
        indv_subj = indv_response["identifier_ssi"]
        if dup_checker.length < 20 && !dup_checker.include?(indv_subj)
          matches << indv_response
          dup_checker << indv_subj
        end
      end
    end
  end

  if dup_checker.length < 20
    solr_response = Homosaurus.find_with_conditions("dta_homosaurus_lcase_comment_tesi:#{solr_clean(subject)}", rows: '25', fl: 'identifier_ssi, prefLabel_ssim, altLabel_ssim, comment_ssim, narrower_ssim, broader_ssim, related_ssim' )

    #FIXME - A result for "http" gives back the entire array of values...
    if solr_response.present?

      solr_response.each do |indv_response|
        indv_subj = indv_response["identifier_ssi"]
        if dup_checker.length < 20 && !dup_checker.include?(indv_subj)
          matches << indv_response
          dup_checker << indv_subj
        end
      end
    end
  end

  if matches.present?

    return matches.map! { |item|
      ##{URI.escape(item)}
      full_uri = 'http://homosaurus.org/terms/' + item['identifier_ssi']

      count = ActiveFedora::Base.find_with_conditions("homosaurus_subject_ssim:#{solr_clean(full_uri)}", rows: '100', fl: 'subject_tesim' ).length
      if count >= 99
        count = "99+"
      else
        count = count.to_s
      end

      variants = item['altLabel_ssim']

      {
          "uri_link" => full_uri,
          "label" => item['prefLabel_ssim'].first,
          "broader" => getBroader(item['broader_ssim']),
          "narrower" => getNarrower(item['narrower_ssim']),
          "related" => getRelated(item['related_ssim']),
          "variants" => variants,
          "count" => count
      }
    }
  else
    return []
  end
end

.getBroader(broader_uris) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/mei/homosaurus_subject_resource.rb', line 88

def self.getBroader(broader_uris)
  broader_list = []

  if broader_uris.present?
    broader_uris.each do |broader_single_uri|
      broader_label = Homosaurus.find_with_conditions("id:#{solr_clean(broader_single_uri)}", rows: '1', fl: 'prefLabel_ssim' )
      broader_list << {:uri_link=>"http://homosaurus.org/terms/#{broader_single_uri.split('/').last}", :label=>broader_label[0]["prefLabel_ssim"][0]}
    end
  end

  return broader_list
end

.getNarrower(narrower_uris) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/mei/homosaurus_subject_resource.rb', line 101

def self.getNarrower(narrower_uris)
  narrower_list = []

  if narrower_uris.present?
    narrower_uris.each do |narrower_single_uri|
      narrower_label = Homosaurus.find_with_conditions("id:#{solr_clean(narrower_single_uri)}", rows: '1', fl: 'prefLabel_ssim' )
      narrower_list << {:uri_link=>"http://homosaurus.org/terms/#{narrower_single_uri.split('/').last}", :label=>narrower_label[0]["prefLabel_ssim"][0]}
    end
  end

  return narrower_list
end

.getRelated(related_uris) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/mei/homosaurus_subject_resource.rb', line 114

def self.getRelated(related_uris)
  related_list = []

  if related_uris.present?
    related_uris.each do |related_single_uri|
      related_label = Homosaurus.find_with_conditions("id:#{solr_clean(related_single_uri)}", rows: '1', fl: 'prefLabel_ssim' )
      related_list << {:uri_link=>"http://homosaurus.org/terms/#{related_single_uri.split('/').last}", :label=>related_label[0]["prefLabel_ssim"][0]}
    end
  end

  return related_list
end

.solr_clean(term) ⇒ Object



127
128
129
# File 'app/models/mei/homosaurus_subject_resource.rb', line 127

def self.solr_clean(term)
  return term.gsub('\\', '\\\\').gsub(':', '\\:').gsub(' ', '\ ')
end