Ejemplo n.º 1
0
 public void AddCutomRule(ICustomRule customRule)
 {
     if (customRule != null)
     {
         _customRules.Add(customRule);
     }
 }
Ejemplo n.º 2
0
        private int OrderWeight(ICustomRule arg)
        {
            if (arg is IsIdentifiableRule irule)
            {
                switch (irule.Action)
                {
                case RuleAction.None:
                    return(-6000);

                //ignore rules float to the top
                case RuleAction.Ignore:
                    return(100);

                //then consider the report explicit rules (by pattern)
                case RuleAction.Report:
                    return(0);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            //socket rules sink to the bottom
            if (arg is SocketRule)
            {
                return(-5000);
            }


            //ConsensusRules should sink to the bottom but just above SocketRules (if any)
            if (arg is ConsensusRule)
            {
                return(-3000);
            }

            //some odd custom rule type that is not a socket or basic rule, do them after the regular reports but before sockets
            return(-50);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Selects types that meet a custom rule.
 /// </summary>
 /// <param name="rule">An instance of the custom rule.</param>
 /// <returns>An updated set of conditions that can be applied to a list of types.</returns>
 public ConditionList MeetCustomRule(ICustomRule rule)
 {
     _sequence.AddFunctionCall(FunctionDelegates.MeetCustomRule, rule, true);
     return(new ConditionList(_types, _should, _sequence));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Selects types that meet a custom rule.
 /// </summary>
 /// <param name="rule">An instance of the custom rule.</param>
 /// <returns>An updated set of conditions that can be applied to a list of types.</returns>
 public PredicateList MeetCustomRule(ICustomRule rule)
 {
     _sequence.AddFunctionCall(FunctionDelegates.MeetCustomRule, rule, true);
     return(new PredicateList(_types, _sequence));
 }
Ejemplo n.º 5
0
        private void ProcessAfterSegment(string orginalText, SuperLinkedList <WordInfo> result)
        {
            //匹配同义词
            if (_Options.SynonymOutput)
            {
                SuperLinkedListNode <WordInfo> node = result.First;

                while (node != null)
                {
                    List <string> synonyms = _Synonym.GetSynonyms(node.Value.Word);

                    if (synonyms != null)
                    {
                        foreach (string word in synonyms)
                        {
                            node = result.AddAfter(node, new WordInfo(word, node.Value.Position,
                                                                      node.Value.Pos, node.Value.Frequency, _Parameters.SymbolRank,
                                                                      WordType.Synonym, node.Value.WordType));
                        }
                    }

                    node = node.Next;
                }
            }

            //通配符匹配
            if (_Options.WildcardOutput)
            {
                SuperLinkedListNode <WordInfo> node = result.First;

                while (node != null)
                {
                    List <Dict.Wildcard.WildcardInfo> wildcards =
                        _Wildcard.GetWildcards(node.Value.Word);

                    if (wildcards.Count > 0)
                    {
                        for (int i = 0; i < wildcards.Count; i++)
                        {
                            Dict.Wildcard.WildcardInfo wildcardInfo = wildcards[i];

                            int count = wildcardInfo.Segments.Count;
                            if (!_Options.WildcardSegment)
                            {
                                count = 1;
                            }

                            for (int j = 0; j < count; j++)
                            {
                                WordInfo wi = wildcardInfo.Segments[j];

                                if (wi.Word == node.Value.Word)
                                {
                                    continue;
                                }

                                wi.Rank      = _Parameters.WildcardRank;
                                wi.Position += node.Value.Position;
                                result.AddBefore(node, wi);
                            }
                        }
                    }

                    node = node.Next;

                    if (node != null)
                    {
                        //过滤英文分词时多元分词重复输出的问题
                        if (node.Previous.Value.Word.ToLower() == node.Value.Word.ToLower())
                        {
                            node = node.Next;
                        }
                    }
                }
            }

            //用户自定义规则
            if (_Options.CustomRule)
            {
                ICustomRule rule = CustomRule.GetCustomRule(_Parameters.CustomRuleAssemblyFileName,
                                                            _Parameters.CustomRuleFullClassName);

                if (rule != null)
                {
                    rule.Text = orginalText;
                    rule.AfterSegment(result);
                }
            }
        }