Added "extract" argument to "get_top_terms" method
authorThierry Florac <thierry.florac@onf.fr>
Tue, 30 Jun 2015 14:19:52 +0200
changeset 7 6a22cec2899b
parent 6 9f3987a2dd72
child 8 2064d2a24a70
Added "extract" argument to "get_top_terms" method
src/pyams_thesaurus/interfaces/thesaurus.py
src/pyams_thesaurus/thesaurus.py
--- a/src/pyams_thesaurus/interfaces/thesaurus.py	Wed Jun 17 10:01:13 2015 +0200
+++ b/src/pyams_thesaurus/interfaces/thesaurus.py	Tue Jun 30 14:19:52 2015 +0200
@@ -90,6 +90,9 @@
     def reset_terms_parent(self):
         """Reset thesaurus terms parent attribute"""
 
+    def get_top_terms(self, extract=None):
+        """Get top terms, for given extract or for the whole thesaurus"""
+
     def reset_top_terms(self):
         """Reset thesaurus top terms"""
 
--- a/src/pyams_thesaurus/thesaurus.py	Wed Jun 17 10:01:13 2015 +0200
+++ b/src/pyams_thesaurus/thesaurus.py	Tue Jun 30 14:19:52 2015 +0200
@@ -115,7 +115,6 @@
         self.reset_terms_parent()
         self.reset_top_terms()
 
-    @property
     def sublocations(self):
         return self.terms, self.catalog
 
@@ -128,7 +127,9 @@
         self._top_terms = [term for term in value or () if term.usage is None]
 
     def init_catalog(self):
+        # Init catalog
         catalog = self.catalog = Catalog()
+        locate(catalog, self)
         # Init fulltext search catalog
         catalog['fulltext'] = TextIndexWithInterface(IThesaurusTerm, 'label', language=self.language)
         # Init stemmed search catalog
@@ -202,6 +203,11 @@
         self.top_terms = [term for term in self.terms.values()
                           if (not term.generic) and (not term.usage)]
 
+    def get_top_terms(self, extract=None):
+        if extract is None:
+            return self.top_terms
+        return [term for term in self.top_terms if extract in term.extracts]
+
     def clear(self):
         self.terms.clear()
         self.catalog.reset()