Пример #1
0
from src.neti_neti_trainer import NetiNetiTrainer
from src.neti_neti import NetiNeti

if __name__ == '__main__':
    print "Running NetiNeti Training, it might take a while..."

    nnt = NetiNetiTrainer()
    nn = NetiNeti(nnt)

    print nn.find_names(
        "A frog-killing fungus known as Batrachochytrium dendrobatidis, or Bd, has already led to the decline of more than 200 amphibian species including the now extinct-in-the-wild Panamanian golden frog."
    )
Пример #2
0
        self.end_headers()
        self.wfile.write('hello world')

    def do_POST(self):
        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={
                                    'REQUEST_METHOD': 'POST',
                                    'CONTENT_TYPE':
                                    self.headers['Content-Type'],
                                })
        self.send_response(200)
        self.end_headers()
        self.wfile.write(nn.find_names(form['data'].value))
        return


def run(server_class=HTTPServer, handler_class=MyHandler):
    server_address = (HOST, PORT)
    print('Starting server, use <Ctrl-C> to stop')
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()


if __name__ == '__main__':
    print "Running NetiNeti Training, it might take a while..."
    nnt = NetiNetiTrainer()
    nn = NetiNeti(nnt)

    run()
Пример #3
0
# calculate the standard deviation of a population
# accepts: an array, the population
# returns: the standard deviation
def standard_deviation(population):
    if len(population) == 1:
        return 0
    return math.sqrt(variance(population))


population = []

time_start = time.clock()
classifier = NetiNetiTrainer()
time_training = time.clock()
print ("Training time: %s" % (time_training - time_start))
nn = NetiNeti(classifier)
for i in range(1, num_cycles):
    print ("going through the cycle %s" % i)
    time_start = time.clock()
    result = nn.find_names(open("data/test.txt").read())
    print ("Name finding time: %s" % (time.clock() - time_start))

    test_result_file = open("data/test_result_after_refactoring.txt", 'w')

    for i in result[1]:
        test_result_file.write(i + "\n")

    test_result_file.close()

    args = shlex.split('diff -d  data/test_result_before_refactoring.txt data/test_result_after_refactoring.txt')
    result = subprocess.Popen(args, stdout = subprocess.PIPE, stderr= subprocess.PIPE).communicate()
Пример #4
0
from src.neti_neti_trainer import NetiNetiTrainer
from src.neti_neti import NetiNeti

if __name__ == '__main__':
    print "Running NetiNeti Training, it might take a while..."
    
    nnt = NetiNetiTrainer()
    nn = NetiNeti(nnt)
    
    print nn.find_names("A frog-killing fungus known as Batrachochytrium dendrobatidis, or Bd, has already led to the decline of more than 200 amphibian species including the now extinct-in-the-wild Panamanian golden frog.")
Пример #5
0
from src.neti_neti_trainer import NetiNetiTrainer
from src.neti_neti import NetiNeti
from glob import glob
import sys
import os

nnt = NetiNetiTrainer()
nn = NetiNeti(nnt)

if len(sys.argv) >= 2:

    input_dir = sys.argv[1]

    result = []
    for document in glob(os.path.join(input_dir, "*.txt")):

        with open(document, 'rb') as f:
            data = unicode(f.read(), 'utf8')
            #data = data.replace("\r\n", "\n")

            res = nn.find_names(data)
            result += [os.path.basename(document) + " {}".format(res)]

    print("\t".join(result))