⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 medlinecitation.java

📁 一个自然语言处理的Java开源工具包。LingPipe目前已有很丰富的功能
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            sb.append("\n");        }        if (mOtherAbstracts.length > 0) {            sb.append("     OTHER ABSTRACTS="                      + Arrays.asList(mOtherAbstracts));            sb.append("\n");        }        if (mCommentOrCorrections.length > 0) {            sb.append("     COMMENTS OR CORRECTIONS="                      + Arrays.asList(mCommentOrCorrections));            sb.append("\n");        }        // sb.append(" XML=");        // sb.append(xmlString());        return sb.toString();    }    void setXMLString(String xmlString) {        mXMLString = xmlString;    }    public static MedlineCitation parse(InputSource inSource,                                        XMLReader xmlReader)        throws IOException, SAXException {        DelegatingHandler handler = new DelegatingHandler();        Handler citationHandler = new Handler(handler);        handler.setDelegate(MedlineCitationSet.MEDLINE_CITATION_ELT,                            citationHandler);        xmlReader.setContentHandler(handler);        xmlReader.parse(inSource);        return citationHandler.getCitation();    }    // <!ELEMENT MedlineCitation (%NlmDcmsID.Ref;, %PMID.Ref;,    //                            %DateCreated.Ref;, DateCompleted?,    //                            DateRevised?, Article, MedlineJournalInfo,    //                            ChemicalList?,    //                            CitationSubset*, CommentsCorrections?,    //                            GeneSymbolList?,    //                            MeshHeadingList?, NumberOfReferences?,    //                            PersonalNameSubjectList?,    //                            OtherID*, OtherAbstract*, KeywordList*,    //                            SpaceFlightMission*,    //                            InvestigatorList?, GeneralNote*)>    // <!ATTLIST MedlineCitation    //           Owner %Owner; "NLM"    //           Status %Status; >    // <!ENTITY % Owner "(NLM | NASA | PIP | KIE | HSR | HMD | SIS | NOTNLM)">    // <!ENTITY % Status "(Completed | In-Process | PubMed-not-MEDLINE |    //                    In-Data-Review | Publisher) #REQUIRED">    // <!ENTITY % NlmDcmsID.Ref "NlmDcmsID?">    // <!ENTITY % PMID.Ref "PMID">    // <!ENTITY % PubDate.Ref "PubDate">    // <!ENTITY % DateCreated.Ref "DateCreated">    // <!ELEMENT PersonalNameSubjectList (PersonalNameSubject+)>    // returned citation will have null XML bytes, which is OK    // <!ELEMENT GeneSymbol (#PCDATA)>    // <!ELEMENT GeneSymbolList (GeneSymbol+)>    static class Handler extends DelegateHandler {        private String mOwner;        private String mStatus;        private final TextAccumulatorHandler mNlmDcmsIDHandler            = new TextAccumulatorHandler();        private final TextAccumulatorHandler mPMIDHandler            = new TextAccumulatorHandler();        private final DateHandler mDateCreatedHandler;        private final DateHandler mDateCompletedHandler;        private final DateHandler mDateRevisedHandler;        private final Article.Handler mArticleHandler;        private final JournalInfo.Handler mJournalInfoHandler;        private final ArrayList mChemicalList = new ArrayList();        private final Chemical.Handler mChemicalHandler;        private final ArrayList mCitationSubsetList = new ArrayList();        private final TextAccumulatorHandler mCitationSubsetHandler            = new TextAccumulatorHandler();        private final ArrayList mCommentOrCorrectionList = new ArrayList();        private final ArrayList mGeneSymbolList = new ArrayList();        private final TextAccumulatorHandler mGeneSymbolHandler            = new TextAccumulatorHandler();        private final MeshHeading.ListHandler mMeshHeadingListHandler;        private final TextAccumulatorHandler mNumberOfReferencesHandler            = new TextAccumulatorHandler();        private final ArrayList mPersonalNameSubjectList = new ArrayList();        private final PersonalNameSubject.Handler mPersonalNameSubjectHandler;        private final ArrayList mOtherIDList = new ArrayList();        private final OtherID.Handler mOtherIDHandler;        private final ArrayList mOtherAbstractList = new ArrayList();        private final OtherAbstract.Handler mOtherAbstractHandler;        private final ArrayList mKeywordListList = new ArrayList();        private final KeywordList.Handler mKeywordListHandler;        private final ArrayList mSpaceFlightMissionList = new ArrayList();        private final TextAccumulatorHandler mSpaceFlightMissionHandler            = new TextAccumulatorHandler();        private final ArrayList mInvestigatorList = new ArrayList();        private final Investigator.Handler mInvestigatorHandler;        private final ArrayList mGeneralNoteList = new ArrayList();        private final GeneralNote.Handler mGeneralNoteHandler;        public Handler(DelegatingHandler delegator) {            super(delegator);            mDateCreatedHandler = new DateHandler(delegator);            mDateCompletedHandler = new DateHandler(delegator);            mDateRevisedHandler = new DateHandler(delegator);            mArticleHandler = new Article.Handler(delegator);            mJournalInfoHandler = new JournalInfo.Handler(delegator);            mChemicalHandler = new Chemical.Handler(delegator);            mMeshHeadingListHandler                = new MeshHeading.ListHandler(delegator);            mPersonalNameSubjectHandler                = new PersonalNameSubject.Handler(delegator);            mOtherIDHandler = new OtherID.Handler();            mOtherAbstractHandler = new OtherAbstract.Handler(delegator);            mKeywordListHandler = new KeywordList.Handler(delegator);            mInvestigatorHandler = new Investigator.Handler(delegator);            mGeneralNoteHandler = new GeneralNote.Handler();            setDelegate(MedlineCitationSet.NLM_DCMS_ID_ELT,                        mNlmDcmsIDHandler);            setDelegate(MedlineCitationSet.PMID_ELT,mPMIDHandler);            setDelegate(MedlineCitationSet.DATE_CREATED_ELT,                        mDateCreatedHandler);            setDelegate(MedlineCitationSet.DATE_COMPLETED_ELT,                        mDateCompletedHandler);            setDelegate(MedlineCitationSet.DATE_REVISED_ELT,                        mDateRevisedHandler);            setDelegate(MedlineCitationSet.CHEMICAL_ELT,                        mChemicalHandler);            setDelegate(MedlineCitationSet.CITATION_SUBSET_ELT,                        mCitationSubsetHandler);            setDelegate(MedlineCitationSet.MESH_HEADING_LIST_ELT,                        mMeshHeadingListHandler);            setDelegate(MedlineCitationSet.NUMBER_OF_REFERENCES_ELT,                        mNumberOfReferencesHandler);            setDelegate(MedlineCitationSet.PERSONAL_NAME_SUBJECT_ELT,                        mPersonalNameSubjectHandler);            setDelegate(MedlineCitationSet.KEYWORD_LIST_ELT,                        mKeywordListHandler);            setDelegate(MedlineCitationSet.GENERAL_NOTE_ELT,                        mGeneralNoteHandler);            setDelegate(MedlineCitationSet.GENE_SYMBOL_ELT,                        mGeneSymbolHandler);            setDelegate(MedlineCitationSet.SPACE_FLIGHT_MISSION_ELT,                        mSpaceFlightMissionHandler);            setDelegate(MedlineCitationSet.OTHER_ID_ELT,                        mOtherIDHandler);            setDelegate(MedlineCitationSet.INVESTIGATOR_ELT,                        mInvestigatorHandler);            setDelegate(MedlineCitationSet.OTHER_ABSTRACT_ELT,                        mOtherAbstractHandler);            for (int i = 0;                 i < MedlineCitationSet.COMMENT_OR_CORRECTIONS.length; ++i) {                String elt = MedlineCitationSet.COMMENT_OR_CORRECTIONS[i];                setDelegate(elt,new CommentOrCorrection.Handler(elt,                                                                delegator));            }            setDelegate(MedlineCitationSet.MEDLINE_JOURNAL_INFO_ELT,                        mJournalInfoHandler);            setDelegate(MedlineCitationSet.ARTICLE_ELT,mArticleHandler);        }        public void finishDelegate(String qName, DefaultHandler handler) {            if (qName.equals(MedlineCitationSet.CITATION_SUBSET_ELT)) {                mCitationSubsetList.add(mCitationSubsetHandler.getText());            } else if (qName.equals(MedlineCitationSet.CHEMICAL_ELT)) {                mChemicalList.add(mChemicalHandler.getChemical());            } else if (qName.equals(MedlineCitationSet.KEYWORD_LIST_ELT)) {                mKeywordListList.add(mKeywordListHandler.getKeywordList());            } else if (qName.equals(MedlineCitationSet.GENERAL_NOTE_ELT)) {                mGeneralNoteList.add(mGeneralNoteHandler.getNote());            } else if (qName.equals(MedlineCitationSet.GENE_SYMBOL_ELT)) {                mGeneSymbolList.add(mGeneSymbolHandler.getText());            } else if (qName.equals(MedlineCitationSet                                    .SPACE_FLIGHT_MISSION_ELT)) {                mSpaceFlightMissionList.add(mSpaceFlightMissionHandler                                            .getText());            } else if (qName.equals(MedlineCitationSet.OTHER_ID_ELT)) {                mOtherIDList.add(mOtherIDHandler.getOtherID());            } else if (qName.equals(MedlineCitationSet.INVESTIGATOR_ELT)) {                mInvestigatorList.add(mInvestigatorHandler.getInvestigator());            } else if (qName.equals(MedlineCitationSet.OTHER_ABSTRACT_ELT)) {                mOtherAbstractList.add(mOtherAbstractHandler                                       .getOtherAbstract());            } else if (MedlineCitationSet.COMMENT_OR_CORRECTION_SET                       .contains(qName)) {                CommentOrCorrection.Handler ccHandler                    = (CommentOrCorrection.Handler) handler;                mCommentOrCorrectionList.add(ccHandler                                             .getCommentOrCorrection());            } else if (qName.equals(MedlineCitationSet                                    .PERSONAL_NAME_SUBJECT_ELT)) {                mPersonalNameSubjectList                    .add(mPersonalNameSubjectHandler                         .getPersonalNameSubject());            }        }        public void startDocument() throws SAXException {            super.startDocument();            mNlmDcmsIDHandler.reset();            mPMIDHandler.reset();            mDateCreatedHandler.reset();            mDateCompletedHandler.reset();            mDateRevisedHandler.reset();            mCitationSubsetList.clear();            mChemicalList.clear();            mKeywordListList.clear();            mKeywordListHandler.reset();            mGeneralNoteList.clear();            mGeneSymbolList.clear();            mSpaceFlightMissionList.clear();            mOtherIDList.clear();            mInvestigatorList.clear();            mOtherAbstractList.clear();            mCommentOrCorrectionList.clear();            mMeshHeadingListHandler.reset();            mNumberOfReferencesHandler.reset();            mPersonalNameSubjectList.clear();        }        public void startElement(String namespaceURI, String localName,                                 String qName, Attributes atts)            throws SAXException {            if (qName.equals(MedlineCitationSet.MEDLINE_CITATION_ELT)) {                mOwner = atts.getValue(MedlineCitationSet.OWNER_ATT);                mStatus = atts.getValue(MedlineCitationSet.STATUS_ATT);            } else {                super.startElement(namespaceURI,localName,qName,atts);            }        }        public MedlineCitation getCitation() {            String[] citationSubsets = new String[mCitationSubsetList.size()];            mCitationSubsetList.toArray(citationSubsets);            Chemical[] chemicals = new Chemical[mChemicalList.size()];            mChemicalList.toArray(chemicals);            KeywordList[] keywordLists                = new KeywordList[mKeywordListList.size()];            mKeywordListList.toArray(keywordLists);            GeneralNote[] generalNotes                = new GeneralNote[mGeneralNoteList.size()];            mGeneralNoteList.toArray(generalNotes);            String[] geneSymbols = new String[mGeneSymbolList.size()];            mGeneSymbolList.toArray(geneSymbols);            String[] spaceFlightMissions                = new String[mSpaceFlightMissionList.size()];            mSpaceFlightMissionList.toArray(spaceFlightMissions);            OtherID[] otherIDs = new OtherID[mOtherIDList.size()];            mOtherIDList.toArray(otherIDs);            Investigator[] investigators                = new Investigator[mInvestigatorList.size()];            mInvestigatorList.toArray(investigators);            OtherAbstract[] otherAbstracts                = new OtherAbstract[mOtherAbstractList.size()];            mOtherAbstractList.toArray(otherAbstracts);            CommentOrCorrection[] commentOrCorrections                = new CommentOrCorrection[mCommentOrCorrectionList.size()];            mCommentOrCorrectionList.toArray(commentOrCorrections);            PersonalNameSubject[] personalNameSubjects                = new PersonalNameSubject[mPersonalNameSubjectList.size()];            mPersonalNameSubjectList.toArray(personalNameSubjects);            return new MedlineCitation(mOwner,                                       mStatus,                                       mNlmDcmsIDHandler.getText(),                                       mPMIDHandler.getText(),                                       mDateCreatedHandler.getDate(),                                       mDateCompletedHandler.getDate(),                                       mDateRevisedHandler.getDate(),                                       chemicals,                                       citationSubsets,                                       mMeshHeadingListHandler                                       .getMeshHeadings(),                                       mNumberOfReferencesHandler.getText(),                                       personalNameSubjects,                                       keywordLists,                                       generalNotes,                                       geneSymbols,                                       spaceFlightMissions,                                       otherIDs,                                       investigators,                                       otherAbstracts,                                       commentOrCorrections,                                       mJournalInfoHandler.getJournalInfo(),                                       mArticleHandler.getArticle());        }    }    // <!ENTITY % normal.date "(Year,Month,Day,(Hour,(Minute,Second?)?)?)">    static class DateHandler extends DelegateHandler {        private final DateFormat mDateFormat            = new SimpleDateFormat("yyyy.MM.dd",Locale.ENGLISH);        private final TextAccumulatorHandler mYearHandler            = new TextAccumulatorHandler();        private final TextAccumulatorHandler mMonthHandler            = new TextAccumulatorHandler();        private final TextAccumulatorHandler mDayHandler            = new TextAccumulatorHandler();        public DateHandler(DelegatingHandler delegator) {            super(delegator);            setDelegate(MedlineCitationSet.YEAR_ELT,mYearHandler);            setDelegate(MedlineCitationSet.MONTH_ELT,mMonthHandler);            setDelegate(MedlineCitationSet.DAY_ELT,mDayHandler);        }        public void startDocument() throws SAXException {            super.startDocument();            reset();        }        public void reset() {            mYearHandler.reset();            mMonthHandler.reset();            mDayHandler.reset();        }        public Date getDate() {            String yyyy = mYearHandler.getText();            String mm = mMonthHandler.getText();            String dd = mDayHandler.getText();            String date = yyyy + '.' + mm + '.' + dd;            if (date.length() < 3) return null;            try {                return mDateFormat.parse(date);            } catch (ParseException e) {                // log                return null;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -