Skip to content

Commit

Permalink
Merge pull request #19 from akb89/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
akb89 authored Jun 6, 2019
2 parents 9817ce1 + d126b9a commit bdd28d2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions pyfn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def _convert(args):
'need to specify the --sent parameter pointing at the '
'.sentences file absolute filepath')
annosets = semaforu.unmarshall_annosets(args.source_path, args.sent)
## Starting marshalling
os.makedirs(args.target_path, exist_ok=True)
# Starting marshalling
if args.target_format == 'bios':
os.makedirs(args.target_path, exist_ok=True)
biosm.marshall_annosets_dict(annosets_dict, args.target_path,
args.filter, args.output_sentences,
args.excluded_frames,
Expand All @@ -90,6 +90,7 @@ def _convert(args):
args.excluded_sentences,
args.excluded_annosets)
if args.target_format == 'semafor':
os.makedirs(args.target_path, exist_ok=True)
semaform.marshall_annosets_dict(annosets_dict, args.target_path,
args.filter, args.output_sentences,
args.excluded_frames,
Expand Down Expand Up @@ -126,7 +127,9 @@ def main():
help='absolute filepath to source dir')
parser_convert.add_argument('--target', required=True,
dest='target_path',
help='absolute filepath to target dir')
help='absolute path to target dir or file.'
'is dirpath if --to is semafor or bios. '
'is filepath if --to is semeval')
parser_convert.add_argument('--from', required=True,
dest='source_format',
choices=['semafor', 'bios', 'semeval',
Expand Down
4 changes: 2 additions & 2 deletions pyfn/marshalling/unmarshallers/bios.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _create_annoset(lines, sentence, annoset_id):

def _create_sent_dict(bios_filepath):
sent_dict = {}
with open(bios_filepath, 'r') as bios_stream:
with open(bios_filepath, 'r', encoding='utf-8') as bios_stream:
tokens = []
sent_index = -1
for line in bios_stream:
Expand All @@ -141,7 +141,7 @@ def unmarshall_annosets(bios_filepath, sent_filepath=None):
sent_dict = marsh_utils.get_sent_dict(sent_filepath)
else:
sent_dict = _create_sent_dict(bios_filepath)
with open(bios_filepath, 'r') as bios_stream:
with open(bios_filepath, 'r', encoding='utf-8') as bios_stream:
index = -1
annoset_id = 0
lines = []
Expand Down
2 changes: 1 addition & 1 deletion pyfn/marshalling/unmarshallers/semafor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def unmarshall_annosets(semafor_filepath, sent_filepath):
"""Unmarshall a semafor .frame.elements file to pyfn.AnnotationSets."""
annosets = []
sent_dict = marsh_utils.get_sent_dict(sent_filepath)
with open(semafor_filepath, 'r') as semafor_stream:
with open(semafor_filepath, 'r', encoding='utf-8') as semafor_stream:
for line in semafor_stream:
line = line.strip()
line_split = line.split('\t')
Expand Down
2 changes: 1 addition & 1 deletion pyfn/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
def load(config_file):
"""Load an ImmutableConfig from a YAML configuration file."""
logger.info('Loading config from file {}'.format(config_file))
with open(config_file, 'r') as config_stream:
with open(config_file, 'r', encoding='utf-8') as config_stream:
config = yaml.safe_load(config_stream)
return ImmutableConfig(config)
2 changes: 1 addition & 1 deletion pyfn/utils/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_sent_dict(sent_filepath):
"""
sent_dict = {}
sent_iter = 0
with open(sent_filepath, 'r') as sent_stream:
with open(sent_filepath, 'r', encoding='utf-8') as sent_stream:
for line in sent_stream:
line = line.rstrip()
sent_dict[sent_iter] = line
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
author_email='[email protected]',
long_description=long_description,
long_description_content_type='text/markdown',
version='1.3.4',
version='1.3.6',
url='https://gitlab.com/akb89/pyfn',
download_url='https://pypi.org/project/pyfn/#files',
license='MIT',
Expand Down

0 comments on commit bdd28d2

Please sign in to comment.