Ejemplo n.º 1
0
        public TermConversionResult AbbreviateTerm(string term)
        {
            TermConversionResult r = new TermConversionResult();

            r.Input         = term;
            r.Configuration = TermConverterConfiguration;

            if (TermConverterConfiguration.DelimeterForNotFound_Left.Length > 0)
            {
                term = term.Replace(TermConverterConfiguration.DelimeterForNotFound_Left, "");
            }

            if (TermConverterConfiguration.DelimeterForNotFound_Right.Length > 0)
            {
                term = term.Replace(TermConverterConfiguration.DelimeterForNotFound_Right, "");
            }

            string termRemaining           = term;
            string abbreviatedTerm         = "";
            string searchString            = term;
            string result                  = "";
            string subStringOfsearchString = "";

            do
            {
                if (_TermToAbbreviationDictionary.ContainsKey(searchString.ToUpper()))
                {
                    r.NodesFound.Add(searchString);
                    result = _TermToAbbreviationDictionary[searchString.ToUpper()];
                    switch (TermConverterConfiguration.AbbreviationCaseConvention)
                    {
                    case CaseConvention.PascalCase:
                        result = result.ToTitleCase();
                        break;

                    case CaseConvention.camelCase:
                        result = result.ToTitleCase();
                        break;

                    case CaseConvention.lowercase:
                        result = result.ToLower();
                        break;

                    case CaseConvention.UPPERCASE:
                        result = result.ToUpper();
                        break;

                    default:
                        break;
                    }

                    if (abbreviatedTerm == "")
                    {
                        if (TermConverterConfiguration.AbbreviationCaseConvention == CaseConvention.camelCase)
                        {
                            result = result.ToLower();
                        }
                        abbreviatedTerm = result;
                    }
                    else
                    {
                        abbreviatedTerm = abbreviatedTerm + TermConverterConfiguration.AbbreviationDelimeter + result;
                    }

                    termRemaining = termRemaining.ReplaceFirstOccurence(searchString, "").TrimStart();
                    if (termRemaining.StartsWith(TermConverterConfiguration.TermDelimeter))
                    {
                        termRemaining = termRemaining.ReplaceFirstOccurence(TermConverterConfiguration.TermDelimeter, "");
                    }

                    if (termRemaining.Length != 0)
                    {
                        if (termRemaining[0] == '-')
                        {
                            termRemaining = termRemaining.ReplaceFirstOccurence("-", "");
                        }
                    }
                    searchString = termRemaining;
                }
                else
                {
                    int delimeterIndex = searchString.LastIndexOf(TermConverterConfiguration.TermDelimeter);
                    if (delimeterIndex > -1 && (!TermConverterConfiguration.TreatHyphenAsTermDelimeter || TermConverterConfiguration.TermDelimeter == "-"))
                    {
                        subStringOfsearchString = searchString.Substring(0, delimeterIndex);
                    }
                    else
                    {
                        int hyphenIndex = searchString.LastIndexOf('-');

                        if (delimeterIndex == hyphenIndex)
                        {
                            subStringOfsearchString = "";
                        }
                        else if (delimeterIndex > hyphenIndex)
                        {
                            subStringOfsearchString = searchString.Substring(0, delimeterIndex);
                        }
                        else if (hyphenIndex > delimeterIndex)
                        {
                            if (hyphenIndex.Equals(0))
                            {
                                subStringOfsearchString = "";
                            }
                            else
                            {
                                subStringOfsearchString = searchString.Substring(0, hyphenIndex);
                            }
                        }
                    }


                    if (subStringOfsearchString == "")
                    {
                        if (searchString.IsANumber())
                        {
                            abbreviatedTerm = abbreviatedTerm
                                              + TermConverterConfiguration.AbbreviationDelimeter
                                              + searchString;
                        }
                        else
                        {
                            r.NodesNotFound.Add(searchString);
                            switch (TermConverterConfiguration.AbbreviationCaseConvention)
                            {
                            case CaseConvention.PascalCase:
                                if (abbreviatedTerm == string.Empty)
                                {
                                    abbreviatedTerm = TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToTitleCase();
                                }
                                else
                                {
                                    abbreviatedTerm = abbreviatedTerm + TermConverterConfiguration.AbbreviationDelimeter + TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToTitleCase();
                                }
                                break;

                            case CaseConvention.camelCase:
                                if (abbreviatedTerm == string.Empty)
                                {
                                    abbreviatedTerm = TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToLower();
                                }
                                else
                                {
                                    abbreviatedTerm = abbreviatedTerm + TermConverterConfiguration.AbbreviationDelimeter + TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToTitleCase();
                                }
                                break;

                            case CaseConvention.lowercase:
                                if (abbreviatedTerm == string.Empty)
                                {
                                    abbreviatedTerm = TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToLower();
                                }
                                else
                                {
                                    abbreviatedTerm = abbreviatedTerm + TermConverterConfiguration.AbbreviationDelimeter + TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToLower();
                                }

                                break;

                            case CaseConvention.UPPERCASE:
                                if (abbreviatedTerm == string.Empty)
                                {
                                    abbreviatedTerm = TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToUpper();
                                }
                                else
                                {
                                    abbreviatedTerm = abbreviatedTerm + TermConverterConfiguration.AbbreviationDelimeter + TermConverterConfiguration.DelimeterForNotFound_Left + searchString.ToUpper();
                                }

                                break;

                            default:
                                break;
                            }


                            abbreviatedTerm = abbreviatedTerm + TermConverterConfiguration.DelimeterForNotFound_Right;
                        }

                        termRemaining = termRemaining.ReplaceFirstOccurence(searchString, "").TrimStart();
                        if (termRemaining.Length != 0)
                        {
                            if (termRemaining[0] == '-')
                            {
                                termRemaining = termRemaining.ReplaceFirstOccurence("-", "");
                            }
                        }
                        searchString = termRemaining;
                    }
                    else
                    {
                        searchString = subStringOfsearchString;
                    }
                }
            } while (termRemaining.Length > 0);

            r.Output = abbreviatedTerm;
            return(r);
        }
