class COEUS::COEUS

Public Class Methods

delete(sub, pred, obj) click to toggle source

This method uses COEUS API to get delete triples based on provided parameters. Note: Requires that the API key is previously defined

Parameters

  • sub - the triple subject to delete

  • pred - the triple predicate to delete

  • obj - the riple object to delete

# File lib/coeus.rb, line 155
def self.delete(sub, pred, obj)
        if @key == ''
                raise '[COEUS] undefined API key'
        else
               content = URI.parse(@host + 'api/' + @key + '/delete/' + sub + '/' + pred + '/' + obj).read
               result = JSON.parse(content)
               if result['status'] != 100
                       raise '[COEUS] unable to delete triple: ' + result['message']
               else
                       return true
               end
       end
end
get_host() click to toggle source
# File lib/coeus.rb, line 43
def self.get_host
        @host
end
get_key() click to toggle source
# File lib/coeus.rb, line 65
def self.get_key
        @key
end
host(host) click to toggle source

This method defines the base COEUS host for the next actions

Parameters

  • host - the new host settings

Default

# File lib/coeus.rb, line 29
def self.host(host)
        # verify if valid HTTP URL
        if host.start_with?('http')
                @host = host

                # add final slash (/) if not available
                if !@host.end_with?('/')
                        @host += '/'
                end
        else
                raise '[COEUS] Invalid host URL'
        end
end
key(key) click to toggle source

This method defines the COEUS seed API key

Parameters

  • key - the COEUS API key

Default

  • uavr

# File lib/coeus.rb, line 61
def self.key(key)
        @key = key
end
print() click to toggle source
query(query) click to toggle source

This method performs a SPARQL query on the COEUS endpoint

Parameters

  • query - the complete SPARQL query (including prefixes)

# File lib/coeus.rb, line 91
def self.query(query)
        sparql = SPARQL::Client.new(@host + 'sparql')
        return sparql.query(query)
end
triple(sub, pred, obj) click to toggle source

This method uses COEUS API to get match triples based on provided parameters

Parameters

  • sub - the triple set subject

  • pred - the triple set predicate

  • obj - the triple set object

# File lib/coeus.rb, line 78
def self.triple(sub, pred, obj)
        content = URI.parse(@host + 'api/triple/' + sub + '/' + pred + '/' + obj + '/js').read
        return JSON.parse(content)['results']['bindings']
end
update(sub, pred, old_obj, new_obj) click to toggle source

This method uses COEUS API to get update existing triples based on provided parameters. Note: Requires that the API key is previously defined

Parameters

  • sub - the triple subject

  • pred - the triple predicate

  • old_obj - the old triple object

  • new_obj - the new triple object

# File lib/coeus.rb, line 131
def self.update(sub, pred, old_obj, new_obj)
        if @key == ''
                raise '[COEUS] undefined API key'
        else
               content = URI.parse(@host + 'api/' + @key + '/update/' + sub + '/' + pred + '/' + old_obj + ',' + new_obj).read
               result = JSON.parse(content)
               if result['status'] != 100
                       raise '[COEUS] unable to update triple: ' + result['message']
               else
                       return true
               end
       end
end
write(sub, pred, obj) click to toggle source

This method uses COEUS API to get write new triples based on provided parameters. Note: Requires that the API key is previously defined

Parameters

  • sub - the new triple subject

  • pred - the new triple predicate

  • obj - the new riple object

# File lib/coeus.rb, line 106
def self.write(sub, pred, obj)
        if @key == ''
                raise '[COEUS] undefined API key'
        else
               content = URI.parse(@host + 'api/' + @key + '/write/' + sub + '/' + pred + '/' + obj).read
               result = JSON.parse(content)
               if result['status'] != 100
                       raise '[COEUS] unable to store triple: ' + result['message']
               else
                       return true
               end
       end
end