Beispiel #1
0
        /// <summary>
        /// Recognizes named entities occurring in content text that recorded in the dictionary.
        /// </summary>
        /// <param name="content">The content string to recognize the named entities.</param>
        /// <returns>A set of <see cref="NamedEntityInfo&lt;T&gt;"/> represents named entities that is recognized from the content text.</returns>
        public IList <NamedEntityInfo <T> > Recognize(string content)
        {
            content = content.ToLower();

            IList <string> tokens = NamedEntityDictionary <T> .Tokenize(content);

            IList <NamedEntityInfo <T> > result = new List <NamedEntityInfo <T> >();
            int contentIndex = 0;

            while (tokens.Count > 0)
            {
                PrefixMatch <string, T> match = this.prefixTree.LongestPrefixMatch(tokens);
                if (match.Length == 0)
                {
                    contentIndex += tokens[0].Length;
                    tokens.RemoveAt(0);
                    continue;
                }

                int termLength = 0;
                for (int index = 0; index < match.Length; index++)
                {
                    termLength += tokens[0].Length;
                    tokens.RemoveAt(0);
                }

                NamedEntityInfo <T> entity =
                    new NamedEntityInfo <T>(match.Value, contentIndex, termLength);
                result.Add(entity);
                contentIndex += termLength;
            }

            return(result);
        }
        private bool tryMask(PrefixEntry entry, bool topLevel, string callsign)
        {
            bool result = false;

            if (usPossesions.Contains(Convert.ToInt32(entry.Data.ADIF)) & topLevel == true)
            {
                result = true;
            }
            //check entry kind
            else if (topLevel)
            {
                if (!AllowedForTop.Contains(entry.Kind))
                {
                    return(result);
                }
            }
            else
            {
                if (!AllowedForSub.Contains(entry.Kind))
                {
                    return(result);
                }
            }
            // mobile, portable, beacon, rover
            if (callsign.EndsWith("/M") || callsign.EndsWith("/P") || callsign.EndsWith("/B") || callsign.EndsWith("/R"))
            {
                callsign = callsign.Substring(0, callsign.Length - 2);
            }
            string[] maskParts = entry.Mask.Split(',');
            for (int i = 0; i < maskParts.Length; i++)
            {
                PrefixMatch prefixMatch = comparePrefix(maskParts[i], callsign);
                EndingMatch endingMatch = compareEnding(maskParts[i], callsign);
                if (topLevel)
                {
                    result = ResultForTop[(int)prefixMatch, (int)endingMatch];
                }
                else
                {
                    result = ResultForChild[(int)prefixMatch, (int)endingMatch];
                }
                if (result)
                {
                    break;
                }
            }
            return(result);
        }