Ejemplo n.º 1
0
 def _wm_change_cb(self, author, action, element=None, relation=None):
     if element is not None:
         self._publish_change(author, action, [utils.element2msg(element)])
     else:
         self._publish_change(author,
                              action,
                              relation=utils.relation2msg(relation))
Ejemplo n.º 2
0
 def _wm_query_rel_cb(self, msg):
     # TODO: get rid of this. Replace implementation with a standard SPARQL query
     to_ret = srvs.WmQueryRelationsResponse()
     with self._times:
         to_ret.matches = [utils.relation2msg(x) for x in self._ontology.get_relations(utils.msg2relation(msg.relation))]
     if self._verbose:
         log.info("[wmQueryRelation]", "Query: {} Answer: {}. Time: {:0.3f} secs".format(msg.relation, to_ret.matches, self._times.get_last()))
     return to_ret
Ejemplo n.º 3
0
 def set_relation(self, subj, pred, obj, value=True):
     msg = srvs.WmSetRelationRequest()
     msg.author = self._author_name + self._debug_info()
     msg.relation = utils.relation2msg(utils.makeRelation(subj, pred, obj))
     msg.value = value
     res = self._call(self._set_relations, msg)
     if (res):
         return res.ok
     return False
Ejemplo n.º 4
0
 def get_relations(self, subj, pred, obj):
     if pred != "" and subj != "" and obj != "" and subj != "-1" and obj != "-1":
         subj = self.get_element(subj)
         obj = self.get_element(obj)
         rels = self.get_reasoner_relations(subj, pred, obj)
         if rels is not None:
             return rels
         else:
             return subj.getRelations(pred=self.get_sub_properties(pred),
                                      obj=obj.id)
     msg = srvs.WmQueryRelationsRequest()
     msg.relation = utils.relation2msg(utils.makeRelation(subj, pred, obj))
     res = self._call(self._query_relations, msg)
     if (res):
         return [utils.msg2relation(x) for x in res.matches]
Ejemplo n.º 5
0
    def set_relation(self, subj, pred, obj, value=True):
        """
        @brief      Sets a relation.

        @param      subj   (string)The subj uri
        @param      pred   (string)The predicate uri
        @param      obj    (string)The object uri
        @param      value  (Bool) True set the relation, False removes
                           it

        @return     (bool) False on failure
        """
        msg = srvs.WmSetRelationRequest()
        msg.author = self._author_name + self._debug_info()
        msg.relation = utils.relation2msg(utils.makeRelation(subj, pred, obj))
        msg.value = value
        res = self._call(self._set_relations, msg)
        if (res):
            return res.ok
        return False
Ejemplo n.º 6
0
    def get_relations(self, subj, pred, obj):
        """
        @brief      Get all relations matchin the input.

        @param      subj  (string) The relation subject
        @param      pred  (string) The relation predicate
        @param      obj   (string) The relation object

        @return     A list of relations
        """
        if pred != "" and subj != "" and obj != "" and subj != "-1" and obj != "-1":
            subj = self.get_element(subj)
            obj = self.get_element(obj)
            rels = self.get_reasoner_relations(subj, pred, obj)
            if rels is not None:
                return rels
            else:
                return subj.getRelations(pred=self.get_sub_properties(pred), obj=obj.id)
        msg = srvs.WmQueryRelationsRequest()
        msg.relation = utils.relation2msg(utils.makeRelation(subj, pred, obj))
        res = self._call(self._query_relations, msg)
        if(res):
            return [utils.msg2relation(x) for x in res.matches]