Skip to content

Commit

Permalink
Trac #19307: Improve statistic name and add collection name plural to…
Browse files Browse the repository at this point in the history
… FindStat interface

URL: http://trac.sagemath.org/19307
Reported by: stumpc5
Ticket author(s): Christian Stump
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager authored and vbraun committed Mar 20, 2016
2 parents ce839d2 + e94f996 commit b2d7828
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/sage/databases/findstat.py
Expand Up @@ -248,6 +248,7 @@ def increasing_tree_shape(elt, compare=min):
FINDSTAT_STATISTIC_COLLECTION = 'StatisticCollection'
FINDSTAT_STATISTIC_DATA = 'StatisticData'
FINDSTAT_STATISTIC_GENERATING_FUNCTION = 'StatisticGeneratingFunction'
FINDSTAT_STATISTIC_NAME = 'StatisticTitle'
FINDSTAT_STATISTIC_DESCRIPTION = 'StatisticDescription'
FINDSTAT_STATISTIC_REFERENCES = 'StatisticReferences'
FINDSTAT_STATISTIC_CODE = 'StatisticCode'
Expand Down Expand Up @@ -956,6 +957,7 @@ def _find_by_id(self):
raise

self._description = self._raw[FINDSTAT_STATISTIC_DESCRIPTION].encode("utf-8")
self._name = self._raw[FINDSTAT_STATISTIC_NAME].encode("utf-8")
self._references = self._raw[FINDSTAT_STATISTIC_REFERENCES].encode("utf-8")
self._collection = FindStatCollection(self._raw[FINDSTAT_STATISTIC_COLLECTION])
self._code = self._raw[FINDSTAT_STATISTIC_CODE]
Expand Down Expand Up @@ -1518,14 +1520,14 @@ def set_description(self, value):
sage: s = findstat([(d, randint(1,1000)) for d in DyckWords(4)]); s # optional -- internet
a new statistic on Cc0005: Dyck paths
sage: s.set_description("Random values on Dyck paths.\r\nNot for submssion.") # optional -- internet
sage: s.set_description("Random values on Dyck paths.\r\nNot for submission.") # optional -- internet
sage: s # optional -- internet
a new statistic on Cc0005: Dyck paths
sage: s.name() # optional -- internet
'Random values on Dyck paths.'
sage: print s.description() # optional -- internet
Random values on Dyck paths.
Not for submssion.
Not for submission.
"""
self._raise_error_modifying_statistic_with_perfect_match()

Expand All @@ -1547,7 +1549,11 @@ def name(self):
sage: findstat(1).name() # optional -- internet,random
u'The number of ways to write a permutation as a minimal length product of simple transpositions.'
"""
return self._description.partition(FINDSTAT_SEPARATOR_NAME)[0]
# this needs to be decided how to do properly
if hasattr(self,"_name"):
return self._name
else:
return self._description.partition(FINDSTAT_SEPARATOR_NAME)[0]

def references(self):
r"""
Expand Down Expand Up @@ -2159,21 +2165,34 @@ def _repr_(self):
"""
return "%s: %s" %(self.id_str(), self._name_plural)

def name(self):
def name(self, style="singular"):
r"""
Return the name of the FindStat collection.
INPUT:
- a string -- (default:"singular") can be
"singular", or "plural".
OUTPUT:
The name of the FindStat collection, in singular.
The name of the FindStat collection, in singular or in plural.
EXAMPLES::
sage: from sage.databases.findstat import FindStatCollection
sage: FindStatCollection("Binary trees").name() # optional -- internet
u'Binary tree'
sage: FindStatCollection("Binary trees").name(style="plural") # optional -- internet
u'Binary trees'
"""
return self._name
if style == "singular":
return self._name
elif style == "plural":
return self._name_plural
else:
raise ValueError("Argument 'style' (=%s) must be 'singular' or 'plural'."%style)

class FindStatCollections(Parent, UniqueRepresentation):
r"""
Expand Down

0 comments on commit b2d7828

Please sign in to comment.