Class Pho::QueryProfile
In: lib/pho/query_profile.rb
Parent: Object

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.

Methods

Attributes

field_weights  [R]  The list of field weightings
label  [R]  Label associated with the resource in the Platform config
uri  [R]  URI for this resource

Public Class methods

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

[Source]

# 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

[Source]

# 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

[Source]

# 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

Public Instance methods

[Source]

# File lib/pho/query_profile.rb, line 105
    def <<(weight)
        @field_weights << weight    
    end

Retrieve a FieldWeighing by name

[Source]

# File lib/pho/query_profile.rb, line 110
    def get_by_name(name)
      return @field_weights.detect { |field| field.name == name }  
    end

Is there a field weighting for a property with this name?

[Source]

# File lib/pho/query_profile.rb, line 133
    def mapped_name?(name)
      return get_by_name(name) != nil
    end

Remove a FieldWeighting from the collection

[Source]

# File lib/pho/query_profile.rb, line 123
    def remove(fw)
      return @field_weights.delete(fw)
    end

Remove all field weights

[Source]

# File lib/pho/query_profile.rb, line 128
    def remove_all()
      @field_weights = Array.new
    end

Remove a FieldWeighting by name

[Source]

# 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

Dump this object to an RDF/XML representation suitable for submitting to the Platform

[Source]

# 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 an RDF/XML presentation of this object to the provided Platform Store

[Source]

# File lib/pho/query_profile.rb, line 163
    def upload(store)
        return store.put_query_profile(self.to_rdf)  
    end

[Validate]