Simpler returns
This commit is contained in:
@ -6,3 +6,5 @@ An implementation of the [Douglas Hofstadter](http://prelectur.stanford.edu/lect
|
||||
This implementation is a copycat of Scott Boland's [Java implementation](http://itee.uq.edu.au/~scottb/_Copycat/), but re-written into Python. It's not a direct translation - but based on his code. I did not carry over the GUI, as this version can more usefully be run from command line, or imported for use by other Python scripts.
|
||||
|
||||
In cases where I could not grok the Java implementation easily or directly I took ideas from the [LISP implementation](http://web.cecs.pdx.edu/~mm/how-to-get-copycat.html), or directly from [Melanie Mitchell](https://en.wikipedia.org/wiki/Melanie_Mitchell)'s "[Analogy-Making as Perception](http://www.amazon.com/Analogy-Making-Perception-Computer-Melanie-Mitchell/dp/0262132893/ref=tmm_hrd_title_0?ie=UTF8&qid=1351269085&sr=1-3)"
|
||||
|
||||
I also tried to make the code more pythonic.
|
||||
|
||||
@ -16,9 +16,7 @@ class ConceptMapping(object):
|
||||
return '<ConceptMapping: %s from %s to %s>' % (self.__str__(), self.initialDescriptor, self.targetDescriptor)
|
||||
|
||||
def __str__(self):
|
||||
if self.label:
|
||||
return self.label.name
|
||||
return 'anonymous'
|
||||
return self.label and self.label.name or 'anonymous'
|
||||
|
||||
def slipability(self):
|
||||
association = self.__degreeOfAssociation()
|
||||
@ -51,9 +49,7 @@ class ConceptMapping(object):
|
||||
return False
|
||||
if not self.initialObject.distinguishingDescriptor(self.initialDescriptor):
|
||||
return False
|
||||
if not self.targetObject.distinguishingDescriptor(self.targetDescriptor):
|
||||
return False
|
||||
return True
|
||||
return self.targetObject.distinguishingDescriptor(self.targetDescriptor)
|
||||
|
||||
def sameInitialType(self, other):
|
||||
return self.initialDescriptionType == other.initialDescriptionType
|
||||
@ -80,16 +76,10 @@ class ConceptMapping(object):
|
||||
return self.sameTypes(other) and self.sameInitialDescriptor(other)
|
||||
|
||||
def isContainedBy(self, mappings):
|
||||
for mapping in mappings:
|
||||
if self.sameKind(mapping):
|
||||
return True
|
||||
return False
|
||||
return any([self.sameKind(mapping) for mapping in mappings])
|
||||
|
||||
def isNearlyContainedBy(self, mappings):
|
||||
for mapping in mappings:
|
||||
if self.nearlySameKind(mapping):
|
||||
return True
|
||||
return False
|
||||
return any([self.nearlySameKind(mapping) for mapping in mappings])
|
||||
|
||||
def related(self, other):
|
||||
if self.initialDescriptor.related(other.initialDescriptor):
|
||||
@ -108,9 +98,7 @@ class ConceptMapping(object):
|
||||
return False
|
||||
if not self.label or not other.label:
|
||||
return False
|
||||
if self.label != other.label:
|
||||
return True
|
||||
return False
|
||||
return self.label != other.label
|
||||
|
||||
def supports(self, other):
|
||||
# Concept-mappings (a -> b) and (c -> d) support each other if a is related
|
||||
@ -130,9 +118,7 @@ class ConceptMapping(object):
|
||||
return False
|
||||
if not self.label or not other.label:
|
||||
return False
|
||||
if self.label == other.label:
|
||||
return True
|
||||
return False
|
||||
return self.label == other.label
|
||||
|
||||
def relevant(self):
|
||||
return self.initialDescriptionType.fully_active() and self.targetDescriptionType.fully_active()
|
||||
|
||||
Reference in New Issue
Block a user