# HG changeset patch # User Thierry Florac # Date 1437578521 -7200 # Node ID 65193a93dd6a47d5a8bc895a209ef683e432e8f1 # Parent bfd9acbe4224f57491c2722b72ff9ffbfc3d14fb Added JSON-RPC methods diff -r bfd9acbe4224 -r 65193a93dd6a src/pyams_thesaurus/rpc/json/__init__.py --- a/src/pyams_thesaurus/rpc/json/__init__.py Tue Jun 30 14:21:29 2015 +0200 +++ b/src/pyams_thesaurus/rpc/json/__init__.py Wed Jul 22 17:22:01 2015 +0200 @@ -17,7 +17,7 @@ # import interfaces from pyams_thesaurus.interfaces.term import STATUS_ARCHIVED -from pyams_thesaurus.interfaces.thesaurus import IThesaurus +from pyams_thesaurus.interfaces.thesaurus import IThesaurus, IThesaurusExtracts # import packages from pyams_utils.list import unique @@ -26,7 +26,29 @@ @jsonrpc_method(endpoint='thesaurus') +def getExtracts(request, thesaurus_name): + """Get extracts of given thesaurus""" + thesaurus = query_utility(IThesaurus, name=thesaurus_name) + if thesaurus is None: + return [] + extracts = IThesaurusExtracts(thesaurus) + return [{'id': extract.__name__, + 'text': extract.name} for extract in extracts.values()] + + +@jsonrpc_method(endpoint='thesaurus') +def getTopTerms(request, thesaurus_name, extract_name=None): + """Get top terms of given thesaurus""" + thesaurus = query_utility(IThesaurus, name=thesaurus_name) + if thesaurus is None: + return [] + return ({'id': term.label, + 'text': term.label} for term in thesaurus.getTopTerms(extract_name)) + + +@jsonrpc_method(endpoint='thesaurus') def findTerms(request, query, thesaurus_name, extract_name=None): + """Find terms matching given query, returning their title""" thesaurus = query_utility(IThesaurus, name=thesaurus_name) if thesaurus is None: return [] @@ -39,6 +61,7 @@ @jsonrpc_method(endpoint='thesaurus') def findTermsWithLabel(request, query, thesaurus_name, extract_name=None): + """Find terms matching given query, returning their full label""" thesaurus = query_utility(IThesaurus, name=thesaurus_name) if thesaurus is None: return []