public virtual string GetXml()

        {
            StringBuilder xmlOut = new StringBuilder();

            if (lexRecordObjs_ != null)

            {
                xmlOut.Append(LexRecord.GetXmlHeader());
                xmlOut.Append(GlobalVars.LS_STR);
                xmlOut.Append(LexRecord.GetXmlRootBeginTag());
                xmlOut.Append(GlobalVars.LS_STR);
                for (int i = 0; i < lexRecordObjs_.Count; i++)

                {
                    LexRecord temp = (LexRecord)lexRecordObjs_[i];
                    xmlOut.Append(temp.GetXml(1));
                }

                xmlOut.Append(LexRecord.GetXmlRootEndTag());
                xmlOut.Append(GlobalVars.LS_STR);
            }

            return(xmlOut.ToString());
        }
        public static bool CheckSpacesForList(LexRecord lexRecord, int contentType)

        {
            bool validFlag = true;


            List <string> inList = LexRecordUtil.GetListFromLexRecord(lexRecord, contentType);

            for (int i = 0; i < inList.Count; i++)

            {
                string inItem    = (string)inList[i];
                string newInItem = StringTrim(inItem);
                if (!newInItem.Equals(inItem))

                {
                    validFlag = false;
                    ErrMsgUtilLexRecord.AddContentErrMsg(contentType, 7, inItem, lexRecord);


                    LexRecordUtil.SetItemInListInLexRecordAt(lexRecord, contentType, newInItem, i);
                }
            }

            return(validFlag);
        }
        public static bool CheckContents(LexRecord lexRecord)

        {
            bool validFlag = CheckCont.CheckContent.CheckDuplicatesForList(lexRecord, 7);

            return validFlag;
        }
        public static bool CheckContent(LexRecord lexRecord)

        {
            bool validFlag = CheckIllegalCat(lexRecord);

            return(validFlag);
        }
Exemple #5
0
        /**
         * check if this record has a standard (regular) inflection
         *
         * @param record
         * @param simplenlg
         *            syntactic category
         * @return true if standard (regular) inflection
         */
        private bool standardInflections(LexRecord record, LexicalCategory category)
        {
            List <string> variants = null;

            switch (category.GetLexicalCategory())
            {
            case LexicalCategory.LexicalCategoryEnum.NOUN:
                variants = record.GetCatEntry().GetNounEntry().GetVariants();
                break;

            case LexicalCategory.LexicalCategoryEnum.ADJECTIVE:
                variants = record.GetCatEntry().GetAdjEntry().GetVariants();
                break;

            case LexicalCategory.LexicalCategoryEnum.ADVERB:
                variants = record.GetCatEntry().GetAdvEntry().GetVariants();
                break;

            case LexicalCategory.LexicalCategoryEnum.MODAL:
                variants = record.GetCatEntry().GetModalEntry().GetVariant();
                break;

            case LexicalCategory.LexicalCategoryEnum.VERB:
                if (record.GetCatEntry().GetVerbEntry() != null)     // aux verbs (eg  be) won't  have verb entries
                {
                    variants = record.GetCatEntry().GetVerbEntry().GetVariants();
                }
                break;
            }

            return(variants != null && variants.Contains("reg"));
        }
        public virtual List <string> GetSpellingVars(string separator)

        {
            List <string> spellingVars = new List <string>();

            if (lexRecordObjs_ != null)

            {
                for (int i = 0; i < lexRecordObjs_.Count; i++)

                {
                    LexRecord temp     = (LexRecord)lexRecordObjs_[i];
                    string    eui      = temp.GetEui();
                    string    category = temp.GetCategory();
                    spellingVars.Add(temp.GetBase() + separator + eui + separator + category);

                    List <string> tempSpellVars = temp.GetSpellingVars();
                    for (int j = 0; j < tempSpellVars.Count; j++)

                    {
                        string tempSpellVar = (string)tempSpellVars[j];
                        spellingVars.Add(tempSpellVar + separator + eui + separator + category);
                    }
                }
            }

            return(spellingVars);
        }
