Exemple #1
0
def main(*args, **kwargs):
    """ NuPIC NLP main entry point. """
    (options, args) = parser.parse_args()
    if options.max_terms.lower() == 'all':
        max_terms = sys.maxint
    else:
        max_terms = int(options.max_terms)
    min_sparsity = float(options.min_sparsity)
    prediction_start = int(options.prediction_start)
    verbosity = 0
    if options.verbose:
        verbosity = 5

    # Create the cache directory if necessary.
    if not os.path.exists(cache_dir):
        os.mkdir(cache_dir)

    reader = NLTK_Reader(os.path.join(cache_dir, 'text'), verbosity=verbosity)
    builder = SDR_Builder(cept_app_key, cache_dir, verbosity=verbosity)
    nupic = Nupic_Word_Client()
    runner = Association_Runner(builder,
                                nupic,
                                max_terms,
                                min_sparsity,
                                prediction_start,
                                verbosity=verbosity)

    noun_pairs = reader.get_noun_pairs_from_all_texts()[:max_terms]

    runner.associate(noun_pairs)
def main(*args, **kwargs):
  """ NuPIC NLP main entry point. """
  (options, args) = parser.parse_args()
  if options.max_terms.lower() == 'all':
    max_terms = sys.maxint
  else:
    max_terms = int(options.max_terms)
  min_sparsity = float(options.min_sparsity)
  prediction_start = int(options.prediction_start)
  verbosity = 0
  if options.verbose:
    verbosity = 5

  # Create the cache directory if necessary.
  if not os.path.exists(cache_dir):
    os.mkdir(cache_dir)

  reader = NLTK_Reader(os.path.join(cache_dir, 'text'), verbosity=verbosity)
  builder = SDR_Builder(cept_app_key, cache_dir, verbosity=verbosity)
  nupic = Nupic_Word_Client()
  runner = Association_Runner(builder, nupic, max_terms, min_sparsity, prediction_start, verbosity=verbosity)

  noun_pairs = reader.get_noun_pairs_from_all_texts()[:max_terms]
  
  runner.associate(noun_pairs)
def main(*args, **kwargs):
    """POS Experiment main entry point."""

    (options, args) = parser.parse_args()
    verbosity = NLTK_Reader.WARN
    if options.verbose:
        verbosity = NLTK_Reader.DEBUG

    reader = NLTK_Reader(input='./resources/text',
                         cache_dir='./cache/text',
                         verbosity=verbosity)

    simple_tags = not options.full_tagging

    if options.text_info:
        reader.text_report()
    if options.list_texts:
        print 'Available texts:'
        for t in reader.available_texts():
            print '\t%s' % t

    if options.input_text:
        target_text = options.input_text
    else:
        target_text = None

    if target_text is not None:
        if options.pos_report:
            print 'Parts of Speech found in %s:' % target_text
            for pos in reader.get_parts_of_speech(target_text,
                                                  simplify_tags=simple_tags):
                tag_description = reader.describe_tag(pos)
                print '\t%6s  %s (%s)' % (pos, tag_description[0],
                                          tag_description[1])
        else:
            output_dir = options.output_dir

            model = ModelFactory.create(run_pos_model_params.MODEL_PARAMS)
            model.enableInference({'predictedField': 'pos'})

            if output_dir:
                if not os.path.exists(output_dir):
                    os.mkdir(output_dir)
                output_file_path = os.path.join(output_dir,
                                                'pos_out_' + target_text)
                # Clear the output file with a header.
                with open(output_file_path, 'w') as output_file:
                    output_file.write('%10s%10s%20s\n' %
                                      ('input', 'pos', 'predicted_pos'))
                # Append each result to output file.
                with open(output_file_path, 'a') as output_file:
                    run_pos_experiment(model, reader, target_text, simple_tags,
                                       output_file)
            else:
                run_pos_experiment(model, reader, target_text, simple_tags)
def main(*args, **kwargs):
    """POS Experiment main entry point."""

    (options, args) = parser.parse_args()
    verbosity = NLTK_Reader.WARN
    if options.verbose:
        verbosity = NLTK_Reader.DEBUG

    reader = NLTK_Reader(input="./resources/text", cache_dir="./cache/text", verbosity=verbosity)

    simple_tags = not options.full_tagging

    if options.text_info:
        reader.text_report()
    if options.list_texts:
        print "Available texts:"
        for t in reader.available_texts():
            print "\t%s" % t

    if options.input_text:
        target_text = options.input_text
    else:
        target_text = None

    if target_text is not None:
        if options.pos_report:
            print "Parts of Speech found in %s:" % target_text
            for pos in reader.get_parts_of_speech(target_text, simplify_tags=simple_tags):
                tag_description = reader.describe_tag(pos)
                print "\t%6s  %s (%s)" % (pos, tag_description[0], tag_description[1])
        else:
            output_dir = options.output_dir

            model = ModelFactory.create(run_pos_model_params.MODEL_PARAMS)
            model.enableInference({"predictedField": "pos"})

            if output_dir:
                if not os.path.exists(output_dir):
                    os.mkdir(output_dir)
                output_file_path = os.path.join(output_dir, "pos_out_" + target_text)
                # Clear the output file with a header.
                with open(output_file_path, "w") as output_file:
                    output_file.write("%10s%10s%20s\n" % ("input", "pos", "predicted_pos"))
                # Append each result to output file.
                with open(output_file_path, "a") as output_file:
                    run_pos_experiment(model, reader, target_text, simple_tags, output_file)
            else:
                run_pos_experiment(model, reader, target_text, simple_tags)