Class Pho::FieldPredicateMap
In: lib/pho/field_predicate_map.rb
Parent: Object

Models a the Field Predicate Map configuration associated with a Platform Store.

Class methods exist to create a FieldPredicateMap instance by reading from a store, and to create DatatypeProperty instances checking that the supplied data is valid according to the same logic as used by the Platform API.

Methods

Attributes

datatype_properties  [R]  An array of DatatypeProperty instances
label  [R]  Label associated with the resource in the Platform config
uri  [R]  URI for this resource

Public Class methods

Create a DatatypeProperty instance, automatically assigning a unique identifier to it, and validating the supplied data to ensure it matches the platform rules.

Then automatically appends it to the provided fpmap instance

[Source]

# File lib/pho/field_predicate_map.rb, line 157
    def FieldPredicateMap.add_mapping(fpmap, store, property_uri, name, analyzer=nil)
      mapping = create_mapping(store, property_uri, name, analyzer)
      fpmap << mapping
      return mapping
    end

Create a DatatypeProperty instance, automatically assigning a unique identifier to it, and validating the supplied data to ensure it matches the platform rules

[Source]

# File lib/pho/field_predicate_map.rb, line 139
    def FieldPredicateMap.create_mapping(store, property_uri, name, analyzer=nil)
        check_value("property_uri", property_uri)
        check_value("name", name)
        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        
        if analyzer != nil && analyzer.empty?
          analyzer = nil
        end  
        suffix = get_suffix(property_uri)
        mapping_uri = store.build_uri("/config/fpmaps/1##{suffix}")
        return DatatypeProperty.new(mapping_uri, property_uri, name, analyzer)        
    end

[Source]

# File lib/pho/field_predicate_map.rb, line 163
    def initialize(uri, label, datatype_properties = [])
      @uri = uri
      @label = label
      @datatype_properties = datatype_properties
    end

Read a FieldPredicateMap instance from the provided store. The method will retrieve the config as JSON, and parse it to create an object instance.

[Source]

# File lib/pho/field_predicate_map.rb, line 109
    def FieldPredicateMap.read_from_store(store)
        resp = store.get_field_predicate_map(Pho::ACCEPT_JSON)        
        if resp.status != 200
          raise "Unable to read Field Predicate Map from store. Response code was #{resp.status}"
        end

        fpmap_uri = store.build_uri("/config/fpmaps/1")
      
        json = JSON.parse( resp.content )
        labels = json[fpmap_uri]["http:\/\/www.w3.org\/2000\/01\/rdf-schema#label"]
        label = ""
        if labels != nil
          label = labels[0]["value"]
        end
        
        fpmap = FieldPredicateMap.new(fpmap_uri, label)
        
        mapped_properties = json[fpmap_uri]["http:\/\/schemas.talis.com\/2006\/frame\/schema#mappedDatatypeProperty"]
        mapped_properties.each { |uri|
          property = json[uri["value"]]
          property_uri = property["http:\/\/schemas.talis.com\/2006\/frame\/schema#property"][0]["value"]
          name = property["http:\/\/schemas.talis.com\/2006\/frame\/schema#name"][0]["value"]
          fpmap << DatatypeProperty.new(uri["value"], property_uri, name)
        }
        
        return fpmap        
    end

Public Instance methods

Append a DatatypeProperty object to this map. Note that the method does not validate the object, and neither does it check for duplicate mappings.

[Source]

# File lib/pho/field_predicate_map.rb, line 172
    def <<(obj)
      @datatype_properties << obj
    end

Find the DatatypeProperty (if any) with the following name mapping

[Source]

# File lib/pho/field_predicate_map.rb, line 211
    def get_by_name(name)
      return @datatype_properties.detect { |mapping| name == mapping.name }
    end

Find the DatatypeProperty using a property uri

[Source]

# File lib/pho/field_predicate_map.rb, line 216
    def get_by_uri(uri)
      return @datatype_properties.detect { |mapping| uri == mapping.property_uri }
    end

Lookup the name mapped to the specified uri

uri:the property uri to search for

[Source]

# File lib/pho/field_predicate_map.rb, line 179
    def get_name(uri)
      p = @datatype_properties.detect { |mapping| uri == mapping.property_uri }
      if p == nil
        return nil
      else
        return p.name        
      end
    end

Lookup the property mapped to the specified name

name:the name to search for

[Source]

# File lib/pho/field_predicate_map.rb, line 191
    def get_property_uri(name)
      p = @datatype_properties.detect { |mapping| name == mapping.name }
      if p == nil
        return nil
      else
        return p.property_uri
      end
    end

Is there a mapping for a property with this name?

[Source]

# File lib/pho/field_predicate_map.rb, line 201
    def mapped_name?(name)
      return get_property_uri(name) != nil
    end

Is there a mapping for this uri?

[Source]

# File lib/pho/field_predicate_map.rb, line 206
    def mapped_uri?(uri)
      return get_name(uri) != nil
    end

Remove a DatatypeProperty from the collection

[Source]

# File lib/pho/field_predicate_map.rb, line 221
    def remove(datatype_property)
      return @datatype_properties.delete(datatype_property)
    end

Remove all currently mapped properties

[Source]

# File lib/pho/field_predicate_map.rb, line 242
    def remove_all()
      @datatype_properties = Array.new
    end

Remove a DatatypeProperty by its mapped name

[Source]

# File lib/pho/field_predicate_map.rb, line 226
    def remove_by_name(name)
      p = get_by_name(name)
      if (p != nil)
        return remove(p)
      end   
    end

Remove a DatatypeProperty by its mapped uri

[Source]

# File lib/pho/field_predicate_map.rb, line 234
    def remove_by_uri(uri)
      p = get_by_uri(uri)
      if (p != nil)
        return remove(p)
      end
    end

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

[Source]

# File lib/pho/field_predicate_map.rb, line 247
    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}FieldPredicateMap\"/> "
      rdf << " <rdfs:label>#{@label}</rdfs:label> "
      
      @datatype_properties.each do |property|
        rdf << " <frm:mappedDatatypeProperty rdf:resource=\"#{property.uri}\"/> "
      end
                  
      rdf << " </rdf:Description>"
      
      @datatype_properties.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/field_predicate_map.rb, line 272
    def upload(store)
        return store.put_field_predicate_map(self.to_rdf)  
    end

[Validate]