Skip to content

Commit

Permalink
REFACTOR: Unified data loading strategy when using a line split method
Browse files Browse the repository at this point in the history
  • Loading branch information
timmahrt committed Oct 29, 2016
1 parent d3ed749 commit 574940f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
8 changes: 1 addition & 7 deletions lmeds/lmeds_io/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ def loadTxtFile(fn):

def loadTxtFileWHTML(fn):
with io.open(fn, "r", encoding="utf-8") as fd:
txt = fd.read()

lineEnding = utils.detectLineEnding(txt)
if lineEnding is None: # Should be only a single line
txtList = [txt, ]
else:
txtList = txt.split(lineEnding)
txtList = [row.rstrip("\n") for row in fd.readlines()]

newTxtList = []
for row in txtList:
Expand Down
4 changes: 1 addition & 3 deletions lmeds/lmeds_io/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ def getPageStr(self, pageNum):

def parseSequence(sequenceFN, keepDirectives=False):
with io.open(sequenceFN, "r", encoding='utf-8') as fd:
data = fd.read()
testItemList = data.split("\n")
testItemList = [row.strip() for row in testItemList]
testItemList = [row.rstrip("\n") for row in fd.readlines()]
testItemList = [row for row in testItemList if row != '']

if keepDirectives is False:
Expand Down
5 changes: 2 additions & 3 deletions lmeds/lmeds_io/user_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
def loadUserResponse(fn):

with io.open(fn, "r", encoding="utf-8") as fd:
featureList = fd.read().split("\n")
featureList = [row.strip() for row in featureList]

featureList = [row.rstrip('\n') for row in fd.readlines()]

returnList = []
for line in featureList:
if line == "":
Expand Down
2 changes: 1 addition & 1 deletion lmeds/user_scripts/post_process_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def extractFromTest(path, keyList, removeItemList=None, onlyKeepList=None):
testSequenceDataList = []
for fn in utils.findFiles(path, filterExt=".csv"):
with io.open(join(path, fn), "r", encoding="utf-8") as fd:
subjectDataList = fd.read().split("\n")
subjectDataList = [row.rstrip("\n") for row in fd.readlines()]
subjectDataList = [line.split(",", 1) for line in subjectDataList]
testSequenceDataList.append((fn, subjectDataList))

Expand Down

0 comments on commit 574940f

Please sign in to comment.