Ejemplo n.º 1
0
 def toElement(self):
     to_ret = Element(self._type)
     to_ret._label = self._label
     for _, p in self.params.items():
         if p.dataTypeIs(Element):
             to_ret.addRelation(self, "skiros:hasParam", p.toElement())
     for c in self._pre_conditions:
         to_ret.addRelation(self, "skiros:hasPreCondition", c.toElement())
     for c in self._hold_conditions:
         to_ret.addRelation(self, "skiros:hasHoldCondition", c.toElement())
     for c in self._post_conditions:
         to_ret.addRelation(self, "skiros:hasPostCondition", c.toElement())
     return to_ret
Ejemplo n.º 2
0
    def get_individual(self, name, context_id=""):
        """
        @brief Builds an element from an individual

        @param context_id if defined look for the individual only in the context
        """
        subject = self.lightstring2uri(name)
        if not self.uri_exists(subject, context_id):
            raise Exception(
                "Element {} doesn't exist in ontology. Uri: {}. Context: {}.".
                format(name, subject, context_id))
        e = Element()
        for predicate, obj in self.ontology(context_id).predicate_objects(
                subject):
            if OWL.DatatypeProperty in self.ontology().objects(
                    predicate, RDF.type) or predicate == RDFS.comment:
                e.setProperty(self.uri2lightstring(predicate),
                              obj.value,
                              self.uri2lightstring(obj.datatype),
                              force_convertion=True)
            elif OWL.ObjectProperty in self.ontology().objects(
                    predicate, RDF.type):
                e.addRelation("-1", self.uri2lightstring(predicate),
                              self.uri2lightstring(obj))
            elif predicate == RDF.type and obj != OWL.NamedIndividual:
                e._type = self.uri2lightstring(str(obj))
            elif obj == OWL.NamedIndividual:
                pass
            elif predicate == RDFS.label:
                e._label = obj.value
            else:
                log.error(
                    "[get_individual]",
                    "Ignoring {}-{}-{}. Predicate is not defined in the ontology."
                    .format(name, self.uri2lightstring(predicate),
                            self.uri2lightstring(obj)))
        for subj, predicate in self.ontology(context_id).subject_predicates(
                subject):
            if (self.uri2lightstring(predicate) != "skiros:hasTemplate"):
                e.addRelation(self.uri2lightstring(subj),
                              self.uri2lightstring(predicate), "-1")
        self._add_reasoners_prop(e)
        return e