关闭

Metamap Java Api 使用教程

标签: javaapimatemap
1509人阅读 评论(2) 收藏 举报
Metamap(简称mm)是一个用于识别文本中包含的一体化医学语言系统概念的工具。

mm java api允许通过java程序调用mm的映射引擎,进入mm java api页面(https://mmtx.nlm.nih.gov/JavaApi.shtml

使用mm java api之前需要下载以下工具包:
1)MetaMap Full download
The full version of MetaMap must be downloaded from MetaMap Full Download and installed before installing the Java API distribution.  
2)Java Runtime Environment (JRE) 1.8 or later
Java Runtime Environment (JRE 1.8) or later is the minimum required environment for running the API. Java is available from the "Developer Resources for Java Technology" website (http://www.java.com/).

获取mm java api使用文档:

mm java api版本信息:
1)linux 2016  2014  2013v2  2013
2)windowXP/7  2014  2013v2  2013
3)Mac OS/X 2016  2014  2013v2  2013 v1

安装和调用过程:
根据操作系统的类型,下载相应版本的mm full和mm java api安装包
下载前需要注册一个UMLS账号,账号需要审核,审核时间大约为一天,审核通过后即可登录进行下载。

选择window对应的版本,下载得到两个安装包


将两个安装包解压到同一个根目录下,我选择的是D盘,解压后得到两个文件夹


1)安装mm full
运行D:\public_mm_win32_main_2014\public_mm中的install matemap.bat,弹出窗口

点击 next
如果没有自动匹配jre的路径,在browse中选择jre的安装路径即可,点击next

至此MetaMap安装成功

2)启动 mmserver
启动mmserver之前需要先启动taggerserver
启动方法:运行D:\public_mm_win32_main_2014\public_mm\bin中的skrmedpostctl_start.bat,运行结果如下

启动mmserver
启动方法:在D盘目录下启动命令行窗口(shift+右键→在此处打开命令窗口),弹出命令窗口

第一次输入命令行时,会报错,但是第二次输入相同的命令行,mmserver启动成功(原因不明)

3)在java程序中调用mm server
在eclipse中新建工程,在library中导入下面两个jar包

编写程序(代码如下图),调用mm server,程序正常运行,调用成功。

packageorg.irlab.yxh.test;
importjava.util.List;
importgov.nih.nlm.nls.metamap.Ev;
importgov.nih.nlm.nls.metamap.Mapping;
importgov.nih.nlm.nls.metamap.MetaMapApi;
importgov.nih.nlm.nls.metamap.MetaMapApiImpl;
importgov.nih.nlm.nls.metamap.Negation;
importgov.nih.nlm.nls.metamap.PCM;
importgov.nih.nlm.nls.metamap.Result;
importgov.nih.nlm.nls.metamap.Utterance;

publicclassMetaMapDemo {

      publicstaticvoidmain(String[] args) throws Exception{           
            Stringinput = "high blood pressure"; //待映射文本
            MetaMapApiapi = newMetaMapApiImpl();
            System.out.println("api instanciated");  //api实例化      
            List<Result>resultList = api.processCitationsFromString(input);            
            Resultresult = resultList.get(0);
            List<Negation>negations = result.getNegationList();            
           for(Negation negation : negations){
                  System.out.println("conceptposition:"+negation.getConceptPositionList());
                  System.out.println("concept pairs:"+negation.getConceptPairList());
                  System.out.println("trigger positions: "+negation.getTriggerPositionList());
                  System.out.println("trigger: "+negation.getTrigger());
                  System.out.println("type: "+negation.getType());
            }
            
           for(Utterance utterance : result .getUtteranceList()) {
                  System.out.println("Utterance:");
                  System.out.println("  Id: "+ utterance.getId());
                  System.out.println("  Utterance text: "+ utterance.getString());
                  System.out.println("  Position: "+ utterance.getPosition());
                        for(PCM pcm : utterance .getPCMList()) {
                              System.out.println("Mappings:");
                              for(Mapping map : pcm .getMappingList()) {
                                    System.out.println("Phrase:");
                                    System.out.println("  Map Score: "+ map.getScore());
                                    for(Ev mapEv : map .getEvList()) {
                                          System.out.println("  Score: "+ mapEv.getScore());
                                          System.out.println("  Concept Id: "+ mapEv.getConceptId());
                                          System.out.println("  Concept Name: "+ mapEv.getConceptName());
                                          System.out.println("  Preferred Name: "+ mapEv.getPreferredName());
                                          System.out.println("  Matched Words: "+ mapEv.getMatchedWords());
                                          System.out.println("  Semantic Types: "+ mapEv.getSemanticTypes());
                                          System.out.println("  MatchMap: "+ mapEv.getMatchMap());
                                          System.out.println("  MatchMap alt. repr.: "+ mapEv.getMatchMapList());
                                          System.out.println("  is Head?: "+ mapEv.isHead());
                                          System.out.println("  is Overmatch?: "+ mapEv.isOvermatch());
                                          System.out.println("  Sources: "+ mapEv.getSources());
                                          System.out.println("  Positional Info: "+ mapEv.getPositionalInfo());
                                    }
                        }
                  }
            }
            
      }
      
}

输出的结果:
api instanciated
Utterance:
  Id: 00000000.tx.1
  Utterance text: high blood pressure
  Position: (0, 19)
Mappings:
Phrase:
  Map Score: -1000
  Score: -1000
  Concept Id: C0020538
  Concept Name: Blood Pressure, High
  Preferred Name: Hypertensive disease
  Matched Words: [high, blood, pressure]
  Semantic Types: [dsyn]
  MatchMap: [[[1, 3], [1, 3], 0]]
  MatchMap alt. repr.: [[[phrase start: 1, phrase end: 3], [concept start: 1, concept end: 3], lexical variation: 0]]
  is Head?: true
  is Overmatch?: false
  Sources: [AOD, MSH, MTH, NCI, NLMSubSyn, OMIM, SNM, SNMI, SNOMEDCT_US]
  Positional Info: [(0, 19)]
Phrase:
  Map Score: -1000
  Score: -1000
  Concept Id: C2926615
  Concept Name: High blood pressure
  Preferred Name: Ever told by doctor or nurse that you have high blood pressure:Finding:Point in time:^Patient:Ordinal
  Matched Words: [high, blood, pressure]
  Semantic Types: [clna]
  MatchMap: [[[1, 3], [1, 3], 0]]
  MatchMap alt. repr.: [[[phrase start: 1, phrase end: 3], [concept start: 1, concept end: 3], lexical variation: 0]]
  is Head?: true
  is Overmatch?: false
  Sources: [LNC, NLMSubSyn]
  Positional Info: [(0, 19)]

至此MetaMap Java API调用成功!
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1516次
    • 积分:25
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章存档
    阅读排行
    最新评论