Exemple #7
0
        /**
         * check if this record has a standard (regular) inflection
         *
         * @param record
         * @param simplenlg
         *            syntactic category
         * @return true if standard (regular) inflection
         */

        private bool standardInflections(LexRecord record, LexicalCategory category)
        {
            List <string> variants = null;

            switch (((LexicalCategory)category).lexType)
            {
            case LexicalCategoryEnum.NOUN:
                variants = record.GetCatEntry().GetNounEntry().GetVariants();
                break;

            case LexicalCategoryEnum.ADJECTIVE:
                variants = record.GetCatEntry().GetAdjEntry().GetVariants();
                break;

            case LexicalCategoryEnum.ADVERB:
                variants = record.GetCatEntry().GetAdvEntry().GetVariants();
                break;

            case LexicalCategoryEnum.MODAL:
                variants = record.GetCatEntry().GetModalEntry().GetVariant();
                break;

            case LexicalCategoryEnum.VERB:
                if (record.GetCatEntry().GetVerbEntry() != null)     // aux verbs (eg
                // be) won't
                // have verb
                // entries
                {
                    variants = record.GetCatEntry().GetVerbEntry().GetVariants();
                }
                break;
            }

            return(notEmpty(variants) && variants.contains("reg"));
        }
        public virtual List <string> GetInflVars()

        {
            List <string> inflVars = new List <string>();

            if (lexRecordObjs_ != null)

            {
                for (int i = 0; i < lexRecordObjs_.Count; i++)

                {
                    LexRecord temp = (LexRecord)lexRecordObjs_[i];

                    List <InflVar> inflValues = temp.GetInflVarsAndAgreements().GetInflValues();
                    for (int j = 0; j < inflValues.Count; j++)

                    {
                        InflVar inflVar = (InflVar)inflValues[j];
                        inflVars.Add(inflVar.GetVar());
                    }
                }
            }

            return(inflVars);
        }
        public virtual List <string> GetInflVars(string separator)

        {
            List <string> inflVars = new List <string>();

            if (lexRecordObjs_ != null)

            {
                for (int i = 0; i < lexRecordObjs_.Count; i++)

                {
                    LexRecord temp = (LexRecord)lexRecordObjs_[i];

                    List <InflVar> inflValues = temp.GetInflVarsAndAgreements().GetInflValues();
                    for (int j = 0; j < inflValues.Count; j++)

                    {
                        InflVar inflVar = (InflVar)inflValues[j];


                        string inflVarDetail = inflVar.GetVar() + separator + inflVar.GetCat() + separator +
                                               inflVar.GetInflection() + separator + inflVar.GetEui() + separator +
                                               inflVar.GetUnInfl() + separator + inflVar.GetCit() + separator +
                                               inflVar.GetType();
                        inflVars.Add(inflVarDetail);
                    }
                }
            }

            return(inflVars);
        }
        public static List<string> GetListFromLexRecord(LexRecord lexRecord, int contentType)
        {
            List<string> outList = new List<string>();
            switch (contentType)

            {
                case 2:
                    outList = lexRecord.GetSpellingVars();
                    break;
                case 5:
                    outList = lexRecord.GetVariants();
                    break;
                case 6:
                    outList = lexRecord.GetNominalizations();
                    break;
                case 7:
                    outList = lexRecord.GetAbbreviations();
                    break;
                case 8:
                    outList = lexRecord.GetAcronyms();
                    break;
            }

            return outList;
        }
        public static bool CheckDuplicatesForList(LexRecord lexRecord, int contentType)

        {
            bool validFlag = true;


            List <string> inList = LexRecordUtil.GetListFromLexRecord(lexRecord, contentType);
            List <string> uList  = new List <string>();

            for (int i = 0; i < inList.Count; i++)

            {
                string inItem = (string)inList[i];

                if (uList.Contains(inItem) == true)

                {
                    validFlag = false;
                    ErrMsgUtilLexRecord.AddContentErrMsg(contentType, 2, inItem, lexRecord);
                }
                else

                {
                    uList.Add(inItem);
                }
            }

            if (!validFlag)

            {
                LexRecordUtil.SetListInLexRecord(lexRecord, contentType, uList);
            }

            return(validFlag);
        }
        private static List <LexRecord> GetLexRecords(Node node)


        {
            List <LexRecord> lexRecords = new List <LexRecord>();

            LexRecord lexRecord = null;
            CatEntry  catEntry  = null;

            for (Node records = node.FirstChild; records != null; records = records.NextSibling)


            {
                for (Node record = records.FirstChild; record != null; record = record.NextSibling)


                {
                    if (record.NodeType == XmlNodeType.Element)

                    {
                        if (record.Name.Equals("lexRecord"))

                        {
                            lexRecord = new LexRecord();
                            GetLexRecord(record, lexRecord, catEntry);
                        }

                        lexRecords.Add(lexRecord);
                    }
                }
            }

            return(lexRecords);
        }
        public static bool StaticCheckLexRecord(LexRecord lexRecord, HashSet <string> irregExpEuiList, bool checkEuiFlag)

        {
            ErrMsgUtil.ResetErrMsg();

            bool euiFlag = true;

            if (checkEuiFlag == true)

            {
                euiFlag = CheckEui.CheckContent(lexRecord);
            }

            bool citFlag = CheckCitation.CheckContent(lexRecord);
            bool svFlag  = CheckSpellingVars.CheckContent(lexRecord);
            bool catFlag = CheckCategory.CheckContent(lexRecord);
            bool varFlag = CheckVariants.CheckContent(lexRecord);
            bool nomFlag = CheckNominalizations.CheckContent(lexRecord);
            bool abbFlag = CheckAbbreviations.CheckContent(lexRecord);
            bool acrFlag = CheckAcronyms.CheckContent(lexRecord);

            bool citFlag2 = CheckCitation.CheckContents(lexRecord);
            bool svFlag2  = CheckSpellingVars.CheckContents(lexRecord);
            bool varFlag2 = CheckVariants.CheckContents(lexRecord, irregExpEuiList);

            bool nomFlag2  = CheckNominalizations.CheckContents(lexRecord);
            bool abbFlag2  = CheckAbbreviations.CheckContents(lexRecord);
            bool acrFlag2  = CheckAcronyms.CheckContents(lexRecord);
            bool validFlag = (euiFlag) && (citFlag) && (svFlag) && (catFlag) && (varFlag) && (nomFlag) && (abbFlag) &&
                             (acrFlag) && (citFlag2) && (svFlag2) && (varFlag2) && (nomFlag2) && (abbFlag2) &&
                             (acrFlag2);


            return(validFlag);
        }
