Пример #1
0
        public DivisibleEnumerable <Morpheme> AnalyzeImmediate(string str)
        {
            var unitCluster = new MorphemeCluster {
                units = new List <Morpheme>()
            };
            int generalStartIndex = 0;
            int i = 0;

            for (; i < str.Length;)
            {
                bool didBlockReaderHit = false;
                foreach (var reader in blockReaderes)
                {
                    int      nextIndex    = i;
                    Morpheme blockProduct = null;
                    if (didBlockReaderHit = reader.ReadBlock(str, i, out nextIndex, out blockProduct))
                    {
                        if (generalStartIndex != i)
                        {
                            if (TryReadGeneral(str, generalStartIndex, i - 1, out Morpheme generalProduct))
                            {
                                if (generalProduct != null)
                                {
                                    unitCluster.units.Add(generalProduct);
                                }
                            }
                        }
                        i = generalStartIndex = nextIndex;
                        if (blockProduct != null)
                        {
                            unitCluster.units.Add(blockProduct);
                        }
                        break;
                    }
                }
                if (!didBlockReaderHit)
                {
                    i++;
                }
            }
            if (TryReadGeneral(str, generalStartIndex, i - 1, out Morpheme lastGeneralProduct))
            {
                if (lastGeneralProduct != null)
                {
                    unitCluster.units.Add(lastGeneralProduct);
                }
            }
            if (unitCluster.units.Count > 0)
            {
                return(unitCluster);
            }
            return(null);
        }
Пример #2
0
 bool BlockReader.ReadBlock(string text, int startIndex, out int nextIndex, out Morpheme product)
 {
     nextIndex = startIndex;
     product   = null;
     foreach (var marker in markers)
     {
         if (MarkerBlockReader.CheckMarker(text, marker, startIndex, out nextIndex))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
        bool GeneralReader.ReadBlock(string text, int startIndex, int lastIndex, out Morpheme product)
        {
            product = null;
            var part = text.Substring(startIndex, lastIndex - startIndex + 1);

            if (float.TryParse(part, out float number))
            {
                product = new Morpheme {
                    id = 6, word = part
                };
                return(true);
            }
            return(false);
        }
Пример #4
0
 public void FeedMorpheme(Morpheme morpheme)
 {
     wordCandidateInfoDict.TryGetValue(morpheme.word, out var wordCandInfos);
     if (wordCandInfos != null)
     {
         activatedWords.Add(morpheme.word);
         foreach (var wordCandInfo in wordCandInfos)
         {
             foreach (var candidateHolder in wordCandInfo.candidateHolders)
             {
                 Utilities.AddIfNotDuplicated(candidateHolder.candidates, wordCandInfo.condidateAnalyzer);
             }
         }
     }
 }
Пример #5
0
 public bool TryReadGeneral(string text, int startIndex, int lastIndex, out Morpheme product)
 {
     product = null;
     if (startIndex <= lastIndex)
     {
         product = null;
         foreach (var generalReader in generalReaders)
         {
             if (generalReader.ReadBlock(text, startIndex, lastIndex, out product))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #6
0
 bool BlockReader.ReadBlock(string text, int startIndex, out int nextIndex, out Morpheme product)
 {
     nextIndex = startIndex;
     product   = null;
     foreach (var marker in markers)
     {
         if (CheckMarker(text, marker.marker, startIndex, out nextIndex))
         {
             product = new Morpheme {
                 id = marker.formatID, word = marker.marker
             };
             return(true);
         }
     }
     return(false);
 }