AnthonyMRios / pymetamap

Python wraper for MetaMap
170 stars 61 forks source link

Running error #9

Open wangyueyao opened 7 years ago

wangyueyao commented 7 years ago

I have already installed the metamap13 and when i run the example under windows 7, i get the following error: image I have also already import the pymetamp and replace the address in the metamap.get_instance method: image I just don't know what to do, please help me ^^

AnthonyMRios commented 7 years ago

pymetamap currently does not support Windows because of my use of NamedTemporaryFile in the SubprocessBackend. It will work on Linux and Mac systems.

wangyueyao commented 7 years ago

Thank you for answering the question, I will use it in Linux systems. Thanks! O(∩_∩)O~

Civiano commented 7 years ago

I have installed the pymetamap in Mac OS, when I run >>> sents = ['Heart Attack', 'John had a huge heart attack'] >>> concepts,error = mm.extract_concepts(sents,[1,2]) I get the following errors: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/changsu/anaconda/lib/python2.7/site-packages/pymetamap-0.1-py2.7.egg/pymetamap/SubprocessBackend.py", line 117, in extract_concepts metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE) File "/Users/changsu/anaconda/lib/python2.7/subprocess.py", line 390, in __init__ errread, errwrite) File "/Users/changsu/anaconda/lib/python2.7/subprocess.py", line 1024, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

Could you help me please to solve this problem?

AnthonyMRios commented 7 years ago

Hi Civiano,

When initializing the api: mm = MetaMap.get_instance('/opt/public_mm/bin/metamap12') the path must be a full path to where you have installed metamap.

For example, if you installed metamp 16 in your home directory, then you would use the following:

mm = MetaMap.get_instance('/Users/changsu/public_mm/bin/metamap16')

Civiano commented 7 years ago

thanks, but i got another problem when run pymetamap on ubuntu os concepts,error = mm.extract_concepts(sents,[1,2]) Traceback (most recent call last): File "", line 1, in File "pymetamap/SubprocessBackend.py", line 117, in extract_concepts metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE,shell=True) File "/usr/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

Could you help me please to solve this problem? Thanks!

AnthonyMRios commented 7 years ago

Hi Civiano,

Can you give me all the code you are trying to run? Assuming the path is correct and everything is installed, then you should check that you started skrmedpostctl and wsdserverctl.

Civiano commented 7 years ago
  1. the code: from pymetamap import MetaMap mm = MetaMap.get_instance('/media/zhangminhua/205CB4CD5CB49ECA/metamap/public_mm/bin/metamap12') sents = ['Heart Attack', 'John had a huge heart attack'] concepts,error = mm.extract_concepts(sents,[1,2])

  2. errors: Traceback (most recent call last): File "", line 1, in File "pymetamap/SubprocessBackend.py", line 117, in extract_concepts metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

  3. path: PATH: /usr/lib/java/jdk180_144/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games JAVA_HOME: /usr/lib/java/jdk180_144 CLASSPATH: /usr/lib/java/jdk180_144/lib

  4. skrmedpostctl and wsdserverctl are started by using: chmod +x skrmedpostctl\wsdserverctl sh skrmedpostctl\wsdserverctl start if not, it will return “insufficient privilege”

thank you very much!

nishalpattan commented 6 years ago

I am also facing the same error after executing below line

concepts,error = mm.extract_concepts(sents,[1,2])

concepts,error = mm.extract_concepts(sents,[1,2])Traceback (most recent call last): File "", line 1, in
File "pymetamap/SubprocessBackend.py", line 124, in extract_concepts metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 13] Permission denied

AnthonyMRios commented 6 years ago

Hi Nishal,

The issue you are having is different. Can you create a new issue specific to your problem? Anyways, did you install metamap? Also, do you have read permissions to use metamap assuming it is installed?

nishalpattan commented 6 years ago

yes , I have installed metamap. will try again and let you know

nishalpattan commented 6 years ago

I had tried again after reinstalling java in my Linux machine. I made sure that metamap is working correctly. Now it is working fine. Thanks

kaushikacharya commented 6 years ago

@AnthonyMRios I was also struggling with the same issue as mentioned by Civiano on Sep 2, 2017 in Linux environment. But it got resolved based on your suggestion on Aug 16, 2017:

the path must be a full path to where you have installed metamap.

