<commit_before>#
#   Copyright (c) 2010-2014, MIT Probabilistic Computing Project
#
#   Lead Developers: <NAME> and <NAME>
#   Authors: <NAME>, <NAME>, <NAME>, <NAME>
#   Research Leads: <NAME>, <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

from bayesdb.client import Client
from cmd2 import Cmd
import sys

class BayesDBApp(Cmd):
  """Provides "interactive mode" features."""

  def __init__(self, client):
    self.client = client
    self.prompt = 'bql> '
    Cmd.__init__(self, 'tab')

  def do_show(self, line):
    self.client('show ' + str(line))

  def do_list(self, line):
    self.client('list ' + str(line))

  def do_analyze(self, line):
    self.client('analyze ' + str(line))

  def do_execute(self, line):
    self.client('execute ' + str(line))

  def do_drop(self, line):
    self.client('drop ' + str(line))

  def do_initialize(self, line):
    self.client('initialize ' + str(line))

  def do_create(self, line):
    self.client('create ' + str(line))

  def do_infer(self, line):
    self.client('infer ' + str(line))

  def do_select(self, line):
    self.client('select ' + str(line))

  def do_simulate(self, line):
    self.client('simulate ' + str(line))

  def do_save(self, line):
    self.client('save ' + str(line))
    
  def do_load(self, line):
    self.client('load ' + str(line))

  def do_estimate(self, line):
    self.client('estimate ' + str(line))

  def do_update(self, line):
    self.client('update ' + str(line))
    
  def default(self, line):
    self.client(str(line))

def run_command_line():
  # Get command line arguments to specify hostname and port
  hostname = None
  port = None
  if len(sys.argv) > 1:
    # Treat the first argument as hostname[:port]
    input = sys.argv[1].split(':')
    hostname = input[0]
    if len(input) == 2:
      port = int(input[1])
    elif len(input) > 2:
      print "Run with 'python bql [hostname[:port]]'"
    
  client = Client(hostname, port)
  app = BayesDBApp(client)
  app.cmdloop()
    

if __name__ == "__main__":
  run_command_line()<commit_msg>Add friendly help message to command line client<commit_after>#
#   Copyright (c) 2010-2014, MIT Probabilistic Computing Project
#
#   Lead Developers: <NAME> and <NAME>
#   Authors: <NAME>, <NAME>, <NAME>, <NAME>
#   Research Leads: <NAME>, <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

from bayesdb.client import Client
from cmd2 import Cmd
import sys

class BayesDBApp(Cmd):
  """Provides "interactive mode" features."""

  def __init__(self, client):
    self.client = client
    self.prompt = 'bql> '
    Cmd.__init__(self, 'tab')

  def do_show(self, line):
    self.client('show ' + str(line))

  def do_list(self, line):
    self.client('list ' + str(line))

  def do_analyze(self, line):
    self.client('analyze ' + str(line))

  def do_execute(self, line):
    self.client('execute ' + str(line))

  def do_drop(self, line):
    self.client('drop ' + str(line))

  def do_initialize(self, line):
    self.client('initialize ' + str(line))

  def do_create(self, line):
    self.client('create ' + str(line))

  def do_infer(self, line):
    self.client('infer ' + str(line))

  def do_select(self, line):
    self.client('select ' + str(line))

  def do_simulate(self, line):
    self.client('simulate ' + str(line))

  def do_save(self, line):
    self.client('save ' + str(line))
    
  def do_load(self, line):
    self.client('load ' + str(line))

  def do_estimate(self, line):
    self.client('estimate ' + str(line))

  def do_update(self, line):
    self.client('update ' + str(line))

  def do_help(self, line):
    self.client('help ' + str(line))
    
  def default(self, line):
    self.client(str(line))

def run_command_line():
  # Get command line arguments to specify hostname and port
  hostname = None
  port = None
  if len(sys.argv) > 1:
    # Treat the first argument as hostname[:port]
    input = sys.argv[1].split(':')
    hostname = input[0]
    if len(input) == 2:
      port = int(input[1])
    elif len(input) > 2:
      print "Run with 'python bql [hostname[:port]]'"

  print """Welcome to BayesDB. You may enter BQL commands directly into this prompt. Type 'help' for help, and 'quit' to quit."""
  client = Client(hostname, port)
  app = BayesDBApp(client)
  app.cmdloop()
    

if __name__ == "__main__":
  run_command_line()
{'fraction_non_alphanumeric': 0.13455087588520312, 'fraction_numerical': 0.007081625046589639, 'mean_word_length': 3.529113924050633, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3571025', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1750, 'n_words': 534}