Ejemplo n.º 1
0
        /// <summary>
        /// 分析句子 并 将结果 以 实体格式返回
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public IList <Wl.WordsAnalyzer.Models.AnalysedWordStruct> SentenceAnalysis(string title)
        {
            var origin = analyzerWords.GetAnalyzedWords(title);

            IList <Wl.WordsAnalyzer.Models.AnalysedWordStruct> lsRetWords = new List <Wl.WordsAnalyzer.Models.AnalysedWordStruct>();

            foreach (string word in origin)
            {
                var singular    = analyzerSingular.GetAnalyzedWords(word);
                var synFromWord = new List <string>();
                if (!word.IsSymbolMark())
                {
                    synFromWord = analyzerSynonym.GetAnalyzedWords(word).ToList();
                }
                var synFromSingular = new List <string>();
                if (singular != null && singular.Any())
                {
                    if (!singular.First().IsSymbolMark())
                    {
                        synFromSingular = analyzerSynonym.GetAnalyzedWords(singular.First()).ToList();
                    }
                }
                lsRetWords.Add(new Wl.WordsAnalyzer.Models.AnalysedWordStruct
                {
                    OriginalWord               = word.IsSymbolMark() ? word.ConvertHexToChar().ToString() : word,
                    SingularizedWord           = singular.First().IsSymbolMark() ? singular.First().ConvertHexToChar().ToString() : singular.First(),
                    SynonymsOfOriginalWord     = synFromWord,
                    SynonymsOfSingularizedWord = synFromSingular
                });
            }

            return(lsRetWords);
        }
Ejemplo n.º 2
0
        public void TestAnalyzerGeneral()
        {
            var retDict = new List <Wl.WordsAnalyzer.Models.AnalysedWordStruct>();

            var title = @"Anti-broken 360° Full Protection PC Case Cover Tempered Glass Gifts For iPhone 5/5S/SE/6/6S/7 + Plus and * Android 4.0 work ? very hard or Symbian 3.0 -q ";

            var analyzerWords = new Wl.WordsAnalyzer.AnalyzerContainer <Lucene.Net.Analysis.WhitespaceAnalyzer>();

            var analyzerSingular = new Wl.WordsAnalyzer.AnalyzerContainer <Wl.WordsAnalyzer.SingularAnalyzer>(true);

            var analyzerSynonym = new Wl.WordsAnalyzer.AnalyzerContainer <Wl.WordsAnalyzer.SynonymAnalyzer>(true);

            var origin = analyzerWords.GetAnalyzedWords(title);

            foreach (string word in origin)
            {
                var singular    = analyzerSingular.GetAnalyzedWords(word);
                var synFromWord = new List <string>();
                if (!word.IsSymbolMark())
                {
                    synFromWord = analyzerSynonym.GetAnalyzedWords(word).ToList();
                }
                var synFromSingular = new List <string>();
                if (singular != null && singular.Any())
                {
                    if (!singular.First().IsSymbolMark())
                    {
                        synFromSingular = analyzerSynonym.GetAnalyzedWords(singular.First()).ToList();
                    }
                }
                retDict.Add(new Wl.WordsAnalyzer.Models.AnalysedWordStruct
                {
                    OriginalWord               = word.IsSymbolMark() ? word.ConvertHexToChar().ToString() : word,
                    SingularizedWord           = singular.First().IsSymbolMark() ? singular.First().ConvertHexToChar().ToString() : singular.First(),
                    SynonymsOfOriginalWord     = synFromWord,
                    SynonymsOfSingularizedWord = synFromSingular
                });
            }

            var jc = JsonConvert.SerializeObject(retDict);

            Console.Write(jc);
        }
Ejemplo n.º 3
0
        public void TestAnalyzerStandard()
        {
            var title = @"Anti-broken 360° Full Protection PC Case Cover Tempered Glass Gifts For iPhone 5/5S/SE/6/6S/7 Plus and Android 4.0 work ? very hard or Symbian 3.0 -q ";

            var analyzer = new Wl.WordsAnalyzer.AnalyzerContainer();

            var retTitle = analyzer.GetAnalyzedWords(title);

            Console.WriteLine(string.Join(",", retTitle.ToArray()));
        }