I think in the README file under the Example Usage section, you should mention this in bold.

Also I feel in the code its better to check if the MetaMap path is absolute or not. In MetaMap.py, inside both the functions a) init and (b) get_instance you can check if the path is absolute or not using os.path.isabs According to python documentation, it will check:

On Unix, that means it begins with a slash

If its not absolute, just exit with appropriate message.

AnthonyMRios commented 6 years ago

Hi @kaushikacharya, I'm sorry for the issues you had running the code.

I agree with your suggestions. I'm currently working on other projects. I have noted the suggestion and I will try to add them sometime within the next couple weeks.

kaushikacharya commented 6 years ago

Hi Anthony, If you are ok then I can also make changes and create a pull request.

Regards, Kaushik

On Fri, Jul 20, 2018 at 8:18 PM, Anthony Rios notifications@github.com wrote:

Hi @kaushikacharya https://github.com/kaushikacharya, I'm sorry for the issues you had running the code.

I agree with your suggestions. I'm currently working on other projects. I have noted the suggestion and I will try to add them sometime within the next couple weeks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AnthonyMRios/pymetamap/issues/9#issuecomment-406623669, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWfs_JFxUCpz2j3L7LtFmk_KfUsxnczks5uIe3FgaJpZM4MIno9 .

AnthonyMRios commented 6 years ago

Sure. That would be great.

kibamin commented 5 years ago

thanks, but i got another problem when run pymetamap on ubuntu os concepts,error = mm.extract_concepts(sents,[1,2]) Traceback (most recent call last): File "", line 1, in File "pymetamap/SubprocessBackend.py", line 117, in extract_concepts metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE,shell=True) File "/usr/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

Could you help me please to solve this problem? Thanks!

how you fixed this problem ? please help me

AnthonyMRios commented 5 years ago

Hi @kibamin,

Do you have MetaMap installed on the Ubuntu machine? If not, you will need to get it from here: https://metamap.nlm.nih.gov/MetaMap.shtml

kibamin commented 5 years ago

Hi @kibamin,

Do you have MetaMap installed on the Ubuntu machine? If not, you will need to get it from here: https://metamap.nlm.nih.gov/MetaMap.shtml

Yes, i installed that on ubuntu and run WSD server and work with that without problem. But when run your code in line >>> concepts,error = mm.extract_concepts(sents,[1,2]) i get this (same) error :

File "pymetamap/SubprocessBackend.py", line 117, in extract_concepts metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE,shell=True) File "/usr/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

how to fix this ?

thank you

AnthonyMRios commented 5 years ago

Hi kibamin,

from the looks of things, it looks like you are not pointing to the location where you installed everything. I will need to see more of your code and know the file path to help more.

kibamin commented 5 years ago

Hi kibamin,

from the looks of things, it looks like you are not pointing to the location where you installed everything. I will need to see more of your code and know the file path to help more.

Hi Anthony

thank you for everything. I found my mistake, i made a mistake in pulbic_mm file path.

thank you

kaushikacharya commented 5 years ago

@AnthonyMRios, We should probably put a check for existence of MetaMap path just after assigning self.metamap_filename https://github.com/AnthonyMRios/pymetamap/blob/master/pymetamap/MetaMap.py#L30

something like this:

assert os.path.exists(mm.metamap_filename), "Incorrect MetaMap filename path"

Regards, Kaushik

On Mon, Apr 29, 2019 at 11:25 AM Amin Abbasi notifications@github.com wrote:

Hi kibamin,

from the looks of things, it looks like you are not pointing to the location where you installed everything. I will need to see more of your code and know the file path to help more.

Hi Anthony

thank you for everything. I found my mistake, i made a mistake in pulbic_mm file path.

thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AnthonyMRios/pymetamap/issues/9#issuecomment-487458456, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCZ7M4QU5ZH7WJMXTW2PY3PS2EUFANCNFSM4DBCPI6Q .

AnthonyMRios commented 5 years ago

Yeah, I agree. That would help clear up many of the issues posted here.

lediona commented 4 years ago

Hi, I am running : mm = MetaMap.get_instance('/Users/ledionanishani/Documents/public_mm/bin/metamap18') sents = ['Heart Attack', 'John had a huge heart attack'] concepts,error = mm.extract_concepts(sents,[1,2])

And the concepts are empty. Could you please what I am doing wrong? thanks in advance

