Ejemplo n.º 1
0
            void AfterMatchListener.OnResultRequested(Action <MutableGrammarBlock> blockTaker)
            {
                MutableGrammarBlock baseBlock = null;
                List <GrammarBlock> modifiers = new List <GrammarBlock>();

                foreach (var afLIs in updatedMatches)
                {
                    if (afLIs.index == 0 && parent.preMod != null)
                    {
                        afLIs.result.listener.OnResultRequested((mod) => modifiers.Add(mod));
                    }
                    else if ((afLIs.index == 0 && parent.preMod == null) || (afLIs.index == 1 && parent.preMod != null))
                    {
                        afLIs.result.listener.OnResultRequested((mgBlock) => baseBlock = mgBlock);
                    }
                    else if ((afLIs.index == 1 && parent.preMod == null) || (afLIs.index == 2 && parent.preMod != null))
                    {
                        afLIs.result.listener.OnResultRequested((mod) => modifiers.Add(mod));
                    }
                }
                if (baseBlock != null)
                {
                    foreach (var mod in modifiers)
                    {
                        baseBlock.AddModifier(mod);
                    }
                    blockTaker(baseBlock);
                }
            }
Ejemplo n.º 2
0
        void AfterMatchListener.OnResultRequested(Action <MutableGrammarBlock> blockTaker)
        {
            var mClusterGBlock            = new StdMutableClusterGBlock();
            MutableGrammarBlock lastBlock = null;

            baseAMatchLis.OnResultRequested(
                (gBlock) => mClusterGBlock.subBlocks.Add(lastBlock = gBlock)
                );
            if (mClusterGBlock.subBlocks.Count == 1)
            {
                blockTaker(lastBlock);
            }
            else if (mClusterGBlock.subBlocks.Count > 1)
            {
                blockTaker(mClusterGBlock);
            }
        }
Ejemplo n.º 3
0
 public static void ApplyModAndMeta(
     MutableGrammarBlock newBlock,
     GrammarBlock sourceBlock,
     GBlockConvertListener listener,
     GBlockConverter metaConv = null,
     GBlockConverter modConv  = null
     )
 {
     if (sourceBlock.metaInfo != null)
     {
         var metaLis = new MixedGBlockConvertListener {
             _subBlockConverter = listener.metaConverter,
             _metaConverter     = PassThroughGBlockConverter.instance,
             _modConverter      = PassThroughGBlockConverter.instance
         };
         var result = listener.metaConverter.ConvertGBlock(sourceBlock.metaInfo, metaLis);
         if (result.result != null)
         {
             newBlock.AddMetaInfo(result.result);
         }
     }
     if (sourceBlock.modifier != null)
     {
         var modLis = new MixedGBlockConvertListener {
             _subBlockConverter = listener.modConverter,
             _metaConverter     = listener.metaConverter,
             _modConverter      = listener.modConverter,
             _baseLisetner      = listener
         };
         var result = listener.modConverter.ConvertGBlock(sourceBlock.modifier, modLis);
         if (result.result != null)
         {
             newBlock.AddModifier(result.result);
         }
     }
     listener.AdditionalEdit(newBlock);
 }
Ejemplo n.º 4
0
 void GBlockConvertListener.AdditionalEdit(MutableGrammarBlock mgBlock)
 {
     _baseLisetner?.AdditionalEdit(mgBlock);
 }
Ejemplo n.º 5
0
 void GBlockConvertListener.AdditionalEdit(MutableGrammarBlock mgBlock)
 {
 }
Ejemplo n.º 6
0
 public GBlockConvertResult(bool _didConvert, MutableGrammarBlock _result)
 {
     didConvert = _didConvert;
     result     = _result;
 }
