#
# -*- coding: utf-8 -*-


#-----------------------------------------------------------------------------------------------------------
#   Enable globals:
try:
    g
except NameError:
    import os.path as _p; import inspect as _i
    pathToScript = _p.pardir, 'lib', 'biocase', 'fundamentals.py'
    execfile( _p.join( _p.dirname( _i.getfile( lambda:None ) ), *pathToScript ) )


############################################################################################################
#
#   YELLOW PAGES
#
#===========================================================================================================
from __future__ import division
#-----------------------------------------------------------------------------------------------------------
u                                       = g.configtool.utilities
#-----------------------------------------------------------------------------------------------------------
_feds                                   = u.feds
_Ratingscalculator                      = u.tempratingsweb.Ratingscalculator.Ratingscalculator
#-----------------------------------------------------------------------------------------------------------

#=======================================================================================================
def rate( query ):
    groveFed        = _feds.resolve( 'Grove', readonly = True )
    dsGrove         = groveFed.dsGrove
    topicGraphname  = 'bion'
    focusGraphname  = 'abcd12'
    linenr          = 0
    rc              = _Ratingscalculator( query, topicGraphname, focusGraphname )
    ratings         = rc.getRatings()
    #---------------------------------------------------------------------------------------------------
    print sep0
    print rc.query
    print sep2
    print rc.report
    print sep1
    #---------------------------------------------------------------------------------------------------
    for rating, focusTermnr in ratings:
        linenr += 1
        if linenr > 50: break
        numeronym   = ':%s:%s' % ( focusGraphname, focusTermnr, )
        nodefact    = dsGrove.nodefactForOntonym( numeronym )
        nomonym     = nodefact.ontonym
        print '%3d %6.3f %s' % ( linenr, rating, nomonym, )


############################################################################################################
#
#
#
#===========================================================================================================
if __name__ == '__main__':

    import sys; sys.setrecursionlimit(50)
    sep0 = '#' * 108
    sep1 = '=' * 108
    sep2 = '-' * 108


    rate( """digital """ )
    rate( """norm digital """ )
    rate( """norm( norm digital and norm image )""" )
    rate( """norm( fungi and plants )""" )
    rate( """norm( norm bot* and not ( norm zoo* ) )""" )
    #rate( """norm( norm bot* and not norm zoo*)""" )

