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

Running error #9

Open
wangyueyao opened this issue Feb 22, 2017 · 37 comments
Open

Running error #9

wangyueyao opened this issue Feb 22, 2017 · 37 comments

Comments

@wangyueyao
Copy link

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
Copy link
Owner

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

@wangyueyao
Copy link
Author

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

@Civiano
Copy link

Civiano commented Aug 16, 2017

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
Copy link
Owner

AnthonyMRios commented Aug 16, 2017

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
Copy link

Civiano commented Sep 1, 2017

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
Copy link
Owner

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
Copy link

Civiano commented Sep 2, 2017

  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
Copy link

nishalpattan commented Nov 2, 2017

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
Copy link
Owner

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
Copy link

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

@nishalpattan
Copy link

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
Copy link
Contributor

kaushikacharya commented Jul 20, 2018

@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
Copy link
Owner

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
Copy link
Contributor

kaushikacharya commented Jul 20, 2018 via email

@AnthonyMRios
Copy link
Owner

Sure. That would be great.

AnthonyMRios pushed a commit that referenced this issue Jul 23, 2018
* 1. Mentioned in bold that Metamap binary path should be absolute. 2.
spelling correction

* asserting if Metamap binary path is not absolute. This handles issue #9

* Update MetaMap.py

modify error message
@kibamin
Copy link

kibamin commented Apr 27, 2019

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
Copy link
Owner

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
Copy link

kibamin commented Apr 28, 2019

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
Copy link
Owner

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
Copy link

kibamin commented Apr 29, 2019

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
Copy link
Contributor

kaushikacharya commented Apr 29, 2019 via email

@AnthonyMRios
Copy link
Owner

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

@lediona
Copy link

lediona commented Nov 22, 2019

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
Copy link
Contributor

kaushikacharya commented Nov 22, 2019

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: #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
Copy link

lediona commented Nov 22, 2019

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

@lediona
Copy link

lediona commented Nov 28, 2019

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
Copy link
Contributor

kaushikacharya commented Nov 28, 2019

@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
Copy link

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
Copy link
Contributor

kaushikacharya commented Dec 6, 2019

@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
Copy link

itSammycodethngy commented Dec 6, 2019 via email

@AnthonyMRios
Copy link
Owner

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

@itSammycodethngy
Copy link

itSammycodethngy commented Dec 6, 2019 via email

@itSammycodethngy
Copy link

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'

kaushikacharya added a commit to kaushikacharya/pymetamap that referenced this issue Dec 13, 2019
…g of python 2 and python 3. Resolves issue AnthonyMRios#9 raised on 11th Dec 2019.
AnthonyMRios pushed a commit that referenced this issue Jan 27, 2020
…g of python 2 and python 3. Resolves issue #9 raised on 11th Dec 2019. (#44)
@fatemehshmd
Copy link

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
Copy link
Contributor

@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 #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: #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
Copy link

FayZ676 commented Jul 30, 2022

@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
Copy link

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:

  • Changed the tempFiles to open 'r+b' (likely overkill)
  • Closed both files after the input_file.flush() to close the file handles
  • Reopened the output_file with mode='r' before output = str(output_file.read()) to open a new file handle
  • in the finally, closed both, then removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests