Module: ActiveSesame::Support

Included in:
Ontology::Term, OwlThing
Defined in:
lib/active_sesame/support.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.encode_whitespace(string) ⇒ Object



15
16
17
# File 'lib/active_sesame/support.rb', line 15

def self.encode_whitespace(string)
  string.gsub(" ","%20")
end

.property_to_constant(prop) ⇒ Object

Think about changing to a uri class rather than manipulating strings…



5
6
7
8
9
# File 'lib/active_sesame/support.rb', line 5

def self.property_to_constant(prop)
  prop = prop.to_s
  prop = ResultParser.uri_to_sym(prop) if prop.match(/#/) 
  prop.first.upcase + prop.slice(1,prop.length)
end

.uncode_whitespace(string) ⇒ Object



19
20
21
# File 'lib/active_sesame/support.rb', line 19

def self.uncode_whitespace(string)
  return string.class == String ? string.gsub("%20"," ") : string
end

.uri_to_sym(uri) ⇒ Object



11
12
13
# File 'lib/active_sesame/support.rb', line 11

def self.uri_to_sym(uri)
  uri.split("#")[1].to_sym
end

Instance Method Details

#expand_prefix(prefix, additional_uris = {}) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/active_sesame/support.rb', line 73

def expand_prefix(prefix, additional_uris={})
  #puts "\n#{additional_uris.inspect}\n"
  if additional_uris.has_key?(prefix)
    additional_uris[prefix]
  else
    throw "Invalid Prefix: the prefix \"#{prefix}\" was not found in #{additional_uris.inspect}"
  end
end

#expand_term(full_term, additional_uris = {}) ⇒ Object



67
68
69
70
71
# File 'lib/active_sesame/support.rb', line 67

def expand_term(full_term, additional_uris={})
  #puts "\n#{additional_uris.inspect}\n"
  prefix, term = full_term.split(":")
  (term != nil and not is_uri?(full_term)) ? expand_prefix(prefix, additional_uris) + "#" + term : full_term
end

#expand_terms(term_list, additional_uris = {}) ⇒ Object



62
63
64
65
# File 'lib/active_sesame/support.rb', line 62

def expand_terms(term_list, additional_uris={})
  #puts "\n#{additional_uris.inspect}\n"
  term_list.collect {|term| self.expand_term(term) }
end

#expand_triple(triple, additional_uris = {}) ⇒ Object



57
58
59
60
# File 'lib/active_sesame/support.rb', line 57

def expand_triple(triple, additional_uris={})
  #puts "\n#{additional_uris.inspect}\n"
  triple.keys.inject(Hash.new) {|hash,key| hash[key] = expand_term(triple[key], additional_uris); hash }
end

#expand_triples(triple_list, additional_uris = {}) ⇒ Object



52
53
54
55
# File 'lib/active_sesame/support.rb', line 52

def expand_triples(triple_list, additional_uris={})
  #puts "\n#{additional_uris.inspect}\n"
  triple_list.collect {|triple| expand_triple(triple, additional_uris) }
end

#is_uri?(string) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/active_sesame/support.rb', line 23

def is_uri?(string)
  if string.class == String
    string =~ /^http:\/\//
  else
    false
  end
end

#method_from_uri(uri, additional_uris = {}) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/active_sesame/support.rb', line 43

def method_from_uri(uri, additional_uris={})
  #puts "uris for doober: #{additional_uris.inspect}"
  #puts "uri to be transformed to method #{uri}"
  #puts "method generated: #{self.uri_to_prefix(uri, additional_uris)}"
  uri_prefix = self.uri_to_prefix(uri, additional_uris)
  bogus, term = uri.split("#")
  term ? "#{uri_prefix}_#{term}" : uri_prefix
end

#uri_to_prefix(uri, additional_uris = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_sesame/support.rb', line 31

def uri_to_prefix(uri, additional_uris={})
  uri_prefix, term = uri.split("#")
  uri_prefixes = ActiveSesame::RDFConstants.prefixes.merge(additional_uris)
  uri_prefixes = uri_prefixes.keys.inject(Hash.new) {|hash,key| hash[uri_prefixes[key]] = key; hash} #reverse key and value
  #puts "\n" + uri_prefixes.inspect + "\n"
  if uri_prefixes.has_key?(uri_prefix)
    uri_prefixes[uri_prefix]
  else
    uri_prefix
  end
end