Ejemplo n.º 1
0
def remove_objective_grounding(objective, tbox, abox):
    """Given an objective individual,
       removes the grounded hierarchy (fg tree) that solves it.
    """
    fg = abox.search_one(solvesO=objective)
    if fg:
        destroy_entity(fg)
Ejemplo n.º 2
0
 def updateObjectiveStatus(self, diagnostic_status):
     function_type = self.onto.search_one(
         iri="*{}".format(diagnostic_status.name))
     return_value = "NONE"
     if function_type != None:
         objectives = self.search_objectives()
         old_fg = self.onto.search_one(solvesO=objectives[0])
         o = objectives[0]
         if not (o.typeF == function_type):
             # if movement direction diferent from current direction, change objective
             destroy_entity(o)
             destroy_entity(old_fg)
             # create new objective
             obj_navigate = self.get_new_tomasys_objective(
                 "o_" + function_type.name.replace('f_', ''),
                 "*" + function_type.name)
             fd = obtainBestFunctionDesign(obj_navigate, self.tomasys)
             self.grounded_configuration = self.set_new_grounding(
                 fd, obj_navigate)
             rospy.loginfo(
                 "\n\nNew objective created to solve function: {0}, FG:{1}".
                 format(
                     function_type.name,
                     self.onto.search(type=self.tomasys.FunctionGrounding)))
             return_value = fd  #need reconfig
     return return_value
Ejemplo n.º 3
0
def destroy_all(cls):
    """Destroy all instances of given class.

    Args:
        cls (class): ontology class
    """
    for i in cls.instances():
        destroy_entity(i)
Ejemplo n.º 4
0
    def delete_object(self, obj: Any):
        """
        Deletes the object from the ontology.

        Parameters
        ----------
        obj  the object to be deleted
        """
        ow.destroy_entity(obj)
Ejemplo n.º 5
0
 def remove_objective(self, objective_id):
     # Checks if there are previously defined objectives.
     old_objective = self.onto.search_one(iri="*{}".format(objective_id))
     if old_objective:
         old_fg_instance = self.onto.search_one(solvesO=old_objective)
         with self.ontology_lock:
             destroy_entity(old_fg_instance)
             destroy_entity(old_objective)
         return True
     else:
         return False
Ejemplo n.º 6
0
    def delete_instance(self, class_name, instance_name):
        onto_file = self.ontology
        onto_class = self.ontology[class_name]

        try:
            new_instance = onto_class(instance_name, namespace=onto_file)
            destroy_entity(new_instance)
            onto_file.save(self.path)
            self.load()
        except BaseException:
            pass
Ejemplo n.º 7
0
    def add_instance(self, payload):
        class_name = payload['class_name']
        instance_name = payload['instance_name']
        property_name = payload['property_name']
        property_values = payload['property_values']

        onto_file = self.ontology
        onto_class = self.ontology[class_name]
        onto_property = self.ontology[property_name]

        try:
            new_instance = onto_class(instance_name, namespace=onto_file)
            destroy_entity(new_instance)
            new_instance = onto_class(instance_name, namespace=onto_file)
            for value in property_values:
                onto_value = self.ontology[value]
                new_instance.is_a.append(onto_property.some(onto_value))
            onto_file.save(self.path)
            self.load()
        except BaseException:
            pass
Ejemplo n.º 8
0
def pre_reasoner(onto):
    for i in onto.individuals():
        if i.AvailableBikes == i.AvailableBikeStands == [0]:
            destroy_entity(i)
Ejemplo n.º 9
0
 def destroy_class(class_identifier):
     destroy_entity(class_identifier)
Ejemplo n.º 10
0
def cleanup(onto: Ontology):
    onto.implementation.graph.destroy()
    for e in GENERATED_TYPES:
        destroy_entity(GENERATED_TYPES[e])
    GENERATED_TYPES.clear()
Ejemplo n.º 11
0
    class Hydrogen(emmo.Atom):
        pass

    class Oxygen(emmo.Atom):
        pass

    class H2O(emmo.Molecule):
        """Water molecule."""
        emmo.hasSpatialDirectPart.exactly(2, Hydrogen)
        emmo.hasSpatialDirectPart.exactly(1, Oxygen)

    # Create some
    H1 = Hydrogen()
    H2 = Hydrogen()
    O = Oxygen()  # noqa: E741
    w = H2O()
    w.hasSpatialDirectPart = [H1, H2, O]

onto.sync_attributes(name_policy='sequential', name_prefix='myonto_')
assert onto.base_iri + 'myonto_0' in onto
assert onto.base_iri + 'myonto_6' in onto

onto.sync_attributes(name_policy='uuid', name_prefix='onto_')
assert w.name.startswith('onto_')
assert len(w.name) == 5 + 36

# Remove all traces of onto such that they do not mess up other tests
# when running pytest
for e in itertools.chain(onto.classes(), onto.individuals()):
    owlready2.destroy_entity(e)
Ejemplo n.º 12
0
def remove_instruments(ontology):
    print("removing instruments")
    instruments = ontology.search(type=ontology.Instrument)
    for instrument in instruments:
        owl.destroy_entity(instrument)