Esempio n. 1
0
 def updateInternalStrength(self):
     if not (self.descriptor and self.relation):
         self.internalStrength = 0.0
         return
     averageDepth = (self.descriptor.conceptualDepth +
                     self.relation.conceptualDepth) / 2.0
     averageDepth **= 1.1
     # see if the object corresponds to an object
     # if so, see if the descriptor is present (modulo slippages) in the
     # corresponding object
     changedObjects = [o for o in workspace.initial.objects if o.changed]
     changed = changedObjects[0]
     sharedDescriptorTerm = 0.0
     if changed and changed.correspondence:
         targetObject = changed.correspondence.objectFromTarget
         slippages = workspace.slippages()
         slipnode = self.descriptor.applySlippages(slippages)
         if not targetObject.described(slipnode):
             self.internalStrength = 0.0
             return
         sharedDescriptorTerm = 100.0
     conceptual_height = (100.0 - self.descriptor.conceptualDepth) / 10.0
     sharedDescriptorWeight = conceptual_height ** 1.4
     depthDifference = 100.0 - abs(self.descriptor.conceptualDepth -
                                   self.relation.conceptualDepth)
     weights = ((depthDifference, 12),
                (averageDepth, 18),
                (sharedDescriptorTerm, sharedDescriptorWeight))
     self.internalStrength = weightedAverage(weights)
     if self.internalStrength > 100.0:
         self.internalStrength = 100.0
Esempio n. 2
0
 def updateInternalStrength(self):
     if not (self.descriptor and self.relation):
         self.internalStrength = 0.0
         return
     averageDepth = (self.descriptor.conceptualDepth +
                     self.relation.conceptualDepth) / 2.0
     averageDepth **= 1.1
     # see if the object corresponds to an object
     # if so, see if the descriptor is present (modulo slippages) in the
     # corresponding object
     changedObjects = [o for o in workspace.initial.objects if o.changed]
     changed = changedObjects[0]
     sharedDescriptorTerm = 0.0
     if changed and changed.correspondence:
         targetObject = changed.correspondence.objectFromTarget
         slippages = workspace.slippages()
         slipnode = self.descriptor.applySlippages(slippages)
         if not targetObject.hasDescription(slipnode):
             self.internalStrength = 0.0
             return
         sharedDescriptorTerm = 100.0
     sharedDescriptorWeight = ((100.0 - self.descriptor.conceptualDepth) /
                               10.0)**1.4
     depthDifference = 100.0 - abs(self.descriptor.conceptualDepth -
                                   self.relation.conceptualDepth)
     weights = ((depthDifference, 12), (averageDepth, 18),
                (sharedDescriptorTerm, sharedDescriptorWeight))
     self.internalStrength = weightedAverage(weights)
     if self.internalStrength > 100.0:
         self.internalStrength = 100.0
Esempio n. 3
0
 def buildTranslatedRule(self):
     slippages = workspace.slippages()
     self.category = self.category.applySlippages(slippages)
     self.facet = self.facet.applySlippages(slippages)
     self.descriptor = self.descriptor.applySlippages(slippages)
     self.relation = self.relation.applySlippages(slippages)
     # generate the final string
     self.finalAnswer = workspace.targetString
     changeds = [o for o in workspace.target.objects if
                 o.described(self.descriptor) and
                 o.described(self.category)]
     changed = changeds and changeds[0] or None
     logging.debug('changed object = %s', changed)
     if changed:
         left = changed.leftIndex
         startString = ''
         if left > 1:
             startString = self.finalAnswer[0: left - 1]
         right = changed.rightIndex
         middleString = self.__changeString(
             self.finalAnswer[left - 1: right])
         if not middleString:
             return False
         endString = ''
         if right < len(self.finalAnswer):
             endString = self.finalAnswer[right:]
         self.finalAnswer = startString + middleString + endString
     return True
Esempio n. 4
0
 def buildTranslatedRule(self):
     slippages = workspace.slippages()
     self.category = self.category.applySlippages(slippages)
     self.facet = self.facet.applySlippages(slippages)
     self.descriptor = self.descriptor.applySlippages(slippages)
     self.relation = self.relation.applySlippages(slippages)
     # generate the final string
     self.finalAnswer = workspace.targetString
     changeds = [
         o for o in workspace.target.objects
         if o.hasDescription(self.descriptor)
         and o.hasDescription(self.category)
     ]
     changed = changeds and changeds[0] or None
     logging.debug('changed object = %s' % changed)
     if changed:
         left = changed.leftStringPosition
         startString = ''
         if left > 1:
             startString = self.finalAnswer[0:left - 1]
         right = changed.rightStringPosition
         middleString = self.__changeString(self.finalAnswer[left -
                                                             1:right])
         if not middleString:
             return False
         endString = ''
         if right < len(self.finalAnswer):
             endString = self.finalAnswer[right:]
         self.finalAnswer = startString + middleString + endString
     return True