Last active
October 17, 2015 01:42
-
-
Save jgc128/75964e86b05d760b8158 to your computer and use it in GitHub Desktop.
Code for homework 1 (2015 Fall NLP Class)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
base_dir = '/data1/aromanov/study/2015_fall/nlp/homeworks/hw1/' | |
brit3_filename = os.path.join(base_dir, 'brit3-excerpt.txt') | |
brit3_marked_filename = os.path.join(base_dir, 'brit3-excerpt-marked.txt') | |
problem4_text_filename = os.path.join(base_dir, 'problem4.txt') | |
def load_documents_from_dir(directory): | |
files = [os.path.join(directory, f) for f in os.listdir(directory)] | |
docs = [] | |
for fl in files: | |
with open(fl, 'r') as f: | |
d = f.read() | |
docs.append(d) | |
return docs | |
def load_file(filename): | |
with open(filename, 'r') as f: | |
result = f.read() | |
return result | |
def load_file_lines(filename): | |
with open(filename, 'r') as f: | |
lines = f.readlines() | |
result = [l.strip('\n') for l in lines] | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment