Skip to content

Commit

Permalink
bug fix on json load
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Baptiste-Camps committed Dec 9, 2024
1 parent 9f1fddd commit 3127f0e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions load_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
parser = argparse.ArgumentParser()
parser.add_argument('-s', nargs='+', help="paths to files", required=True)
parser.add_argument('-o', action='store', help="optional base name of output files", type=str, default=False)
parser.add_argument('-f', action="store", help="optional list of features in json", default=False)
parser.add_argument('-f', action="store", help="optional list of features, either in json (generated by Superstyl) or simple txt (one word per line)", default=False)
parser.add_argument('-t', action='store', help="types of features (words, chars, affixes - "
"as per Sapkota et al. 2015 - or pos). pos are currently"
"only implemented for Modern English", type=str,
Expand Down Expand Up @@ -57,9 +57,18 @@
args = parser.parse_args()

if args.f:
print(".......loading preexisting feature list.......")
with open(args.f, 'r') as f:
my_feats = json.loads(f.read())
if args.f.split(".")[-1] == "json":
print(".......loading preexisting feature list from json.......")
my_feats = json.loads(f.read())

elif args.f.split(".")[-1] == "txt":
print(".......loading preexisting feature list from txt.......")
my_feats = [[feat.rstrip(), 0] for feat in f.readlines()]

else:
print(".......unknown feature list format. Ignoring.......")
my_feats = None

else:
my_feats = None
Expand Down

0 comments on commit 3127f0e

Please sign in to comment.