summaryrefslogtreecommitdiff
path: root/lib/opentox.rb
blob: 453ca66f0444ca377849518b0985f729cc96be81 (plain)
1
2
3
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
module OpenTox

  # Generic OpenTox class
  module OtObject

    attr_reader :uri
    attr_accessor :metadata

    # Initialize OpenTox object with optional uri
    def initialize(uri=nil)
      @metadata = {}
      self.uri = uri if uri
    end

    # Set URI
    def uri=(uri)
      @uri = uri
      @metadata[XSD.anyUri] = uri
    end
    
    # Get title
    def title
      load_metadata unless @metadata[DC.title]
      @metadata[DC.title]
    end
    
    # Set title
    def title=(title)
      @metadata[DC.title] = title
    end

    # Get all objects from a service
    def self.all(uri)
    #def OtObject.all(uri)
      RestClientWrapper.get(uri,:accept => "text/uri-list").to_s.split(/\n/)
    end

    # Load metadata from URI
    def load_metadata
      #if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host))
        # TODO: fix metadata retrie
       #@metadata = YAML.load(RestClientWrapper.get(@uri, :accept => "application/x-yaml"))
      #else
        @metadata = Parser::Owl::Generic.new(@uri).metadata
      #end
      @metadata
      #Parser::Owl::Generic.new(@uri).metadata
    end

  end

  module Owl

    class Namespace

      def initialize(uri)
        @uri = uri
      end

      def [](property)
        @uri+property.to_s
      end

      def method_missing(property)
        @uri+property.to_s
      end

    end
  end

end
#
# OWL Namespaces
RDF = OpenTox::Owl::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
OWL = OpenTox::Owl::Namespace.new 'http://www.w3.org/2002/07/owl#'
DC =  OpenTox::Owl::Namespace.new 'http://purl.org/dc/elements/1.1/'
OT =  OpenTox::Owl::Namespace.new 'http://www.opentox.org/api/1.1#'
XSD = OpenTox::Owl::Namespace.new 'http://www.w3.org/2001/XMLSchema#'