Exemplo n.º 1
0
def lemmatize(method, data):
    """
	Takes an array of words or array of tupples containing words and pos tags.
	Both Penn and Wordnet tags are supported
	"""
    data = parse_input(data)
    if data == False:
        return ret_failure(703)
    else:
        res = []
        if method == "wordnet":
            for word in data:
                try:
                    if type(word) is list:
                        res.append([
                            word[0],
                            WordnetLm.lemmatize(word[0], penn_to_wn(word[1]))
                        ])
                    else:
                        res.append([word, WordnetLm.lemmatize(word)])
                except LookupError:
                    return ret_failure(704)
                except:
                    return ret_failure(702)
        else:
            abort(404)
        return ret_success(res)
Exemplo n.º 2
0
def stemmer(method,data):
	"""
	Takes an array of words in JSON format.
	"""
	data = parse_input(data)
	if data == False:
		return ret_failure(703)
	else:
		res=[]
		if method == "lancaster":
			for word in data:
				try:
					res.append([word,LancasterSt.stem(word)])
				except:
					return ret_failure(702)
		elif method == "porter":
			for word in data:
				try:
					res.append([word,PorterSt.stem(word)])
				except:
					return ret_failure(702)
		elif method == 'snowball':
			for word in data:
				try:
					res.append([word,SnowballSt.stem(word)])
				except:
					return ret_failure(702)
		else:
			abort(404)
		return ret_success(res)
Exemplo n.º 3
0
def stemmer(method, data):
    """
	Takes an array of words in JSON format.
	"""
    data = parse_input(data)
    if data == False:
        return ret_failure(703)
    else:
        res = []
        if method == "lancaster":
            for word in data:
                try:
                    res.append([word, LancasterSt.stem(word)])
                except:
                    return ret_failure(702)
        elif method == "porter":
            for word in data:
                try:
                    res.append([word, PorterSt.stem(word)])
                except:
                    return ret_failure(702)
        elif method == 'snowball':
            for word in data:
                try:
                    res.append([word, SnowballSt.stem(word)])
                except:
                    return ret_failure(702)
        else:
            abort(404)
        return ret_success(res)
Exemplo n.º 4
0
def puzzle1():
    contents = helpers.parse_input('day1.txt')
    run_total = 0

    for line in contents:
        run_total += helpers.stoval(line)

    return str(run_total)
Exemplo n.º 5
0
def pos_tag(data):
	data = parse_input(data)
	if data == False:
		return ret_failure(703)
	else:
		try:
			res = nltk.pos_tag(data)
			return ret_success(res)
		except LookupError: 
			return ret_failure(704)
		except:
			return ret_failure(702)
Exemplo n.º 6
0
def puzzle2():
    contents = helpers.parse_input('day1.txt')
    prior = set()
    run_total = 0
    index = 0

    while (True):
        run_total += helpers.stoval(contents[index])

        if run_total in prior:
            return str(run_total)
        else:
            prior.add(run_total)
        index += 1

        if index >= len(contents):
            index = 0
Exemplo n.º 7
0
def lemmatize(method,data):
	"""
	Takes an array of words or array of tupples containing words and pos tags.
	Both Penn and Wordnet tags are supported
	"""
	data = parse_input(data)
	if data == False:
		return ret_failure(703)
	else:
		res=[]
		if method == "wordnet":
			for word in data:
				try:
					if type(word) is list:
						res.append([word[0],WordnetLm.lemmatize(word[0],penn_to_wn(word[1]))])
					else:	
						res.append([word,WordnetLm.lemmatize(word)])
				except LookupError: 
					return ret_failure(704)
				except:
					return ret_failure(702)
		else:
			abort(404)
		return ret_success(res)
Exemplo n.º 8
0
def compute(path):
    n_books, n_libraries, days, book_scores, libraries = parse_input(path)
    best_seq = get_best_sequence(libraries, days, book_scores)
    print(len(best_seq))
    print(best_seq)
    write_out(best_seq, path)