Пример #1
0
        public void Apply()
        {
            var pattern = Pattern <AnnotatedStringData, int> .New()
                          .Group("leftEnv", leftEnv => leftEnv
                                 .Annotation(FeatureStruct.New(PhoneticFeatSys)
                                             .Symbol(Seg)
                                             .Symbol("cons+")
                                             .Feature("voice").EqualToVariable("a").Value))
                          .Group("target", target => target
                                 .Annotation(FeatureStruct.New(PhoneticFeatSys)
                                             .Symbol(Seg)
                                             .Symbol("cons-")
                                             .Symbol("low+").Value))
                          .Group("rightEnv", rightEnv => rightEnv
                                 .Annotation(FeatureStruct.New(PhoneticFeatSys)
                                             .Symbol(Seg)
                                             .Symbol("cons+")
                                             .Feature("voice").Not.EqualToVariable("a").Value)).Value;

            var ruleSpec = new DefaultPatternRuleSpec <AnnotatedStringData, int>(pattern, (r, match) =>
            {
                GroupCapture <int> target = match.GroupCaptures["target"];
                foreach (Annotation <int> ann in match.Input.Annotations.GetNodes(target.Range))
                {
                    ann.FeatureStruct.PriorityUnion(FeatureStruct.New(PhoneticFeatSys).Symbol("low-").Value);
                }
                return(match.Input);
            });

            var rule = new PatternRule <AnnotatedStringData, int>(ruleSpec);
            AnnotatedStringData inputWord = CreateStringData("fazk");

            Assert.IsTrue(rule.Apply(inputWord).Any());
        }
Пример #2
0
        public TData ApplyRhs(PatternRule <TData, TOffset> rule, Match <TData, TOffset> match)
        {
            IPatternRuleSpec <TData, TOffset> ruleSpec = _ruleIds[match.PatternPath.First()];
            var newMatch = new Match <TData, TOffset>(match.Matcher, match.Span, match.Input, match.GroupCaptures, match.PatternPath.Skip(1).ToArray(),
                                                      match.VariableBindings, match.NextAnnotation);

            return(ruleSpec.ApplyRhs(rule, newMatch));
        }
Пример #3
0
        public void Batch()
        {
            var pattern = Pattern <AnnotatedStringData, int> .New()
                          .Group("leftEnv", leftEnv => leftEnv
                                 .Annotation(FeatureStruct.New(PhoneticFeatSys)
                                             .Symbol(Seg)
                                             .Symbol("cons+")
                                             .Feature("voice").EqualToVariable("a").Value))
                          .Group("target", target => target
                                 .Annotation(FeatureStruct.New(PhoneticFeatSys)
                                             .Symbol(Seg)
                                             .Symbol("cons-")
                                             .Symbol("low+").Value))
                          .Group("rightEnv", rightEnv => rightEnv
                                 .Annotation(FeatureStruct.New(PhoneticFeatSys)
                                             .Symbol(Seg)
                                             .Symbol("cons+")
                                             .Feature("voice").Not.EqualToVariable("a").Value)).Value;

            var ruleSpec1 = new DefaultPatternRuleSpec <AnnotatedStringData, int>(pattern, (r, match) =>
            {
                GroupCapture <int> target = match.GroupCaptures["target"];
                foreach (Annotation <int> ann in match.Input.Annotations.GetNodes(target.Range))
                {
                    ann.FeatureStruct.PriorityUnion(FeatureStruct.New(PhoneticFeatSys)
                                                    .Symbol("low-")
                                                    .Symbol("mid-").Value);
                }
                return(match.Input);
            },
                                                                                  input => input.Annotations.Single(ann => ((FeatureSymbol)ann.FeatureStruct.GetValue(Type)) == Word)
                                                                                  .FeatureStruct.IsUnifiable(FeatureStruct.New(WordFeatSys).Symbol("verb").Value));

            var ruleSpec2 = new DefaultPatternRuleSpec <AnnotatedStringData, int>(pattern, (r, match) =>
            {
                GroupCapture <int> target = match.GroupCaptures["target"];
                foreach (Annotation <int> ann in match.Input.Annotations.GetNodes(target.Range))
                {
                    ann.FeatureStruct.PriorityUnion(FeatureStruct.New(PhoneticFeatSys)
                                                    .Symbol("low-")
                                                    .Symbol("mid+").Value);
                }
                return(match.Input);
            });

            var batchSpec = new BatchPatternRuleSpec <AnnotatedStringData, int>(new[] { ruleSpec1, ruleSpec2 });
            var rule      = new PatternRule <AnnotatedStringData, int>(batchSpec);
            AnnotatedStringData inputWord = CreateStringData("fazk");

            inputWord.Annotations.Add(inputWord.Range, FeatureStruct.New(WordFeatSys).Symbol(Word).Symbol("noun").Value);
            Assert.IsTrue(rule.Apply(inputWord).Any());
        }
Пример #4
0
 public TOffset ApplyRhs(PatternRule <TData, TOffset> rule, Match <TData, TOffset> match, out TData output)
 {
     return(_action(rule, match, out output));
 }
Пример #5
0
 public TData ApplyRhs(PatternRule <TData, TOffset> rule, Match <TData, TOffset> match)
 {
     return(_func(rule, match));
 }