<commit_before># A service for movie info

from api.movie.tmdb_api import get_credits
from api.movie.tmdb_api import get_movies
from api.movie.tmdb_api import load_credits_for_name
from api.movie.tmdb_api import load_movie_for_title
from pal.grammars import get_grammar_for_service
from pal.grammars.parser import extract
from pal.grammars.parser import parse
from pal.services.service import Service
from pal.services.service import wrap_response


class MovieService(Service):

    def __init__(self):
        self.grammar = get_grammar_for_service(self.__class__.short_name())
        self.cached_parse = None

    def applies_to_me(self, client, feature_request_type):
        return True

    def get_confidence(self, params):
        query = params['query']

        # TODO: shouldn't have to do this
        if query[-1] == '?':
            query = query[:-1]

        self.cached_parse = (query, parse(query, self.grammar))
        return 100 if self.cached_parse else 0

    @wrap_response
    def go(self, params):
        query = params['query']

        # TODO: shouldn't have to do this
        if query[-1] == '?':
            query = query[:-1]

        if self.cached_parse and self.cached_parse[0] == query:
            parse_tree = self.cached_parse[1]
        else:
            parse_tree = parse(query, self.grammar)

        print parse_tree
        if parse_tree:
            intent = self.extract_intent(parse_tree)
            object_ = self.extract_object(parse_tree)
            self.update_kb(intent, object_)
            result = self.query_kb(intent, object_)
            summary = self.generate_summary(intent, object_, result)
            return ('SUCCESS', summary)
        else:
            return ('ERROR', 'I don\'t understand.')

    @staticmethod
    def extract_intent(parse_tree):
        name = extract('person_concrete', parse_tree)
        title = extract('movie_concrete', parse_tree)
        if title:<commit_msg>JSON, I understand<commit_after># A service for movie info

from api.movie.tmdb_api import get_credits
from api.movie.tmdb_api import get_movies
from api.movie.tmdb_api import load_credits_for_name
from api.movie.tmdb_api import load_movie_for_title
from pal.grammars import get_grammar_for_service
from pal.grammars.parser import extract
from pal.grammars.parser import parse
from pal.services.service import Service
from pal.services.service import wrap_response


class MovieService(Service):

    def __init__(self):
        self.grammar = get_grammar_for_service(self.__class__.short_name())
        self.cached_parse = None

    def applies_to_me(self, client, feature_request_type):
        return True

    def get_confidence(self, params):
        query = params['query']

        # TODO: shouldn't have to do this
        if query[-1] == '?':
            query = query[:-1]

        parse_ = parse(query, self.grammar)
        self.cached_parse = (query, parse_)
        return 100 if parse_ else 0

    @wrap_response
    def go(self, params):
        query = params['query']

        # TODO: shouldn't have to do this
        if query[-1] == '?':
            query = query[:-1]

        if self.cached_parse and self.cached_parse[0] == query:
            parse_tree = self.cached_parse[1]
        else:
            parse_tree = parse(query, self.grammar)

        print parse_tree
        if parse_tree:
            intent = self.extract_intent(parse_tree)
            object_ = self.extract_object(parse_tree)
            self.update_kb(intent, object_)
            result = self.query_kb(intent, object_)
            summary = self.generate_summary(intent, object_, result)
            return ('SUCCESS', summary)
        else:
            return ('ERROR', 'I don\'t understand.')

    @staticmethod
    def extract_intent(parse_tree):
        name = extract('person_concrete', parse_tree)
        title = extract('movie_concrete', parse_tree)
        if title:
{'fraction_non_alphanumeric': 0.09130213631739573, 'fraction_numerical': 0.00508646998982706, 'mean_word_length': 2.6654240447343898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7460928', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1131, 'n_words': 293}