input: Write a function to analyze the sentiment of given text and categorize it into positive, negative, and neutral sentiments. The function should use tokenization and a NaiveBayesClassifier to classify each sentence and determine the overall sentiment. If the given text is empty, return 'neutral'.
  
  assert analyze_sentiment("I love this product!") == 'positive'
  assert analyze_sentiment("I hate this product.") == 'negative'
  assert analyze_sentiment("This is an average product.") == 'neutral'
  assert analyze_sentiment("") == 'neutral'
output: def analyze_sentiment(text):
      if not text:
          return 'neutral'
      
      from nltk.tokenize import sent_tokenize
      from nltk.classify import NaiveBayesClassifier
      from nltk.corpus import subjectivity
      from nltk.sentiment import SentimentAnalyzer
      from nltk.sentiment.util import extract_unigram_feats
      
      sentences = sent_tokenize(text)
      if not sentences:
          return 'neutral'
      
      subj_docs = [(sent, 'subj') for sent in subjectivity.sents(categories='subj')]
      obj_docs = [(sent, 'obj') for sent in subjectivity.sents(categories='obj')]
      
      train_subj_docs = subj_docs[:80]
      test_subj_docs = subj_docs[80:100]
      train_obj_docs = obj_docs[:80]
      test_obj_docs = obj_docs[80:100]
      
      training_docs = train_subj_docs + train_obj_docs
      testing_docs = test_subj_docs + test_obj_docs
      
      sentim_analyzer = SentimentAnalyzer()
      all_words_neg = sentim_analyzer.all_words([mark_negation(doc) for doc in training_docs])
      
      unigram_feats = sentim_analyzer.unigram_word_feats(all_words_neg, min_freq=4)
      sentim_analyzer.add_feat_extractor(extract_unigram_feats, unigrams=unigram_feats)
      
      training_set = sentim_analyzer.apply_features(training_docs)
      test_set = sentim_analyzer.apply_features(testing_docs)
      
      trainer = NaiveBayesClassifier.train
      classifier = sentim_analyzer.train(trainer, training_set)
      
      sentiment_scores = [classifier.classify(sentim_analyzer.extract_features(sent)) for sent in sentences]
      
      positive_count = sentiment_scores.count('subj')
      negative_count = sentiment_scores.count('obj')
      
      if positive_count > negative_count:
          return 'positive'
      elif negative_count > positive_count:
          return 'negative'
      else:
          return 'neutral'