Class: Pho::QueryProfile
- Inherits:
-
Object
- Object
- Pho::QueryProfile
- Defined in:
- lib/pho/query_profile.rb
Overview
Models the QueryProfile configuration associated with a Platform store
Class methods exist to read a QueryProfile from a store, providing some convenience over the basic Store methods.
Instance Attribute Summary collapse
-
#field_weights ⇒ Object
readonly
The list of field weightings.
-
#label ⇒ Object
readonly
Label associated with the resource in the Platform config.
-
#uri ⇒ Object
readonly
URI for this resource.
Class Method Summary collapse
-
.create_weighting(store, name, weight) ⇒ Object
Create a FieldWeighting object suitable for adding to this store.
- .read_from_store(store) ⇒ Object
Instance Method Summary collapse
- #<<(weight) ⇒ Object
-
#get_by_name(name) ⇒ Object
Retrieve a FieldWeighing by name.
-
#initialize(uri, label, field_weights = Array.new) ⇒ QueryProfile
constructor
A new instance of QueryProfile.
-
#mapped_name?(name) ⇒ Boolean
Is there a field weighting for a property with this name?.
-
#remove(fw) ⇒ Object
Remove a FieldWeighting from the collection.
-
#remove_all ⇒ Object
Remove all field weights.
-
#remove_by_name(name) ⇒ Object
Remove a FieldWeighting by name.
-
#to_rdf ⇒ Object
Dump this object to an RDF/XML representation suitable for submitting to the Platform.
-
#upload(store) ⇒ Object
Upload an RDF/XML presentation of this object to the provided Platform Store.
Constructor Details
#initialize(uri, label, field_weights = Array.new) ⇒ QueryProfile
Returns a new instance of QueryProfile.
99 100 101 102 103 |
# File 'lib/pho/query_profile.rb', line 99 def initialize(uri, label, field_weights=Array.new) @uri = uri @label = label @field_weights = field_weights end |
Instance Attribute Details
#field_weights ⇒ Object (readonly)
The list of field weightings
51 52 53 |
# File 'lib/pho/query_profile.rb', line 51 def field_weights @field_weights end |
#label ⇒ Object (readonly)
Label associated with the resource in the Platform config
45 46 47 |
# File 'lib/pho/query_profile.rb', line 45 def label @label end |
#uri ⇒ Object (readonly)
URI for this resource
48 49 50 |
# File 'lib/pho/query_profile.rb', line 48 def uri @uri end |
Class Method Details
.create_weighting(store, name, weight) ⇒ Object
Create a FieldWeighting object suitable for adding to this store. Will ensure that the name of the propery is valid according to the Platform naming rules
- store
-
the store that the weighting is to be created for
- name
-
name of the field to be weighted
- weight
-
the weighting of the field
89 90 91 92 93 94 95 96 97 |
# File 'lib/pho/query_profile.rb', line 89 def QueryProfile.create_weighting(store, name, weight) if !name.match(/^[a-zA-Z][a-zA-Z0-9]*$/) raise "Name does not conform to regular expression: ^[a-zA-Z][a-zA-Z0-9]*$" end weight_uri = store.build_uri("/config/queryprofiles/1##{name}") return FieldWeighting.new(weight_uri, name, weight) end |
.read_from_store(store) ⇒ Object
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 |
# File 'lib/pho/query_profile.rb', line 53 def QueryProfile.read_from_store(store) resp = store.get_query_profile(Pho::ACCEPT_JSON) if resp.status != 200 raise "Unable to read Query Profile from store. Response code was #{resp.status}" end qp_uri = store.build_uri("/config/queryprofiles/1") json = JSON.parse( resp.content ) labels = json[qp_uri]["http:\/\/www.w3.org\/2000\/01\/rdf-schema#label"] if labels != nil && labels.length > 0 label = labels[0]["value"] else label = "query profile" end qp = QueryProfile.new(qp_uri, label) field_weights = json[qp_uri]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#fieldWeight"] field_weights.each { |uri| property = json[uri["value"]] name = property["http:\/\/schemas.talis.com\/2006\/frame\/schema#name"][0]["value"] weight = property["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#weight"][0]["value"] qp << FieldWeighting.new(uri["value"], name, weight) } return qp end |
Instance Method Details
#<<(weight) ⇒ Object
105 106 107 |
# File 'lib/pho/query_profile.rb', line 105 def <<(weight) @field_weights << weight end |
#get_by_name(name) ⇒ Object
Retrieve a FieldWeighing by name
110 111 112 |
# File 'lib/pho/query_profile.rb', line 110 def get_by_name(name) return @field_weights.detect { |field| field.name == name } end |
#mapped_name?(name) ⇒ Boolean
Is there a field weighting for a property with this name?
133 134 135 |
# File 'lib/pho/query_profile.rb', line 133 def mapped_name?(name) return get_by_name(name) != nil end |
#remove(fw) ⇒ Object
Remove a FieldWeighting from the collection
123 124 125 |
# File 'lib/pho/query_profile.rb', line 123 def remove(fw) return @field_weights.delete(fw) end |
#remove_all ⇒ Object
Remove all field weights
128 129 130 |
# File 'lib/pho/query_profile.rb', line 128 def remove_all() @field_weights = Array.new end |
#remove_by_name(name) ⇒ Object
Remove a FieldWeighting by name
115 116 117 118 119 120 |
# File 'lib/pho/query_profile.rb', line 115 def remove_by_name(name) fw = get_by_name(name) if (fw != nil) return remove(fw) end end |
#to_rdf ⇒ Object
Dump this object to an RDF/XML representation suitable for submitting to the Platform
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/pho/query_profile.rb', line 138 def to_rdf rdf = "<rdf:RDF xmlns:frm=\"#{Pho::Namespaces::FRAME}\" " rdf << " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " rdf << " xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" " rdf << " xmlns:bf=\"#{Pho::Namespaces::CONFIG}\" > " rdf << " <rdf:Description rdf:about=\"#{@uri}\"> " rdf << " <rdf:type rdf:resource=\"#{Pho::Namespaces::CONFIG}QueryProfile\"/> " rdf << " <rdfs:label>#{@label}</rdfs:label> " @field_weights.each do |property| rdf << " <bf:fieldWeight rdf:resource=\"#{property.uri}\"/> " end rdf << " </rdf:Description>" @field_weights.each do |property| rdf << property.to_rdf(false) end rdf << "</rdf:RDF>" end |
#upload(store) ⇒ Object
Upload an RDF/XML presentation of this object to the provided Platform Store
163 164 165 |
# File 'lib/pho/query_profile.rb', line 163 def upload(store) return store.put_query_profile(self.to_rdf) end |