def extract_concepts(self, sentences=None, ids=None, filename=None,<EOL>restrict_to_sts=None, restrict_to_sources=None):
if (sentences is not None and filename is not None) or(sentences is None and filename is None):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>input_file = None<EOL>if sentences is not None:<EOL><INDENT>input_file = tempfile.NamedTemporaryFile(mode="<STR_LIT:wb>", delete=False)<EOL><DEDENT>else:<EOL><INDENT>input_file = open(filename, '<STR_LIT:r>')<EOL><DEDENT>output_file_name = None<EOL>error = None<EOL>try:<EOL><INDENT>if sentences is not None:<EOL><INDENT>if ids is not None:<EOL><INDENT>for identifier, sentence in zip(ids, sentences):<EOL><INDENT>input_file.write('<STR_LIT>'.format(identifier, sentence).encode('<STR_LIT:utf8>'))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for sentence in sentences:<EOL><INDENT>input_file.write('<STR_LIT>'.format(sentence).encode('<STR_LIT:utf8>'))<EOL><DEDENT><DEDENT>input_file.flush()<EOL><DEDENT>command = ["<STR_LIT>", os.path.join(self.metamap_filename, "<STR_LIT>")]<EOL>if restrict_to_sts:<EOL><INDENT>if isinstance(restrict_to_sts, str):<EOL><INDENT>restrict_to_sts = [restrict_to_sts]<EOL><DEDENT>if len(restrict_to_sts) > <NUM_LIT:0>:<EOL><INDENT>command.append('<STR_LIT>')<EOL>command.append(str('<STR_LIT:U+002C>'.join(restrict_to_sts)))<EOL><DEDENT><DEDENT>if restrict_to_sources:<EOL><INDENT>if isinstance(restrict_to_sources, str):<EOL><INDENT>restrict_to_sources = [restrict_to_sources]<EOL><DEDENT>if len(restrict_to_sources) > <NUM_LIT:0>:<EOL><INDENT>command.append('<STR_LIT>')<EOL>command.append(str('<STR_LIT:U+002C>'.join(restrict_to_sources)))<EOL><DEDENT><DEDENT>if ids is not None:<EOL><INDENT>command.append('<STR_LIT>')<EOL><DEDENT>command.append(input_file.name)<EOL>metamap_process = subprocess.Popen(command, stdout=subprocess.PIPE)<EOL>while metamap_process.poll() is None:<EOL><INDENT>stdout = str(metamap_process.stdout.readline())<EOL>if '<STR_LIT>' in stdout:<EOL><INDENT>metamap_process.terminate()<EOL>error = stdout.rstrip()<EOL><DEDENT><DEDENT>output_file_name, file_extension = os.path.splitext(input_file.name)<EOL>output_file_name += "<STR_LIT:.>" + "<STR_LIT>"<EOL>with open(output_file_name) as fd:<EOL><INDENT>output = fd.read()<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if sentences is not None:<EOL><INDENT>os.remove(input_file.name)<EOL><DEDENT>else:<EOL><INDENT>input_file.close()<EOL><DEDENT>os.remove(output_file_name)<EOL><DEDENT>concepts = CorpusLite.load(output.splitlines())<EOL>return concepts, error<EOL>
extract_concepts takes a list of sentences and ids(optional)
            then returns a list of Concept objects extracted via
            MetaMapLite.

            Supported Options:
                Restrict to Semantic Types --restrict_to_sts
                Restrict to Sources --restrict_to_sources

            For information about the available options visit
            http://metamap.nlm.nih.gov/.

            Note: If an error is encountered the process will be closed
                  and whatever was processed, if anything, will be
                  returned along with the error found.