Ejemplo n.º 2
0
        public GlossaryComplianceResult CheckCompliance(string term, string abbreviatedTerm)
        {
            GlossaryComplianceResult r = new GlossaryComplianceResult();

            r.Stopwatch.Start();

            r.Term         = term;
            r.Abbreviation = abbreviatedTerm;
            TermConversionResult abbreviationToTermResult = ExpandAbbreviation(r.Abbreviation);
            TermConversionResult termToAbbreviationResult = AbbreviateTerm(r.Term);

            TermConversionResult abbreviationToTermToAbbreviationResult = AbbreviateTerm(abbreviationToTermResult.Output);
            TermConversionResult termToAbbreviationToTermResult         = ExpandAbbreviation(termToAbbreviationResult.Output);

            r.AbbreviationToTermResult = abbreviationToTermResult;
            r.TermToAbbreviationResult = termToAbbreviationResult;

            r.AbbreviationToTerm               = abbreviationToTermResult.Output;
            r.TermToAbbreviation               = termToAbbreviationResult.Output;
            r.TermToAbbreviationToTerm         = termToAbbreviationToTermResult.Output;
            r.AbbreviationToTermToAbbreviation = abbreviationToTermToAbbreviationResult.Output;

            r.AbbreviationExpandsToTermCorrectly = r.AbbreviationToTerm == r.Term;
            r.TermAbbreviatesCorrectly           = r.TermToAbbreviation == r.Abbreviation;

            r.PreferredTermIsUsed = r.AbbreviationExpandsToTermCorrectly &&
                                    r.TermAbbreviatesCorrectly &&
                                    r.AbbreviationToTerm == r.TermToAbbreviationToTerm &&
                                    r.TermToAbbreviation == r.AbbreviationToTermToAbbreviation;

            r.SynonymIsUsed = !r.AbbreviationExpandsToTermCorrectly &&
                              r.TermAbbreviatesCorrectly &&
                              r.AbbreviationToTerm == r.TermToAbbreviationToTerm &&
                              r.TermToAbbreviation == r.AbbreviationToTermToAbbreviation;


            //if ((strPhysicalName == physicalToLogicalToPhysical && strPhysicalName != logicalToPhysical)
            //     || (strPhysicalName == RemoveNotFoundDelimeters(physicalToLogicalToPhysical) &&
            //         strPhysicalName != RemoveNotFoundDelimeters(logicalToPhysical)))
            //{
            //    if (logicalToPhysicalResult.NodesNotFound.Count == 0)
            //    {
            //        r.LogicalNameConvertsToPhysical = true;
            //    }
            //    if (physicalToLogicalResult.NodesNotFound.Count == 0)
            //    {
            //        r.PhysicalNameConvertsToLogical = true;
            //    }
            //}

            if (r.AbbreviationToTerm == r.TermToAbbreviationToTerm &&
                (r.Abbreviation == r.TermToAbbreviation || r.TermToAbbreviation == r.AbbreviationToTermToAbbreviation) &&
                r.Abbreviation != r.AbbreviationToTermToAbbreviation &&
                abbreviationToTermResult.NodesNotFound.Count == 0 &&
                abbreviationToTermToAbbreviationResult.NodesNotFound.Count == 0)
            {
                r.CompoundAvailable = true;
            }

            if (r.Term == r.AbbreviationToTerm &&
                r.AbbreviationToTerm == r.TermToAbbreviationToTerm &&
                r.Abbreviation != r.TermToAbbreviation &&
                r.TermToAbbreviation == r.AbbreviationToTermToAbbreviation)
            {
                r.HyphenNeededForTerm = true;
            }


            r.Mismatch = r.TermToAbbreviation != r.Abbreviation || r.AbbreviationToTerm != r.Term;


            r.Stopwatch.Stop();
            return(r);
        }
Ejemplo n.º 3
0
        public TermConversionResult ExpandAbbreviation(string abbreviation)
        {
            TermConversionResult r = new TermConversionResult();

            r.Input         = abbreviation;
            r.Configuration = TermConverterConfiguration;

            if (abbreviation.IsNullOrEmptyString())
            {
                r.Output = "";
                return(r);
            }
            if (TermConverterConfiguration.DelimeterForNotFound_Left.Length > 0)
            {
                abbreviation = abbreviation.Replace(TermConverterConfiguration.DelimeterForNotFound_Left, "");
            }

            if (TermConverterConfiguration.DelimeterForNotFound_Right.Length > 0)
            {
                abbreviation = abbreviation.Replace(TermConverterConfiguration.DelimeterForNotFound_Right, "");
            }

            string term = "";

            string[] nodes = abbreviation.Split(new string[] { TermConverterConfiguration.AbbreviationDelimeter }, StringSplitOptions.None);
            int      i     = 0;

            foreach (string node in nodes)
            {
                i++;
                if (_AbbreviationToTermDictionary.ContainsKey(node.ToUpper()))
                {
                    r.NodesFound.Add(node);
                    if (i > 1)
                    {
                        term = term + TermConverterConfiguration.TermDelimeter;
                    }
                    switch (TermConverterConfiguration.TermCaseConvention)
                    {
                    case CaseConvention.PascalCase:
                        term = term + _AbbreviationToTermDictionary[node.ToUpper()].ToTitleCase();
                        break;

                    case CaseConvention.camelCase:
                        if (i == 1)
                        {
                            term = term + _AbbreviationToTermDictionary[node.ToUpper()].ToLower();
                        }
                        else
                        {
                            term = term + _AbbreviationToTermDictionary[node.ToUpper()].ToTitleCase();
                        }
                        break;

                    case CaseConvention.lowercase:
                        term = term + _AbbreviationToTermDictionary[node.ToUpper()].ToLower();
                        break;

                    case CaseConvention.UPPERCASE:
                        term = term + _AbbreviationToTermDictionary[node.ToUpper()].ToUpper();
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    if (node.IsANumber())
                    {
                        term = term + TermConverterConfiguration.TermDelimeter + node;
                    }
                    else
                    {
                        r.NodesNotFound.Add(node);
                        term = term + TermConverterConfiguration.TermDelimeter + TermConverterConfiguration.DelimeterForNotFound_Left + node + TermConverterConfiguration.DelimeterForNotFound_Right;
                    }
                }
            }
            term = term.Trim().Replace(" ", TermConverterConfiguration.TermDelimeter);
            if ((TermConverterConfiguration.DelimeterForNotFound_Left + TermConverterConfiguration.DelimeterForNotFound_Right).Length > 0)
            {
                r.Output = term.Replace(TermConverterConfiguration.DelimeterForNotFound_Left + TermConverterConfiguration.DelimeterForNotFound_Right, "");
            }
            else
            {
                if (TermConverterConfiguration.TermDelimeter.Length > 0 &&
                    term.Substring(0, TermConverterConfiguration.TermDelimeter.Length) == TermConverterConfiguration.TermDelimeter)
                {
                    r.Output = term.ReplaceFirstOccurence(TermConverterConfiguration.TermDelimeter, "");
                }
                else
                {
                    r.Output = term;
                }
            }
            return(r);
        }