kaushikacharya commented 4 years ago

Hi, I am running : mm = MetaMap.get_instance('/Users/ledionanishani/Documents/public_mm/bin/metamap18') sents = ['Heart Attack', 'John had a huge heart attack'] concepts,error = mm.extract_concepts(sents,[1,2])

And the concepts are empty. Could you please what I am doing wrong? thanks in advance

@lediona Have a look at the suggestion by Anthony on a similar issue: https://github.com/AnthonyMRios/pymetamap/issues/19

https://metamap.nlm.nih.gov/Docs/README.html#Starting%20the%20MetaMap%20Servers This shows how to run the part of speech tagger and WSD servers. Most likely you haven't started these servers.

lediona commented 4 years ago

@kaushikacharya thank you so much for your prompt reply. It is working like a charm now !!!

lediona commented 4 years ago

Hi, I am using pymetamap but seems like its output is not that accurate: sentence='Its like its stuck Sinus pain and pressure Amoxicillin has worked in the past' concepts, error =mm.extract_concepts(sentence, [1,2])

image

it does not make sense. I getting the same output from different sentences: preferred name: Iodides or Blood group antibody . In the sentence it is not mentioned any blood or antibody. I have used the pymetamap last year and it worked really good in terms of extracting medical terms. I am noticing that it captures the first letter of the sentence instead of the word Do you have any idea why is this happening? thanks in advance!

kaushikacharya commented 4 years ago

@lediona Your input isn't correct.

image

Note the difference between your and mine input. It should be list of string. What you have given is string. Your input is considered as list of characters. And the 2nd input parameter of extract_concepts i.e. [1,2] suggests to use the 1st two elements i.e. 1st two characters of the string.

Have a look at the function: https://github.com/AnthonyMRios/pymetamap/blob/master/pymetamap/SubprocessBackend.py#L27 def extract_concepts(self, sentences=None, ids=None,

More details are available here: https://github.com/AnthonyMRios/pymetamap/blob/master/pymetamap/SubprocessBackend.py#L95 for identifier, sentence in zip(ids, sentences):

