-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from tsmbland/pathlib
Use pathlib for path handling
- Loading branch information
Showing
5 changed files
with
72 additions
and
70 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
import os | ||
import re | ||
from pathlib import Path | ||
|
||
folder1_path = 'OldOutput' | ||
folder2_path = 'NewOutput' | ||
folder1_path = Path('OldOutput') | ||
folder2_path = Path('NewOutput') | ||
lines_to_ignore = ["\"date\":", "\"offset\":", "\"inputfile\":"] | ||
|
||
different_files = [] | ||
|
||
for root, dirs, files in os.walk(folder1_path): | ||
for filename in files: | ||
if "_bioc" not in filename: | ||
continue | ||
folder1_file_path = os.path.join(root, filename) | ||
folder2_file_path = os.path.join(folder2_path, filename) | ||
if os.path.exists(folder2_file_path): | ||
with open(folder1_file_path, 'r') as f1, open(folder2_file_path, 'r') as f2: | ||
lines1 = f1.readlines() | ||
lines2 = f2.readlines() | ||
different_lines = [i for i, (line1, line2) in enumerate(zip(lines1, lines2)) if | ||
re.sub(r"\s+", "", line1, flags=re.UNICODE) != re.sub(r"\s+", "", line2, | ||
flags=re.UNICODE) and | ||
not [x for x in lines_to_ignore if x in line1]] | ||
false_positives = different_lines | ||
different_lines = [] | ||
for i in range(len(false_positives)): | ||
if "[PMC free article]" not in lines1[false_positives[i]] and "[PMC free article]" in lines2[ | ||
false_positives[i]]: | ||
continue | ||
else: | ||
different_lines.append(false_positives[i]) | ||
for folder1_file_path in folder1_path.rglob('*'): | ||
if "_bioc" not in folder1_file_path.name: | ||
continue | ||
folder2_file_path = folder2_path / folder1_file_path.name | ||
if folder2_file_path.exists(): | ||
with open(folder1_file_path, 'r') as f1, open(folder2_file_path, 'r') as f2: | ||
lines1 = f1.readlines() | ||
lines2 = f2.readlines() | ||
different_lines = [ | ||
i for i, (line1, line2) in enumerate(zip(lines1, lines2)) | ||
if re.sub(r"\s+", "", line1, flags=re.UNICODE) != re.sub(r"\s+", "", line2, flags=re.UNICODE) and | ||
not [x for x in lines_to_ignore if x in line1] | ||
] | ||
false_positives = different_lines | ||
different_lines = [] | ||
for i in range(len(false_positives)): | ||
if "[PMC free article]" not in lines1[false_positives[i]] and "[PMC free article]" in lines2[false_positives[i]]: | ||
continue | ||
else: | ||
different_lines.append(false_positives[i]) | ||
|
||
if different_lines: | ||
different_files.append(filename) | ||
if different_lines: | ||
different_files.append(folder1_file_path.name) | ||
|
||
print("\n".join(different_files)) | ||
print(len(different_files)) |