Exemple #1
0
def rule_scout(codelet):
    assert workspace.numberOfUnreplacedObjects() == 0
    changedObjects = [o for o in workspace.initial.objects if o.changed]
    #assert len(changedObjects) < 2
    # if there are no changed objects, propose a rule with no changes
    if not changedObjects:
        return coderack.proposeRule(None, None, None, None, codelet)

    changed = changedObjects[-1]
    # generate a list of distinguishing descriptions for the first object
    # ie. string-position (left-,right-most,middle or whole) or letter category
    # if it is the only one of its type in the string
    objectList = []
    position = changed.getDescriptor(slipnet.stringPositionCategory)
    if position:
        objectList += [position]
    letter = changed.getDescriptor(slipnet.letterCategory)
    otherObjectsOfSameLetter = [o for o in workspace.initial.objects
                                if not o != changed
                                and o.getDescriptionType(letter)]
    if not len(otherObjectsOfSameLetter):
        objectList += [letter]
    # if this object corresponds to another object in the workspace
    # objectList = the union of this and the distingushing descriptors
    if changed.correspondence:
        targetObject = changed.correspondence.objectFromTarget
        newList = []
        slippages = workspace.slippages()
        for node in objectList:
            node = node.applySlippages(slippages)
            if targetObject.described(node):
                if targetObject.distinguishingDescriptor(node):
                    newList += [node]
        objectList = newList  # surely this should be +=
                              # "union of this and distinguishing descriptors"
    assert objectList and len(objectList)
    # use conceptual depth to choose a description
    valueList = []
    for node in objectList:
        depth = node.conceptualDepth
        value = formulas.temperatureAdjustedValue(depth)
        valueList += [value]
    i = formulas.selectListPosition(valueList)
    descriptor = objectList[i]
    # choose the relation (change the letmost object to "successor" or "d"
    objectList = []
    if changed.replacement.relation:
        objectList += [changed.replacement.relation]
    objectList += [changed.replacement.objectFromModified.getDescriptor(
        slipnet.letterCategory)]
    # use conceptual depth to choose a relation
    valueList = []
    for node in objectList:
        depth = node.conceptualDepth
        value = formulas.temperatureAdjustedValue(depth)
        valueList += [value]
    i = formulas.selectListPosition(valueList)
    relation = objectList[i]
    coderack.proposeRule(slipnet.letterCategory, descriptor,
                         slipnet.letter, relation, codelet)
Exemple #2
0
def rule_scout(codelet):
    assert workspace.numberOfUnreplacedObjects() == 0
    changedObjects = [o for o in workspace.initial.objects if o.changed]
    # assert len(changedObjects) < 2
    # if there are no changed objects, propose a rule with no changes
    if not changedObjects:
        return coderack.proposeRule(None, None, None, None, codelet)

    changed = changedObjects[-1]
    # generate a list of distinguishing descriptions for the first object
    # ie. string-position (left-,right-most,middle or whole) or letter category
    # if it is the only one of its type in the string
    objectList = []
    position = changed.getDescriptor(slipnet.stringPositionCategory)
    if position:
        objectList += [position]
    letter = changed.getDescriptor(slipnet.letterCategory)
    otherObjectsOfSameLetter = [o for o in workspace.initial.objects
                                if not o != changed and
                                o.getDescriptionType(letter)]
    if not len(otherObjectsOfSameLetter):
        objectList += [letter]
    # if this object corresponds to another object in the workspace
    # objectList = the union of this and the distingushing descriptors
    if changed.correspondence:
        targetObject = changed.correspondence.objectFromTarget
        newList = []
        slippages = workspace.slippages()
        for node in objectList:
            node = node.applySlippages(slippages)
            if targetObject.described(node):
                if targetObject.distinguishingDescriptor(node):
                    newList += [node]
        objectList = newList  # should this be += ??
    assert objectList
    # use conceptual depth to choose a description
    valueList = []
    for node in objectList:
        depth = node.conceptualDepth
        value = formulas.temperatureAdjustedValue(depth)
        valueList += [value]
    i = formulas.selectListPosition(valueList)
    descriptor = objectList[i]
    # choose the relation (change the letmost object to "successor" or "d"
    objectList = []
    if changed.replacement.relation:
        objectList += [changed.replacement.relation]
    objectList += [changed.replacement.objectFromModified.getDescriptor(
        slipnet.letterCategory)]
    # use conceptual depth to choose a relation
    valueList = []
    for node in objectList:
        depth = node.conceptualDepth
        value = formulas.temperatureAdjustedValue(depth)
        valueList += [value]
    i = formulas.selectListPosition(valueList)
    relation = objectList[i]
    coderack.proposeRule(slipnet.letterCategory, descriptor,
                         slipnet.letter, relation, codelet)
Exemple #3
0
def important_object_correspondence_scout(codelet):
    objectFromInitial = chooseUnmodifiedObject('relativeImportance',
                                               workspace.initial.objects)
    descriptors = objectFromInitial.relevantDistinguishingDescriptors()
    slipnode = formulas.chooseSlipnodeByConceptualDepth(descriptors)
    assert slipnode
    initialDescriptor = slipnode
    for mapping in workspace.slippages():
        if mapping.initialDescriptor == slipnode:
            initialDescriptor = mapping.targetDescriptor
    targetCandidates = []
    for objekt in workspace.target.objects:
        for description in objekt.relevantDescriptions():
            if description.descriptor == initialDescriptor:
                targetCandidates += [objekt]
    assert targetCandidates
    objectFromTarget = chooseUnmodifiedObject('interStringSalience',
                                              targetCandidates)
    assert objectFromInitial.spansString() == objectFromTarget.spansString()
    # get the posible concept mappings
    conceptMappings = formulas.getMappings(
        objectFromInitial, objectFromTarget,
        objectFromInitial.relevantDescriptions(),
        objectFromTarget.relevantDescriptions())
    assert conceptMappings
    assert __slippability(conceptMappings)
    # find out if any are distinguishing
    distinguishingMappings = [m for m in conceptMappings if m.distinguishing()]
    assert distinguishingMappings
    # if both objects span the strings, check to see if the
    # string description needs to be flipped
    opposites = [
        m for m in distinguishingMappings
        if m.initialDescriptionType == slipnet.stringPositionCategory and
        m.initialDescriptionType != slipnet.bondFacet]
    initialDescriptionTypes = [m.initialDescriptionType for m in opposites]
    flipTargetObject = False
    if (objectFromInitial.spansString() and
            objectFromTarget.spansString() and
            slipnet.directionCategory in initialDescriptionTypes and
            __allOppositeMappings(formulas.oppositeMappings) and
            slipnet.opposite.activation != 100.0):
        objectFromTarget = objectFromTarget.flippedVersion()
        conceptMappings = formulas.getMappings(
            objectFromInitial, objectFromTarget,
            objectFromInitial.relevantDescriptions(),
            objectFromTarget.relevantDescriptions())
        flipTargetObject = True
    coderack.proposeCorrespondence(objectFromInitial, objectFromTarget,
                                   conceptMappings, flipTargetObject, codelet)