Exemple #14
0
        public virtual string GetResultStrByBase(string @base, int baseBy, long category, bool showQuery, string query,
                                                 bool noOutputFlag, string noOutputMsg, bool showTotalRecNum, int lexRecordFormat, string fieldSep)
        {
            LexAccessApiResult lexAccessApiResult = null;

            if ((!ReferenceEquals(@base, null)) && (@base.Length > 0))

            {
                lexAccessApiResult = GetLexRecordsByBase(@base, baseBy);
            }

            List <LexRecord> newLexRecordObjs = new List <LexRecord>();

            if (category < 2047L)

            {
                List <LexRecord> lexRecordObjs = lexAccessApiResult.GetJavaObjs();
                for (int i = 0; i < lexRecordObjs.Count; i++)

                {
                    LexRecord temp     = (LexRecord)lexRecordObjs[i];
                    long      catValue = Category.ToValue(temp.GetCategory());
                    if (BitMaskBase.Contains(category, catValue) == true)

                    {
                        newLexRecordObjs.Add(temp);
                    }
                }

                lexAccessApiResult.SetJavaObjs(newLexRecordObjs);
            }

            return(FormatResultToStr(lexAccessApiResult, @base, showQuery, query, noOutputFlag, noOutputMsg,
                                     showTotalRecNum, lexRecordFormat, fieldSep));
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void CheckLexRecords(java.util.Vector<gov.nih.nlm.nls.lexCheck.Lib.LexRecord> lexRecords, java.io.BufferedWriter out, java.io.BufferedWriter dupOut, boolean verbose, java.util.Hashtable<String, java.util.HashSet<String>> dupRecExpList, java.util.HashSet<String> notBaseFormSet) throws java.io.IOException
        public static void CheckLexRecords(List <LexRecord> lexRecords, System.IO.StreamWriter @out,
                                           System.IO.StreamWriter dupOut, bool verbose, Dictionary <string, HashSet <string> > dupRecExpList,
                                           HashSet <string> notBaseFormSet)


        {
            if (verbose == true)

            {
                Console.WriteLine("===== Check Lexicon Cross-Ref Contents =====");
            }

            ErrMsgUtil.ResetErrMsg();
            bool validFlag = true;

            bool dupEuiFlag = CrossCheckDupEuis.Check(lexRecords);

            bool dupRecFlag = CrossCheckDupLexRecords.Check(lexRecords, dupRecExpList, dupOut, verbose);

            validFlag = (dupEuiFlag) && (dupRecFlag);

            int recSize = lexRecords.Count;

            for (int i = 0; i < recSize; i++)

            {
                LexRecord lexRecord = (LexRecord)lexRecords[i];

                bool nomFlag = CrossCheckNomEui.Check(lexRecord);


                bool abbFlag = CrossCheckAbbEui.Check(lexRecord, notBaseFormSet);

                bool acrFlag = CrossCheckAcrEui.Check(lexRecord, notBaseFormSet);
                validFlag = (validFlag) && (nomFlag) && (abbFlag) && (acrFlag);

                if (@out != null)

                {
                    string text = lexRecord.GetText();
                    @out.Write(text);
                }
            }

            bool symFlag = CrossCheckNomSym.Check(lexRecords);

            validFlag = (symFlag) && (validFlag);


            if (!validFlag)

            {
                Console.WriteLine(ErrMsgUtil.GetErrMsg());
            }

            Console.WriteLine("----- Total lexRecords checked: " + recSize);
            Console.WriteLine("----- cross-ref content error type stats -----");
            Console.WriteLine(ErrMsgUtilLexicon.GetErrStats());
        }
 public static string GetLexRecordInfo(LexRecord lexRecord)
 {
     string eui = lexRecord.GetEui();
     string cat = lexRecord.GetCategory();
     string @base = lexRecord.GetBase();
     string info = eui + "|" + @base + "|" + cat;
     return info;
 }
        public virtual void Update(LexRecord lexObj, string token)

        {
            int    index    = token.IndexOf("\t", StringComparison.Ordinal);
            string negative = token.Substring(index + 1);

            lexObj.GetCatEntry().GetAdvEntry().SetNegative(negative);
        }
        public static bool CheckContent(LexRecord lexRecord)

        {
            bool spaceFlag = CheckCont.CheckContent.CheckSpacesForList(lexRecord, 7);

            bool validFlag = spaceFlag;
            return validFlag;
        }
        private static bool CheckGlreg(LexRecord lexRecord)

        {
            string @base     = lexRecord.GetBase();
            bool   validFlag = CheckEntry.CheckGlreg(lexRecord, @base, 1);

            return(validFlag);
        }
Exemple #20
0
        /***********************************************************************************/
        // The following methods map codes in the NIH Specialist Lexicon
        // into the codes used in simplenlg
        /***********************************************************************************/

        /**
         * get the simplenlg LexicalCategory of a record
         *
         * @param cat
         * @return
         */
        private LexicalCategory getSimplenlgCategory(LexRecord record)
        {
            string cat = record.GetCategory();

            if (cat == null)
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ANY));
            }
            else if (cat.Equals("noun", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN));
            }
            else if (cat.Equals("verb", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));
            }
            else if (cat.Equals("aux", StringComparison.OrdinalIgnoreCase) && string.Equals(record.GetBase(), "be", StringComparison.CurrentCultureIgnoreCase))
            { // return aux "be" as a VERB
                // not needed for other aux "have" and "do", they have a verb entry
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB));
            }
            else if (cat.Equals("adj", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE));
            }
            else if (cat.Equals("adv", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB));
            }
            else if (cat.Equals("pron", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PRONOUN));
            }
            else if (cat.Equals("det", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.DETERMINER));
            }
            else if (cat.Equals("prep", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.PREPOSITION));
            }
            else if (cat.Equals("conj", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.CONJUNCTION));
            }
            else if (cat.Equals("compl", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.COMPLEMENTISER));
            }
            else if (cat.Equals("modal", StringComparison.OrdinalIgnoreCase))
            {
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.MODAL));
            }
            else
            { // return ANY for other cats
                return(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ANY));
            }
        }
Exemple #21
0
        public static bool CheckContents(LexRecord lexRecord)

        {
            bool dupFlag = CheckCont.CheckContent.CheckDuplicatesForList(lexRecord, 8);

            bool validFlag = dupFlag;

            return(validFlag);
        }
        public static bool CheckContent(LexRecord lexRecord)

        {
            bool spaceFlag = CheckCont.CheckContent.CheckSpacesForItem(lexRecord, 1);

            bool validFlag = spaceFlag;

            return(validFlag);
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void CheckLexRecords(java.util.Vector<gov.nih.nlm.nls.lexCheck.Lib.LexRecord> lexRecords, java.io.BufferedWriter out, boolean verbose, java.util.HashSet<String> irregExpEuiList) throws Exception
        public static void CheckLexRecords(List <LexRecord> lexRecords, System.IO.StreamWriter @out, bool verbose,
                                           HashSet <string> irregExpEuiList)


        {
            int errRecordNo = 0;
            int okRecordNo  = 0;
            int recSize     = lexRecords.Count;

            if (verbose == true)

            {
                Console.WriteLine("===== Check LexRecord Contents =====");
            }

            if (lexRecords.Count > 0)

            {
                for (int i = 0; i < recSize; i++)

                {
                    LexRecord lexRecord = (LexRecord)lexRecords[i];
                    if (verbose == true)

                    {
                        Console.WriteLine("--- Checking: " + lexRecord.GetEui() + " ---");
                    }

                    if (!StaticCheckLexRecord(lexRecord, irregExpEuiList))

                    {
                        Console.WriteLine(ErrMsgUtil.GetErrMsg());
                        errRecordNo++;
                    }
                    else

                    {
                        okRecordNo++;
                    }

                    if (@out != null)

                    {
                        string text = lexRecord.GetText();
                        @out.Write(text);
                    }
                }
            }

            Console.WriteLine("----- Total lexRecords checked: " + recSize);

            Console.WriteLine("--- lexRecord has no error: " + okRecordNo);
            Console.WriteLine("--- lexRecord has error(s): " + errRecordNo);
            Console.WriteLine("----- content error type stats -----");
            Console.WriteLine(ErrMsgUtilLexRecord.GetErrStats());
        }
Exemple #24
0
        public static bool CheckContents(LexRecord lexRecord)

        {
            bool dupFlag   = CheckDuplicates(lexRecord);
            bool glregFlag = CheckGlreg(lexRecord);
            bool regdFlag  = CheckRegd(lexRecord);
            bool validFlag = (dupFlag) && (glregFlag) && (regdFlag);

            return(validFlag);
        }
        public static void SetItemInLexRecord(LexRecord lexRecord, int contentType, string item)
        {
            switch (contentType)

            {
                case 1:
                    lexRecord.SetBase(item);
                    break;
            }
        }
Exemple #26
0
        public static bool CheckContents(LexRecord lexRecord, HashSet <string> irregExpEuiList)

        {
            bool dupFlag = CheckCont.CheckContent.CheckDuplicatesForList(lexRecord, 5);

            bool irregFlag = CheckIrreg(lexRecord, irregExpEuiList);
            bool validFlag = (dupFlag) && (irregFlag);

            return(validFlag);
        }
        public static bool CheckContents(LexRecord lexRecord)

        {
            bool orderFlag = CheckOrder(lexRecord);
            bool glregFlag = CheckGlreg(lexRecord);
            bool regdFlag  = CheckRegd(lexRecord);
            bool validFlag = (orderFlag) && (glregFlag) && (regdFlag);

            return(validFlag);
        }
Exemple #28
0
        ///**
        // * Extract info about the spelling variants of a word from an NIH record,
        // * and add to the simplenlg Woordelement.
        // *
        // * <P>
        // * Spelling variants are represented as lists of strings, retrievable via
        // * {@link LexicalFeature#SPELL_VARS}
        // *
        // * @param wordElement
        // * @param record
        // */
        private void addSpellingVariants(WordElement wordElement, LexRecord record)
        {
            List <string> vars = record.GetSpellingVars();

            if (vars != null && vars.Count > 0)
            {
                wordElement.setFeature(LexicalFeature.SPELL_VARS, vars);
            }

            // we set the default spelling var as the baseForm
            wordElement.setFeature(LexicalFeature.DEFAULT_SPELL, wordElement.BaseForm);
        }
Exemple #29
0
        public LexRecordNomObj(LexRecord lexRecord)

        {
            if (lexRecord != null)

            {
                base_            = lexRecord.GetBase();
                eui_             = lexRecord.GetEui();
                category_        = lexRecord.GetCategory();
                nominalizations_ = lexRecord.GetNominalizations();
            }
        }
Exemple #30
0
        /**
         * extract information about acronyms from NIH record, and add to a
         * simplenlg WordElement.
         *
         * <P>
         * Acronyms are represented as lists of word elements. Any acronym will have
         * a list of full form word elements, retrievable via
         * {@link LexicalFeature#ACRONYM_OF}
         *
         * @param wordElement
         * @param record
         */

        private void addAcronymInfo(WordElement wordElement, LexRecord record)
        {
            // NB: the acronyms are actually the full forms of which the word is an
            // acronym
            List <string> acronyms = record.GetAcronyms();

            if (!acronyms.isEmpty())
            {
                // the list of full forms of which this word is an acronym
                List <INLGElement> acronymOf = wordElement
                                               .getFeatureAsElementList(LexicalFeature.ACRONYM_OF);

                // keep all acronym full forms and set them up as wordElements
                foreach (var fullForm in acronyms)
                {
                    if (fullForm.contains("|"))
                    {
                        // get the acronym id
                        string acronymID = fullForm.substring(
                            fullForm.indexOf("|") + 1, fullForm.length());
                        // create the full form element
                        WordElement fullFormWE = this.getWordByID(acronymID);

                        if (fullForm != null)
                        {
                            // add as full form of this acronym
                            acronymOf.add(fullFormWE);

                            // List<NLGElement> fullFormAcronyms = fullFormWE
                            // .getFeatureAsElementList(LexicalFeature.ACRONYMS);
                            // fullFormAcronyms.add(wordElement);
                            // fullFormWE.setFeature(LexicalFeature.ACRONYMS,
                            // fullFormAcronyms);
                        }
                    }
                }

                // set all the full forms for this acronym
                wordElement.setFeature(LexicalFeature.ACRONYM_OF, acronymOf);
            }

            // if (!acronyms.isEmpty()) {
            //
            // string acronym = acronyms.get(0);
            // // remove anything after a |, this will be an NIH ID
            // if (acronym.contains("|"))
            // acronym = acronym.substring(0, acronym.indexOf("|"));
            // wordElement.setFeature(LexicalFeature.ACRONYM_OF, acronym);
            // }

            return;
        }