Also note the trigger, pos_info fields in the output. (Read https://metamap.nlm.nih.gov/Docs/MMI_Output.pdf for detail). They show which part of the text is used to create the UMLS concept. In your case its only the 1st character of the string that's creating the concepts.

itSammycodethngy commented 4 years ago

TypeError Traceback (most recent call last)

in 1 sents = ['Heart Attack'] ----> 2 concepts,error = mm.extract_concepts(sents,[1]) 3 concepts ~/pyte/pymetamap/SubprocessBackend.py in extract_concepts(self, sentences, ids, composite_phrase, filename, file_format, allow_acronym_variants, word_sense_disambiguation, allow_large_n, strict_model, relaxed_model, allow_overmatches, allow_concept_gaps, term_processing, no_derivational_variants, derivational_variants, ignore_word_order, unique_acronym_variants, prefer_multiple_concepts, ignore_stop_phrases, compute_all_mappings, mm_data_version, exclude_sources, restrict_to_sources, restrict_to_sts, exclude_sts) 152 if ids is not None: 153 for identifier, sentence in zip(ids, sentences): --> 154 input_text += '{0!r}|{1!r}\n'.format(identifier, sentence).encode('utf8') 155 else: 156 for sentence in sentences: TypeError: can only concatenate str (not "bytes") to str I tried running the example and this is what I get
kaushikacharya commented 4 years ago

@itSammycodethngy Ii seems you are running in Python 3.

https://stackoverflow.com/questions/55033372/can-only-concatenate-str-not-bytes-to-str chepner's answer explains the difference between Python 2 and Python 3:

Python 3 made the distinction between the two very clear and does not allow you to combine them implicitly.

In python 3: image

whereas in python 2 it works smoothly: image

Solution: https://github.com/AnthonyMRios/pymetamap/blob/master/pymetamap/SubprocessBackend.py#L151 Replace input_text = "" by input_text = bytes() Hopefully this change will work. In case you get similar error elsewhere, try making similar changes.

Edit: input_text = "".encode('utf8') should make it consistent for both python 2 and 3.

itSammycodethngy commented 4 years ago

thanks

On Fri, Dec 6, 2019 at 4:29 PM Kaushik Acharya notifications@github.com wrote:

@itSammycodethngy https://github.com/itSammycodethngy Ii seems you are running in Python 3.

https://stackoverflow.com/questions/55033372/can-only-concatenate-str-not-bytes-to-str chepner's answer explains the difference between Python 2 and Python 3:

Python 3 made the distinction between the two very clear and does not allow you to combine them implicitly.

In python 3: [image: image] https://user-images.githubusercontent.com/4562867/70307767-e7d13b00-182f-11ea-8c2b-803a1b15ad08.png

whereas in python 2 it works smoothly: [image: image] https://user-images.githubusercontent.com/4562867/70307844-0800fa00-1830-11ea-9d05-3aa1a995589c.png

Solution:

https://github.com/AnthonyMRios/pymetamap/blob/master/pymetamap/SubprocessBackend.py#L151 Replace input_text = "" by input_text = bytes() Hopefully this change will work. In case you get similar error elsewhere, try making similar changes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AnthonyMRios/pymetamap/issues/9?email_source=notifications&email_token=AHDPLR72W724Q3HGMP573TTQXIEM5A5CNFSM4DBCPI62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGDMNKY#issuecomment-562480811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDPLR42YVKLG2NYFPD5URLQXIEM5ANCNFSM4DBCPI6Q .

AnthonyMRios commented 4 years ago

I made a quick update. I believe it should be consistent now.

itSammycodethngy commented 4 years ago

will pull the latest then

On Fri, Dec 6, 2019 at 10:28 PM Anthony Rios notifications@github.com wrote:

I made a quick update. I believe it should be consistent now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AnthonyMRios/pymetamap/issues/9?email_source=notifications&email_token=AHDPLR4ZYHFPZG3Z6FUWZG3QXJOSDA5CNFSM4DBCPI62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGEHVCY#issuecomment-562592395, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDPLRYGSM7RIGLJVBSDWK3QXJOSDANCNFSM4DBCPI6Q .

itSammycodethngy commented 4 years ago

TypeError Traceback (most recent call last)

in 1 sents = ['Heart Attack'] ----> 2 concepts,error = mm.extract_concepts(sents,[1]) 3 concepts 4 ~/pyte/pymetamap/SubprocessBackend.py in extract_concepts(self, sentences, ids, composite_phrase, filename, file_format, allow_acronym_variants, word_sense_disambiguation, allow_large_n, strict_model, relaxed_model, allow_overmatches, allow_concept_gaps, term_processing, no_derivational_variants, derivational_variants, ignore_word_order, unique_acronym_variants, prefer_multiple_concepts, ignore_stop_phrases, compute_all_mappings, mm_data_version, exclude_sources, restrict_to_sources, restrict_to_sts, exclude_sts) 180 prev_new_line = -1 181 while (prev_new_line + 1) < len(output): --> 182 next_new_line = output.find('\n', prev_new_line + 1) 183 if next_new_line < 0: 184 next_new_line = len(output) TypeError: argument should be integer or bytes-like object, not 'str'
fatemehshmd commented 4 years ago

I ran your code on my Mac laptop and it worked perfectly. But I need to set the whole thing on my station with Windows 10 operating system too. I would really appreciate it if you provide us a setup code which works well on windows too.

kaushikacharya commented 4 years ago

@fatemehshmd

But I need to set the whole thing on my station with Windows 10 operating system too. Have a look at the changes done in https://github.com/AnthonyMRios/pymetamap/pull/39

Though haven't tested on Windows, but I feel pymetamap should now run in Windows too if you have passed input parameter: "sentences" as its not using NamedTemporaryFile.

If you are still facing any issue, we can discuss on the thread: https://github.com/AnthonyMRios/pymetamap/issues/10

But first do check if you are able to run the commands as mentioned in https://metamap.nlm.nih.gov/Installation.shtml e.g. echo "lung cancer" | ./bin/metamap -I

FayZ676 commented 2 years ago

@AnthonyMRios the pymetamap wrapper works like a charm, much appreciated. I am using it to analyze large amounts of medical related data and have noticed that execution halts after 100 calls, I am unable to get passed article 99 in my dataset. Is there a way around this?

dax-westerman commented 10 months ago

I have metamap 2014 running on Windows, and I hit similar issues. I hit an update where the input and output files couldn't be opened for read/write. I made the following updates to resolve on my end: