Пример #1
0
def generate_chosen_concepts(lang):
    """  """
    # card[Exists(at,Not({roomb}))] 4    C1
    # card[Exists(carry,<universe>)] 2   C2
    # bool[Exists(at-robby,{roomb})] 3   RX
    # card[Exists(gripper,Exists(at-robby,{roomb}))] 5   (intermediate)
    # card[Exists(carry,Exists(gripper,Exists(at-robby,{roomb})))] 7

    obj_t = lang.Object
    block_t = lang.get('block')

    handempty = NullaryAtom(lang.get("handempty"))
    on = PrimitiveRole(lang.get("on"))
    on_g = GoalRole(lang.get("on"))
    ontable = PrimitiveConcept(lang.get("ontable"))
    clear = PrimitiveConcept(lang.get("clear"))
    block = PrimitiveConcept(lang.get("block"))

    on_g_on = EqualConcept(on_g, on, 'block')
    M_t = AndConcept(on_g_on, ontable, 'block')
    W = ForallConcept(on_g, ForallConcept(StarRole(on_g), on_g_on))
    M_t_inv = AndConcept(NotConcept(W, obj_t), NotConcept(ontable, obj_t), 'block')

    concepts = [M_t, W, M_t_inv]
    return [], concepts, []  # atoms, concepts, roles
Пример #2
0
def generate_chosen_concepts_without_nominal(lang):
    """  """
    # card[Exists(at,Not({roomb}))] 4    C1
    # card[Exists(carry,<universe>)] 2   C2
    # bool[Exists(at-robby,{roomb})] 3   RX
    # card[Exists(gripper,Exists(at-robby,{roomb}))] 5   (intermediate)
    # card[Exists(carry,Exists(gripper,Exists(at-robby,{roomb})))] 7

    obj_t = lang.Object

    universal = UniversalConcept("object")

    at = PrimitiveRole(lang.get("at"))
    at_g = GoalRole(lang.get("at"))
    carry = PrimitiveRole(lang.get("carry"))
    at_robby = PrimitiveRole(lang.get("at-robby"))
    gripper = PrimitiveRole(lang.get("gripper"))
    at_g_at = EqualConcept(at_g, at, 'object')

    nominal_subst = ExistsConcept(InverseRole(at_g), universal)
    g1 = ExistsConcept(at, NotConcept(nominal_subst, obj_t))
    g2 = ExistsConcept(carry, UniversalConcept("object"))
    g3 = ExistsConcept(
        carry, ExistsConcept(gripper, ExistsConcept(at_robby, nominal_subst)))
    g4 = ExistsConcept(
        at_robby,
        AndConcept(NotConcept(nominal_subst, obj_t),
                   ExistsConcept(InverseRole(at), universal), 'object'))

    concepts = [nominal_subst, g1, g2, g3, g4]
    return [], concepts, []  # atoms, concepts, roles
Пример #3
0
def generate_chosen_concepts(lang):
    """  """

    obj_t = lang.Object

    passenger = PrimitiveConcept(lang.get("passenger"))
    lift_at = PrimitiveConcept(lang.get("lift-at"))
    boarded = PrimitiveConcept(lang.get("boarded"))
    served = PrimitiveConcept(lang.get("served"))

    origin = PrimitiveRole(lang.get("origin"))
    destin = PrimitiveRole(lang.get("destin"))

    # M1 = AndConcept(NotConcept(boarded, obj_t), NotConcept(served, obj_t),
    #                 "object")
    # M2 = AndConcept(boarded, NotConcept(served, obj_t), "object") # K(m2) = 4
    M3 = ExistsConcept(origin, lift_at)
    M4 = ExistsConcept(destin, lift_at)  # K(M4) = 3

    # F1 = AndConcept(M1, M3, "object")
    # F2 = AndConcept(M1, NotConcept(M3, obj_t), "object")
    # F3 = AndConcept(M2, M4, "object")
    # F4 = AndConcept(M2, NotConcept(M4, obj_t), "object")

    not_boarded_nor_served = AndConcept(NotConcept(boarded, obj_t),
                                        NotConcept(served, obj_t), "object")

    F1 = AndConcept(passenger, served, "object")
    F2 = AndConcept(passenger, AndConcept(boarded, M4, "object"), "object")
    F3 = AndConcept(
        passenger,
        AndConcept(boarded, ForallConcept(destin, NotConcept(lift_at, obj_t)),
                   "object"), "object")
    F4 = AndConcept(passenger, AndConcept(not_boarded_nor_served, M3,
                                          "object"), "object")
    F5 = AndConcept(
        passenger,
        AndConcept(not_boarded_nor_served,
                   ForallConcept(origin, NotConcept(lift_at, obj_t)),
                   "object"), "object")

    return [], [F1, F2, F3, F4, F5], []  # atoms, concepts, roles
Пример #4
0
def build_expected_features(lang):
    obj_t = lang.Object

    visited = PrimitiveConcept(lang.get("visited"))
    unvisited = NotConcept(visited, obj_t)
    return [
        ConceptCardinalityFeature(unvisited),
        ConceptCardinalityFeature(visited),
        MinDistanceFeature(PrimitiveConcept(lang.get("at-robot")),
                           PrimitiveRole(lang.get("connected")), unvisited),
    ]
Пример #5
0
def generate_chosen_concepts(lang):
    """  """
    # card[Exists(at,Not({roomb}))] 4    C1
    # card[Exists(carry,<universe>)] 2   C2
    # bool[Exists(at-robby,{roomb})] 3   RX
    # card[Exists(gripper,Exists(at-robby,{roomb}))] 5   (intermediate)
    # card[Exists(carry,Exists(gripper,Exists(at-robby,{roomb})))] 7

    obj_t = lang.Object

    at = PrimitiveRole(lang.get("at"))
    carry = PrimitiveRole(lang.get("carry"))
    at_robby = PrimitiveRole(lang.get("at-robby"))
    gripper = PrimitiveRole(lang.get("gripper"))
    x_param = NominalConcept("roomb", obj_t)
    c1 = ExistsConcept(at, NotConcept(x_param, obj_t))
    c2 = ExistsConcept(carry, UniversalConcept("object"))
    rx = ExistsConcept(at_robby, x_param)
    c3 = ExistsConcept(gripper, rx)
    c4 = ExistsConcept(carry, c3)

    concepts = [c1, c2, c3, c4]
    return [], concepts, []  # atoms, concepts, roles
Пример #6
0
def build_concept(language, node):
    if isinstance(node, str):  # Must be a primitive symbol or universe / empty
        if node == "<universe>":
            return UniversalConcept('object')
        if node == "<empty>":
            return EmptyConcept('object')

        is_goal = False
        if node[-2:] == "_g":
            # We have a goal concept / role
            # (yes, this will fail miserably if some primitive in the original domain is named ending with _g)
            is_goal = True
            node = node[:-2]

        obj = language.get(node)
        assert isinstance(obj, (Predicate, Function, Sort))
        arity = 1 if isinstance(obj, Sort) else obj.uniform_arity()
        assert arity in (1, 2)
        if is_goal:
            return GoalConcept(obj) if arity == 1 else GoalRole(obj)
        else:
            return PrimitiveConcept(obj) if arity == 1 else PrimitiveRole(obj)

    elif node.name == "Nominal":
        assert len(node.children) == 1
        return NominalConcept(node.children[0], language.Object)

    elif node.name == "Not":
        assert len(node.children) == 1
        return NotConcept(build_concept(language, node.children[0]),
                          language.Object)

    elif node.name == "Inverse":
        assert len(node.children) == 1
        return InverseRole(build_concept(language, node.children[0]))

    elif node.name == "And":
        assert len(node.children) == 2
        return AndConcept(build_concept(language, node.children[0]),
                          build_concept(language, node.children[1]), 'object')

    elif node.name == "Exists":
        assert len(node.children) == 2
        role = build_concept(language, node.children[0])
        concept = build_concept(language, node.children[1])
        return ExistsConcept(role, concept)

    elif node.name == "Forall":
        assert len(node.children) == 2
        role = build_concept(language, node.children[0])
        concept = build_concept(language, node.children[1])
        return ForallConcept(role, concept)

    elif node.name == "Restrict":
        assert len(node.children) == 2
        role = build_concept(language, node.children[0])
        concept = build_concept(language, node.children[1])
        return RestrictRole(role, concept)

    elif node.name == "Equal":
        assert len(node.children) == 2
        r1 = build_concept(language, node.children[0])
        r2 = build_concept(language, node.children[1])
        return EqualConcept(r1, r2, 'object')

    elif node.name == "Star":
        assert len(node.children) == 1
        r1 = build_concept(language, node.children[0])
        return StarRole(r1)

    elif node.name == "RoleDifference":
        assert False
        assert len(node.children) == 2
        r1 = build_concept(language, node.children[0])
        r2 = build_concept(language, node.children[1])
        return RoleDifference(r1, r2)

    else:
        raise RuntimeError(
            "Don't know how to deserialize concept / feature: {}".format(node))