Exemple #1
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
Exemple #2
0
 def get_relations(self, r):
     to_ret = []
     predicates = self.context.predicates(self.lightstring2uri(r['src']),
                                          self.lightstring2uri(r['dst']))
     ptypes = self.get_sub_properties(r['type'])
     for p in predicates:
         p = self.uri2lightstring(p)
         if p in ptypes:
             to_ret.append(utils.makeRelation(r['src'], p, r['dst']))
     return to_ret
Exemple #3
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]
Exemple #4
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
Exemple #5
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]