Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check added for MetaMap file existence and executable access for the user #38

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pymetamap/MetaMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# limitations under the License.

import abc
from os.path import isabs
from os import access, X_OK
from os.path import isabs, isfile

DEFAULT_METAMAP_VERSION = '2012'

Expand All @@ -28,6 +29,8 @@ class MetaMap:

def __init__(self, metamap_filename, version=None):
self.metamap_filename = str(metamap_filename)
assert isfile(self.metamap_filename), "metamap_filename: {0} :: Please provide metamap executable file path".format(self.metamap_filename)
assert access(self.metamap_filename, X_OK), "User doesn't have executable access to metamap_filename: {0}".format(self.metamap_filename)
assert isabs(self.metamap_filename), "metamap_filename: {0} should be an absolute path".format(self.metamap_filename)
if version is None:
version = DEFAULT_METAMAP_VERSION
Expand All @@ -42,6 +45,8 @@ def extract_concepts(self, sentences=None, ids=None,
def get_instance(metamap_filename, version=None, backend='subprocess',
**extra_args):
extra_args.update(metamap_filename=metamap_filename, version=version)
assert isfile(metamap_filename), "metamap_filename: {0} :: Please provide metamap executable file path".format(metamap_filename)
assert access(metamap_filename, X_OK), "User doesn't have executable access to metamap_filename: {0}".format(metamap_filename)
assert isabs(metamap_filename), "metamap_filename: {0} should be an absolute path".format(metamap_filename)

if backend == 'subprocess':
Expand Down