Skip to content

Commit

Permalink
Merge pull request #265 from clulab/kwalcock/backport
Browse files Browse the repository at this point in the history
Include the logging from heuristics
  • Loading branch information
kwalcock authored Jan 22, 2025
2 parents d1ebeed + c6adea8 commit 5f4323d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 0 additions & 4 deletions belief_pipeline/pandas_output_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ def __init__(self, file_name: str) -> None:
# if not os.path.exists(file_name):
# os.makedirs(file_name) # find the directory it's in, not use the entire file

def log(self, message: str):
with open("output.txt", "a", encoding="utf-8", newline="\n") as file:
print(message, file=file)

def write(self, text):
nl_count = text.count("\n") + 1
self.log(str(nl_count))
Expand Down
13 changes: 13 additions & 0 deletions belief_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class PipelineStage():
def _init__(self) -> None:
pass

def log(self, message: str):
self.logToFile("log.txt", message)

def logToFile(self, filename: str, message: str):
with open(filename, "a", encoding="utf-8", newline="\n") as file:
print(message, file=file)

class OuterStage(PipelineStage):
def __init__(self) -> None:
super().__init__()
Expand All @@ -17,6 +24,9 @@ def __init__(self, dir_name: str) -> None:
def run(self) -> DataFrame:
pass

def log(self, message: str):
self.logToFile("input.txt", message)

class OutputStage(OuterStage):
def __init__(self, file_name: str) -> None:
super().__init__()
Expand All @@ -25,6 +35,9 @@ def __init__(self, file_name: str) -> None:
def run(self, data_frame: DataFrame):
pass

def log(self, message: str):
self.logToFile("output.txt", message)

class InnerStage(PipelineStage):
def __init__(self) -> None:
super().__init__()
Expand Down
4 changes: 0 additions & 4 deletions belief_pipeline/tpi_input_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def mk_data_frame(self, file_name: str, sep: str) -> DataFrame:
print("There is an empty sentence!")
data_frame["sentence"][index] = "" # What should be done?
return data_frame

def log(self, message: str):
with open("input.txt", "a", encoding="utf-8", newline="\n") as file:
print(message, file=file)

def read(self) -> StringIO:
# In Python, the line separator is preserved.
Expand Down
4 changes: 4 additions & 0 deletions belief_pipeline/tpi_location_stage_with_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tqdm import tqdm

import itertools
import os
import pandas
import re
import spacy
Expand Down Expand Up @@ -68,6 +69,9 @@ def __init__(self, locations_file_name: str) -> None:
# message on the console about lost data, probably from the extra column that we're not using here:
# ParserWarning: Length of header or names does not match length of data. This leads to a loss of data
# with index_col=False.
self.log("locations_file_name " + locations_file_name)
self.log("working directory " + os.getcwd())

locations_data_frame = pandas.read_csv(locations_file_name, sep="\t", encoding="utf-8", index_col=False, names=[
"geonameid", "name", "asciiname", "alternatenames", "latitude", "longitude", "unk1", "unk2", "country_code",
"cc2", "unk3", "unk4", "unk5", "unk6", "population", "elevation", "unk7", "timezone", "unk8" #, "notes"
Expand Down

0 comments on commit 5f4323d

Please sign in to comment.