icsemantic.catalog.indexes.utils

Package platecom :: Package ontocatalog :: Package indexes :: Module utils |
[hide private]
[frames] | no frames]

# Source Code for Module icsemantic.catalog.indexes.utils

     1  """A few common pieces of code used in the catalog indexes in this
     2  package are grouped into functions in this module to make its reuse
     3  easier.
     4  """
     5
     6  from BTrees.IIBTree import IITreeSet, IISet, intersection, union
     7  from Products.CMFCore.utils import getToolByName
     8
     9  from platecom.ontoplone.interfaces.IThesaurus import IThesaurus
    10
    11
    12 -def get_equivalent(portal, k, lang=None):
    13      """Query the local thesaurus for equivalent concepts"""
    14      try:
    15          r = thesaurus_utility(portal).get_equivalent(k, lang, exclude=True)
    16      except IndexError:
    17          r = []
    18      return r
    19
    20
    21 -def get_related(portal, k, lang=None, context=None):
    22      """Query the local thesaurus for related concepts"""
    23      try:
    24          r = thesaurus_utility(portal).get_related(k, lang, context)
    25      except IndexError:
    26          r = []
    27      return r
    28
    29
    30 -def thesaurus_utility(context):
    31      """Return the local utility for the thesaurus"""
    32      portal = getToolByName(context, 'portal_url').getPortalObject()
    33      sm = portal.getSiteManager()
    34      return sm.utilities.queryUtility(IThesaurus)
    35
    36
    37 -def build_catalog_results(id, catalog, catalog_results):
    38      """Build a catalog result simulate an internal catalog result"""
    39      paths = [i.getPath() for i in catalog_results]
    40
    41      results = []
    42      for p in paths:
    43          rid = catalog.hasuid(p)
    44          if rid is not None:
    45              results.append(rid)
    46
    47      return (IISet(tuple(results)), (id,))
    48