Ejemplo n.º 7
0
        GBlockConvertResult GBlockConverter.ConvertGBlock(GrammarBlock sourceGBlock, GBlockConvertListener listener)
        {
            //only applly to SV or Condition SV
            if (!GrammarBlockUtils.HasMetaInfo(sourceGBlock, StdMetaInfos.sv.word) && !GrammarBlockUtils.HasMetaInfo(sourceGBlock, StdMetaInfos.conditionSV.word))
            {
                return(default(GBlockConvertResult));
            }
            //search passive be
            List <GrammarUnit> passiveVerbList = null;
            var originalSubject  = sourceGBlock.cluster.blocks[0];
            var convertedSubject = listener.subBlockConverter.ConvertGBlock(originalSubject, listener).result;
            var originalVerbs    = sourceGBlock.cluster.blocks[1];

            GrammarBlockUtils.DeepForEachBlockUnit(
                originalVerbs,
                (mainVerbUnit) => {
                if (GrammarBlockUtils.IsUnit(mainVerbUnit, "be"))
                {
                    GrammarBlockUtils.DeepForEachBlockUnit(
                        mainVerbUnit.modifier,
                        (contentVerbUnit) => {
                        if (passiveVerbList == null)
                        {
                            passiveVerbList = new List <GrammarUnit>();
                        }
                        passiveVerbList.Add(contentVerbUnit);
                    },
                        StdMetaInfos.verbalBlock.word
                        );
                }
            },
                StdMetaInfos.verbalBlock.word
                );
            //no passive verb found
            if (passiveVerbList == null)
            {
                return(default(GBlockConvertResult));
            }
            //search normal verbs
#if false
            List <GrammarBlock> normalVerbList = null;
            GrammarBlockUtils.ForEachUnits(
                originalVerbs,
                (gUnit) => {
                if (GrammarBlockUtils.ShallowSeekByMetaInfo(sourceGBlock.cluster.blocks[1], StdMetaInfos.verbalBlock.word) != null)
                {
                    if (normalVerbList == null)
                    {
                        normalVerbList = new List <GrammarBlock>();
                    }
                    normalVerbList.Add(gUnit);
                }
            },
                StdMetaInfos.modifierCluster.word
                );
#endif
            MutableGrammarBlock converted = null;
            #region passive only
            if (passiveVerbList.Count > 0)
            {
                var newSVCluster = new StdMutableClusterGBlock {
                };
                StdMutableClusterGBlock newSV = null;
                foreach (var passiveVerb in passiveVerbList)
                {
                    newSV = new StdMutableClusterGBlock {
                    };
                    (newSV as MutableClusterGrammarBlock).AddBlock(defaultSubject);
                    var activizedVerb = listener.subBlockConverter.ConvertGBlock(passiveVerb, listener).result;
                    activizedVerb.AddModifier(convertedSubject);
                    (newSV as MutableClusterGrammarBlock).AddBlock(activizedVerb);
                    (newSVCluster as MutableClusterGrammarBlock).AddBlock(newSV);
                    (newSV as MutableClusterGrammarBlock).AddMetaInfo(sourceGBlock.metaInfo);
                }
                if (passiveVerbList.Count == 1)
                {
                    converted = newSV;
                    GBlockConvertUtility.ApplyModAndMeta(converted, sourceGBlock, listener);
                }
                else
                {
                    converted = newSVCluster;
                    var convLis = new MixedGBlockConvertListener {
                        _baseLisetner  = listener,
                        _metaConverter = new ClusterGBlockConverter {
                            converters = new List <GBlockConverter> {
                                new GBlockConverter_Replace {
                                    number = new Dictionary <string, GrammarBlock> {
                                        { StdMetaInfos.sv.word, StdMetaInfos.sentenceCluster },
                                        { StdMetaInfos.conditionSV.word, StdMetaInfos.sentenceCluster }
                                    }
                                },
                                listener.metaConverter
                            }
                        }
                    };
                    GBlockConvertUtility.ApplyModAndMeta(converted, sourceGBlock, convLis);
                }
            }
            #endregion
            #region no result
            if (converted == null)
            {
                return(default(GBlockConvertResult));
            }

            return(new GBlockConvertResult(true, converted));

            #endregion
        }